Acccept source levels 10+, allow to fail the build when warnings are reported.
diff --git a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java
index 423cd73..c86be4c 100644
--- a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java
+++ b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java
@@ -53,6 +53,7 @@
}
String configurationFile = Utils.getJackpotConfigurationFile(project);
+ boolean failOnWarnings = Utils.getJackpotFailOnWarnings(project);
List<String> cmdLine = new ArrayList<String>();
@@ -70,6 +71,10 @@
cmdLine.add(configurationFile);
}
+ if (failOnWarnings) {
+ cmdLine.add("--fail-on-warnings");
+ }
+
boolean hasSourceRoots = false;
for (String sr : (List<String>) project.getCompileSourceRoots()) {
@@ -96,7 +101,9 @@
"--add-opens=java.base/java.net=ALL-UNNAMED",
"--add-opens=java.desktop/sun.awt=ALL-UNNAMED",
Main.class.getCanonicalName()));
- new ProcessBuilder(cmdLine).inheritIO().start().waitFor();
+ if (new ProcessBuilder(cmdLine).inheritIO().start().waitFor() != 0) {
+ throw new MojoExecutionException("jackpo30 failed.");
+ }
} catch (IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (InterruptedException ex) {
diff --git a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java
index 5ea91a9..3fd1b65 100644
--- a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java
+++ b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java
@@ -47,7 +47,7 @@
}
public static String getJackpotConfigurationFile(MavenProject project) {
- Xpp3Dom configuration = getPluginConfiguration(project, "org.apache.netbeans.modules.jackpot30", "jackpot30-maven-plugin");
+ Xpp3Dom configuration = getJackpotPluginConfiguration(project);
if (configuration != null) {
Xpp3Dom configurationFileElement = configuration.getChild("configurationFile");
@@ -59,4 +59,22 @@
return null;
}
+
+ public static boolean getJackpotFailOnWarnings(MavenProject project) {
+ Xpp3Dom configuration = getJackpotPluginConfiguration(project);
+
+ if (configuration != null) {
+ Xpp3Dom configurationFileElement = configuration.getChild("failOnWarnings");
+
+ if (configurationFileElement != null) {
+ return "true".equalsIgnoreCase(configurationFileElement.getValue());
+ }
+ }
+
+ return false;
+ }
+
+ private static Xpp3Dom getJackpotPluginConfiguration(MavenProject project) {
+ return getPluginConfiguration(project, "org.apache.netbeans.modules.jackpot30", "jackpot30-maven-plugin");
+ }
}
diff --git a/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java b/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
index 4afc5d3..27e6da6 100644
--- a/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
+++ b/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
@@ -74,19 +74,21 @@
ByteArrayOutputStream out = new ByteArrayOutputStream();
Thread outCopy = new Thread(new CopyStream(p.getInputStream(), System.out, out));
- Thread errCopy = new Thread(new CopyStream(p.getErrorStream(), System.err));
+ Thread errCopy = new Thread(new CopyStream(p.getErrorStream(), System.err, out));
outCopy.start();
errCopy.start();
- p.waitFor();
+ int result = p.waitFor();
outCopy.join();
errCopy.join();
out.close();
- String output = new String(out.toByteArray());
+ String output = new String(out.toByteArray()) +
+ System.getProperty("line.separator") +
+ "result: " + result;
Reader in = new InputStreamReader(new FileInputStream(new File(testDir, "golden")), "UTF-8");
StringBuilder golden = new StringBuilder();
diff --git a/cmdline/maven/tests/fail-on-warnings/golden b/cmdline/maven/tests/fail-on-warnings/golden
new file mode 100644
index 0000000..bea3cf1
--- /dev/null
+++ b/cmdline/maven/tests/fail-on-warnings/golden
@@ -0,0 +1,12 @@
+${basedir}/src/main/java/test/App.java:24: warning: [Convert_to_Lambda_or_Member_Reference] This anonymous inner class creation can be turned into a lambda expression.
+ Runnable r = new Runnable() { public void run() { } };
+ ^
+[ERROR] Failed to execute goal org.apache.netbeans.modules.jackpot30:jackpot30-maven-plugin:13.0:analyze (default-cli) on project maven-test: jackpo30 failed. -> [Help 1]
+[ERROR]
+[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
+[ERROR] Re-run Maven using the -X switch to enable full debug logging.
+[ERROR]
+[ERROR] For more information about the errors and possible solutions, please read the following articles:
+[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
+
+result: 1
\ No newline at end of file
diff --git a/cmdline/maven/tests/sl-18/jackpot-settings.xml b/cmdline/maven/tests/fail-on-warnings/jackpot-settings.xml
similarity index 100%
copy from cmdline/maven/tests/sl-18/jackpot-settings.xml
copy to cmdline/maven/tests/fail-on-warnings/jackpot-settings.xml
diff --git a/cmdline/maven/tests/fail-on-warnings/pom.xml b/cmdline/maven/tests/fail-on-warnings/pom.xml
new file mode 100644
index 0000000..c4536a7
--- /dev/null
+++ b/cmdline/maven/tests/fail-on-warnings/pom.xml
@@ -0,0 +1,64 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.netbeans.modules.jackpot30</groupId>
+ <artifactId>maven-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>jackpot30-maven-plugin-test1</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
+ <artifactId>jackpot30-maven-plugin</artifactId>
+ <version>${jackpot.plugin.version}</version>
+ <configuration>
+ <configurationFile>jackpot-settings.xml</configurationFile>
+ <failOnWarnings>true</failOnWarnings>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>17</source>
+ <target>17</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/cmdline/maven/tests/sl-18/src/main/java/test/App.java b/cmdline/maven/tests/fail-on-warnings/src/main/java/test/App.java
similarity index 100%
copy from cmdline/maven/tests/sl-18/src/main/java/test/App.java
copy to cmdline/maven/tests/fail-on-warnings/src/main/java/test/App.java
diff --git a/cmdline/maven/tests/sl-17/golden b/cmdline/maven/tests/sl-17/golden
index e69de29..91c448d 100644
--- a/cmdline/maven/tests/sl-17/golden
+++ b/cmdline/maven/tests/sl-17/golden
@@ -0,0 +1,5 @@
+${basedir}/src/main/java/test/App.java:24: warning: [Convert_to_Lambda_or_Member_Reference] This anonymous inner class creation can be turned into a lambda expression.
+ Runnable r = new Runnable() { public void run() { } };
+ ^
+
+result: 0
\ No newline at end of file
diff --git a/cmdline/maven/tests/sl-17/pom.xml b/cmdline/maven/tests/sl-17/pom.xml
index 405c3e6..0dadded 100644
--- a/cmdline/maven/tests/sl-17/pom.xml
+++ b/cmdline/maven/tests/sl-17/pom.xml
@@ -54,8 +54,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
- <source>1.7</source>
- <target>1.7</target>
+ <source>17</source>
+ <target>17</target>
</configuration>
</plugin>
</plugins>
diff --git a/cmdline/maven/tests/sl-1_17/golden b/cmdline/maven/tests/sl-1_17/golden
new file mode 100644
index 0000000..3f978f9
--- /dev/null
+++ b/cmdline/maven/tests/sl-1_17/golden
@@ -0,0 +1,2 @@
+
+result: 0
\ No newline at end of file
diff --git a/cmdline/maven/tests/sl-18/jackpot-settings.xml b/cmdline/maven/tests/sl-1_17/jackpot-settings.xml
similarity index 100%
copy from cmdline/maven/tests/sl-18/jackpot-settings.xml
copy to cmdline/maven/tests/sl-1_17/jackpot-settings.xml
diff --git a/cmdline/maven/tests/sl-1_17/pom.xml b/cmdline/maven/tests/sl-1_17/pom.xml
new file mode 100644
index 0000000..405c3e6
--- /dev/null
+++ b/cmdline/maven/tests/sl-1_17/pom.xml
@@ -0,0 +1,63 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.netbeans.modules.jackpot30</groupId>
+ <artifactId>maven-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>jackpot30-maven-plugin-test1</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
+ <artifactId>jackpot30-maven-plugin</artifactId>
+ <version>${jackpot.plugin.version}</version>
+ <configuration>
+ <configurationFile>jackpot-settings.xml</configurationFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/cmdline/maven/tests/sl-18/src/main/java/test/App.java b/cmdline/maven/tests/sl-1_17/src/main/java/test/App.java
similarity index 100%
copy from cmdline/maven/tests/sl-18/src/main/java/test/App.java
copy to cmdline/maven/tests/sl-1_17/src/main/java/test/App.java
diff --git a/cmdline/maven/tests/sl-18/golden b/cmdline/maven/tests/sl-1_18/golden
similarity index 96%
rename from cmdline/maven/tests/sl-18/golden
rename to cmdline/maven/tests/sl-1_18/golden
index 880da9c..91c448d 100644
--- a/cmdline/maven/tests/sl-18/golden
+++ b/cmdline/maven/tests/sl-1_18/golden
@@ -1,3 +1,5 @@
${basedir}/src/main/java/test/App.java:24: warning: [Convert_to_Lambda_or_Member_Reference] This anonymous inner class creation can be turned into a lambda expression.
Runnable r = new Runnable() { public void run() { } };
^
+
+result: 0
\ No newline at end of file
diff --git a/cmdline/maven/tests/sl-18/jackpot-settings.xml b/cmdline/maven/tests/sl-1_18/jackpot-settings.xml
similarity index 100%
rename from cmdline/maven/tests/sl-18/jackpot-settings.xml
rename to cmdline/maven/tests/sl-1_18/jackpot-settings.xml
diff --git a/cmdline/maven/tests/sl-18/pom.xml b/cmdline/maven/tests/sl-1_18/pom.xml
similarity index 100%
rename from cmdline/maven/tests/sl-18/pom.xml
rename to cmdline/maven/tests/sl-1_18/pom.xml
diff --git a/cmdline/maven/tests/sl-18/src/main/java/test/App.java b/cmdline/maven/tests/sl-1_18/src/main/java/test/App.java
similarity index 100%
rename from cmdline/maven/tests/sl-18/src/main/java/test/App.java
rename to cmdline/maven/tests/sl-1_18/src/main/java/test/App.java
diff --git a/cmdline/maven/tests/sl-failure/golden b/cmdline/maven/tests/sl-failure/golden
new file mode 100644
index 0000000..44933b4
--- /dev/null
+++ b/cmdline/maven/tests/sl-failure/golden
@@ -0,0 +1,10 @@
+unrecognized source level specification: unparseable
+[ERROR] Failed to execute goal org.apache.netbeans.modules.jackpot30:jackpot30-maven-plugin:13.0:analyze (default-cli) on project maven-test: jackpo30 failed. -> [Help 1]
+[ERROR]
+[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
+[ERROR] Re-run Maven using the -X switch to enable full debug logging.
+[ERROR]
+[ERROR] For more information about the errors and possible solutions, please read the following articles:
+[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
+
+result: 1
\ No newline at end of file
diff --git a/cmdline/maven/tests/sl-18/jackpot-settings.xml b/cmdline/maven/tests/sl-failure/jackpot-settings.xml
similarity index 100%
copy from cmdline/maven/tests/sl-18/jackpot-settings.xml
copy to cmdline/maven/tests/sl-failure/jackpot-settings.xml
diff --git a/cmdline/maven/tests/sl-failure/pom.xml b/cmdline/maven/tests/sl-failure/pom.xml
new file mode 100644
index 0000000..c73ba01
--- /dev/null
+++ b/cmdline/maven/tests/sl-failure/pom.xml
@@ -0,0 +1,63 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.netbeans.modules.jackpot30</groupId>
+ <artifactId>maven-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>jackpot30-maven-plugin-test1</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
+ <artifactId>jackpot30-maven-plugin</artifactId>
+ <version>${jackpot.plugin.version}</version>
+ <configuration>
+ <configurationFile>jackpot-settings.xml</configurationFile>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>unparseable</source>
+ <target>17</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/cmdline/maven/tests/sl-18/src/main/java/test/App.java b/cmdline/maven/tests/sl-failure/src/main/java/test/App.java
similarity index 100%
copy from cmdline/maven/tests/sl-18/src/main/java/test/App.java
copy to cmdline/maven/tests/sl-failure/src/main/java/test/App.java
diff --git a/cmdline/maven/tests/test-custom/golden b/cmdline/maven/tests/test-custom/golden
index c1e0330..a608289 100644
--- a/cmdline/maven/tests/test-custom/golden
+++ b/cmdline/maven/tests/test-custom/golden
@@ -1,3 +1,5 @@
${basedir}/src/main/java/test/App.java:23: warning: [test] test
System.err.println(args[0].length() == 0);
^
+
+result: 0
\ No newline at end of file
diff --git a/cmdline/maven/tests/test1/golden b/cmdline/maven/tests/test1/golden
index 6bafa1b..b3fdf54 100644
--- a/cmdline/maven/tests/test1/golden
+++ b/cmdline/maven/tests/test1/golden
@@ -1,3 +1,5 @@
${basedir}/src/main/java/test/App.java:25: warning: [Synchronization_on_non_final_field] Synchronization on non-final field
synchronized (LOCK) {
^
+
+result: 0
\ No newline at end of file
diff --git a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
index 35c2d2c..b72e704 100644
--- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
+++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
@@ -129,8 +129,8 @@
private static final String OPTION_NO_APPLY = "no-apply";
private static final String OPTION_FAIL_ON_WARNINGS = "fail-on-warnings";
private static final String RUN_TESTS = "run-tests";
- private static final String SOURCE_LEVEL_DEFAULT = "1.7";
- private static final String ACCEPTABLE_SOURCE_LEVEL_PATTERN = "(1\\.)?[2-9][0-9]*";
+ private static final String SOURCE_LEVEL_DEFAULT = "1.8";
+ private static final String ACCEPTABLE_SOURCE_LEVEL_PATTERN = "(1\\.)?[1-9][0-9]*";
public static void main(String... args) throws IOException, ClassNotFoundException {
System.exit(compile(args));
diff --git a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
index 2865c0d..ccc4b17 100644
--- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
+++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
@@ -1035,6 +1035,32 @@
assertEquals(3, Main.findLineForPos(new HashMap<FileObject, int[]>(), test1, 20));
}
+ public void testSource17() throws Exception {
+ String golden =
+ "package test;\n" +
+ "public class Test {\n" +
+ " private void test(java.util.Collection c) {\n" +
+ " boolean b = c.isEmpty();\n" +
+ " }\n" +
+ "}\n";
+
+ doRunCompiler(golden,
+ null,
+ null,
+ "src/test/Test.java",
+ "package test;\n" +
+ "public class Test {\n" +
+ " private void test(java.util.Collection c) {\n" +
+ " boolean b = c.size() == 0;\n" +
+ " }\n" +
+ "}\n",
+ null,
+ "--apply",
+ "--hint",
+ TEST_HINT,
+ "--source", "17");
+ }
+
private static final String DONT_APPEND_PATH = new String("DONT_APPEND_PATH");
private static final String IGNORE = new String("IGNORE");