Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2019-05-29 07:35:46 +0000
committerStephan Herrmann2019-06-25 20:14:01 +0000
commit6457b6c80a6b7bdd29674a56ca3dd77128e86cc1 (patch)
tree7f9edb2b2f919a72f17feac4cf6eedad015d2535
parent4ac2904e518928fb9f4aa2fc7f5f3e9b92d231e5 (diff)
downloadeclipse.jdt.core-6457b6c80a6b7bdd29674a56ca3dd77128e86cc1.tar.gz
eclipse.jdt.core-6457b6c80a6b7bdd29674a56ca3dd77128e86cc1.tar.xz
eclipse.jdt.core-6457b6c80a6b7bdd29674a56ca3dd77128e86cc1.zip
Bug 547591 - Add failOnWarning (-Werror like) flag to the batch compilerI20190625-1800
Mimic javac's -Werror behavior. Report warnings as warnings but if -fainOnWarning argument is given and there are warnings return false from Main.compile or exit with -1. In case there are warnings and the argument is passed print "error: warnings found and -failOnWarning specified" at the end to make it clear to users why the build failed. Change-Id: Id7268746ed29481a20dd6d295134dcd5db7ce437 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java43
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java22
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties4
3 files changed, 66 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 1ccbeb201b..d4aa47bc36 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -734,6 +734,7 @@ public void test012(){
" do not stop at first error, dumping class files with\n" +
" problem methods\n" +
" With \":Fatal\", all optional errors are treated as fatal\n" +
+ " -failOnWarning fail compilation if there are warnings\n" +
" -verbose enable verbose output\n" +
" -referenceInfo compute reference info\n" +
" -progress show progress (only in -log mode)\n" +
@@ -13139,4 +13140,46 @@ public void testBug531579() throws Exception {
"",
false);
}
+
+public void testFailOnWarnings_NoWarning() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "/** */\n" +
+ "public class X {\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -failOnWarning"
+ + " -d \"" + OUTPUT_DIR + File.separator + "bin/\"",
+ "",
+ "",
+ true);
+
+}
+
+public void testFailOnWarnings_WithWarning() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "/** */\n" +
+ "public class X {\n" +
+ "private int a;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -failOnWarning"
+ + " -d \"" + OUTPUT_DIR + File.separator + "bin/\"",
+ "",
+ "----------\n" +
+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
+ " private int a;\n" +
+ " ^\n" +
+ "The value of the field X.a is not used\n" +
+ "----------\n" +
+ "1 problem (1 warning)\n" +
+ "error: warnings found and -failOnWarning specified\n" +
+ "",
+ true);
+}
}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
index 7a74db1569..8f18585cc7 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java
@@ -984,6 +984,10 @@ public class Main implements ProblemSeverities, SuffixConstants {
}
}
}
+ if (this.main.failOnWarning && globalWarningsCount > 0) {
+ printErr("\n"); //$NON-NLS-1$
+ printErr(this.main.bind("compile.failOnWarning")); //$NON-NLS-1$
+ }
if ((this.tagBits & Logger.XML) == 0) {
this.printlnErr();
}
@@ -1424,6 +1428,7 @@ public class Main implements ProblemSeverities, SuffixConstants {
protected PrintWriter out;
public boolean proceed = true;
public boolean proceedOnError = false;
+ public boolean failOnWarning = false;
public boolean produceRefInfo = false;
public int currentRepetition, maxRepetition;
public boolean showProgress = false;
@@ -1779,6 +1784,9 @@ public boolean compile(String[] argv) {
if (this.systemExitWhenFinished) {
this.logger.flush();
this.logger.close();
+ if (this.failOnWarning && this.globalWarningsCount > 0) {
+ System.exit(-1);
+ }
System.exit(this.globalErrorsCount > 0 ? -1 : 0);
}
} catch (IllegalArgumentException e) {
@@ -1803,8 +1811,13 @@ public boolean compile(String[] argv) {
if (this.progress != null)
this.progress.done();
}
- if (this.globalErrorsCount == 0 && (this.progress == null || !this.progress.isCanceled()))
- return true;
+ if (this.progress == null || !this.progress.isCanceled()) {
+ if (this.failOnWarning && (this.globalWarningsCount > 0))
+ return false;
+ if (this.globalErrorsCount == 0)
+ return true;
+ }
+
return false;
}
@@ -2333,6 +2346,11 @@ public void configure(String[] argv) {
this.proceedOnError = true;
continue;
}
+ if (currentArg.equals("-failOnWarning")) { //$NON-NLS-1$
+ mode = DEFAULT;
+ this.failOnWarning = true;
+ continue;
+ }
if (currentArg.equals("-time")) { //$NON-NLS-1$
mode = DEFAULT;
this.timing = TIMING_ENABLED;
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties
index c476812a1a..b4780afc74 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2018 IBM Corporation and others.
+# Copyright (c) 2000, 2019 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -54,6 +54,7 @@ compile.oneInfo = 1 info
compile.severalInfos = {0} info
compile.oneClassFileGenerated = [1 .class file generated]
compile.severalClassFilesGenerated = [{0} .class files generated]
+compile.failOnWarning = error: warnings found and -failOnWarning specified
### configure
configure.requiresJDK1.2orAbove = Need to use a JVM >= 1.2
@@ -317,6 +318,7 @@ misc.usage = {1} {2}\n\
\ do not stop at first error, dumping class files with\n\
\ problem methods\n\
\ With ":Fatal", all optional errors are treated as fatal\n\
+\ -failOnWarning fail compilation if there are warnings\n\
\ -verbose enable verbose output\n\
\ -referenceInfo compute reference info\n\
\ -progress show progress (only in -log mode)\n\

Back to the top