This is an automated email from the ASF dual-hosted git repository. jlahoda pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans-jackpot30.git
The following commit(s) were added to refs/heads/master by this push: new ed24596 Acccept source levels 10+, allow to fail the build when warnings are reported. ed24596 is described below commit ed24596503d462e50896b2e0d851a8de5ff65e25 Author: Jan Lahoda <jlah...@netbeans.org> AuthorDate: Sat Jun 4 10:29:22 2022 +0200 Acccept source levels 10+, allow to fail the build when warnings are reported. --- .../modules/jackpot30/maven/RunJackpot30.java | 9 +++++++- .../netbeans/modules/jackpot30/maven/Utils.java | 20 ++++++++++++++++- .../modules/jackpot30/maven/RunJackpot30Test.java | 8 ++++--- cmdline/maven/tests/fail-on-warnings/golden | 12 ++++++++++ .../jackpot-settings.xml | 0 .../tests/{sl-17 => fail-on-warnings}/pom.xml | 5 +++-- .../src/main/java/test/App.java | 0 cmdline/maven/tests/sl-17/golden | 5 +++++ cmdline/maven/tests/sl-17/pom.xml | 4 ++-- cmdline/maven/tests/sl-1_17/golden | 2 ++ .../tests/{sl-18 => sl-1_17}/jackpot-settings.xml | 0 cmdline/maven/tests/{sl-17 => sl-1_17}/pom.xml | 0 .../{sl-18 => sl-1_17}/src/main/java/test/App.java | 0 cmdline/maven/tests/{sl-18 => sl-1_18}/golden | 2 ++ .../tests/{sl-18 => sl-1_18}/jackpot-settings.xml | 0 cmdline/maven/tests/{sl-18 => sl-1_18}/pom.xml | 0 .../{sl-18 => sl-1_18}/src/main/java/test/App.java | 0 cmdline/maven/tests/sl-failure/golden | 10 +++++++++ .../{sl-18 => sl-failure}/jackpot-settings.xml | 0 cmdline/maven/tests/{sl-17 => sl-failure}/pom.xml | 4 ++-- .../src/main/java/test/App.java | 0 cmdline/maven/tests/test-custom/golden | 2 ++ cmdline/maven/tests/test1/golden | 2 ++ .../netbeans/modules/jackpot30/cmdline/Main.java | 4 ++-- .../modules/jackpot30/cmdline/MainTest.java | 26 ++++++++++++++++++++++ 25 files changed, 102 insertions(+), 13 deletions(-) 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 @@ public abstract class RunJackpot30 extends AbstractMojo { } String configurationFile = Utils.getJackpotConfigurationFile(project); + boolean failOnWarnings = Utils.getJackpotFailOnWarnings(project); List<String> cmdLine = new ArrayList<String>(); @@ -70,6 +71,10 @@ public abstract class RunJackpot30 extends AbstractMojo { cmdLine.add(configurationFile); } + if (failOnWarnings) { + cmdLine.add("--fail-on-warnings"); + } + boolean hasSourceRoots = false; for (String sr : (List<String>) project.getCompileSourceRoots()) { @@ -96,7 +101,9 @@ public abstract class RunJackpot30 extends AbstractMojo { "--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 class Utils { } 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 @@ public class Utils { 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 @@ public class RunJackpot30Test extends TestCase { 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/sl-17/pom.xml b/cmdline/maven/tests/fail-on-warnings/pom.xml similarity index 94% copy from cmdline/maven/tests/sl-17/pom.xml copy to cmdline/maven/tests/fail-on-warnings/pom.xml index 405c3e6..c4536a7 100644 --- a/cmdline/maven/tests/sl-17/pom.xml +++ b/cmdline/maven/tests/fail-on-warnings/pom.xml @@ -47,6 +47,7 @@ <version>${jackpot.plugin.version}</version> <configuration> <configurationFile>jackpot-settings.xml</configurationFile> + <failOnWarnings>true</failOnWarnings> </configuration> </plugin> <plugin> @@ -54,8 +55,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-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-17/pom.xml b/cmdline/maven/tests/sl-1_17/pom.xml similarity index 100% copy from cmdline/maven/tests/sl-17/pom.xml copy to cmdline/maven/tests/sl-1_17/pom.xml 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% copy from cmdline/maven/tests/sl-18/jackpot-settings.xml copy 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% copy from cmdline/maven/tests/sl-18/src/main/java/test/App.java copy 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% rename from cmdline/maven/tests/sl-18/jackpot-settings.xml rename to cmdline/maven/tests/sl-failure/jackpot-settings.xml diff --git a/cmdline/maven/tests/sl-17/pom.xml b/cmdline/maven/tests/sl-failure/pom.xml similarity index 96% copy from cmdline/maven/tests/sl-17/pom.xml copy to cmdline/maven/tests/sl-failure/pom.xml index 405c3e6..c73ba01 100644 --- a/cmdline/maven/tests/sl-17/pom.xml +++ b/cmdline/maven/tests/sl-failure/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>unparseable</source> + <target>17</target> </configuration> </plugin> </plugins> 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% rename from cmdline/maven/tests/sl-18/src/main/java/test/App.java rename 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 @@ public class Main { 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 @@ public class MainTest extends NbTestCase { 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"); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists