From 5bbc7b6187cdb38100b3a4f9fbecb704a92bc4be Mon Sep 17 00:00:00 2001 From: Tomas Zezula Date: Fri, 9 Sep 2016 13:38:55 +0200 Subject: [PATCH] JDK9 command line options updated to JEP 293 --- manual/Tasks/junit.html | 24 +++++++++---------- .../compilers/DefaultCompilerAdapter.java | 4 ++-- .../tools/ant/types/CommandlineJava.java | 4 ++-- .../compilers/DefaultCompilerAdapterTest.java | 14 +++++------ .../optional/junit/JUnitTaskTest.java | 12 +++++----- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/manual/Tasks/junit.html b/manual/Tasks/junit.html index 9a4022e53..a6879a89b 100644 --- a/manual/Tasks/junit.html +++ b/manual/Tasks/junit.html @@ -814,10 +814,10 @@ class.
     <junit fork="true"
         jvm="${platform.java}">
-        <jvmarg value="-Xpatch:${module.name}=${build.test.classes}"/>
-        <jvmarg line="-addmods ${module.name}"/>
-        <jvmarg value="-XaddReads:${module.name}=ALL-UNNAMED"/>
-        <jvmarg value="-XaddExports:${module.name}/my.test=ALL-UNNAMED"/>
+        <jvmarg line="--patch-module ${module.name}=${build.test.classes}"/>
+        <jvmarg line="--add-modules ${module.name}"/>
+        <jvmarg line="--add-reads ${module.name}=ALL-UNNAMED"/>
+        <jvmarg line="--add-exports ${module.name}/my.test=ALL-UNNAMED"/>
         <classpath>
             <pathelement path="${libs.junit}"/>
         </classpath>
@@ -831,16 +831,16 @@ class.
 

Runs my.test.TestCase as a white-box test in the forked VM given by the platform.java property. The junit library is a part of an unnamed module while the tested project and required modules are on the module path. The tests do not have module-info file and are executed in the project module given by module.name property.
-The -Xpatch java option executes the tests built into ${build.test.classes} in a module given +The --patch-module java option executes the tests built into ${build.test.classes} in a module given by module.name property.
-The -addmods java option enables the tested module.
-The -XaddReads java option makes the unnamed module containing the junit readable by tested module.
-The -XaddExports java option makes the non-exported test package my.test accessible from the unnamed module containing the junit.
+The --add-modules java option enables the tested module.
+The --add-reads java option makes the unnamed module containing the junit readable by tested module.
+The --add-exports java option makes the non-exported test package my.test accessible from the unnamed module containing the junit.

     <junit fork="true"
         jvm="${platform.java}">
-        <jvmarg line="-addmods ${test.module.name}"/>
-        <jvmarg value="-XaddExports:${test.module.name}/my.test=junit,ALL-UNNAMED"/>
+        <jvmarg line="--add-modules ${test.module.name}"/>
+        <jvmarg line="--add-exports ${test.module.name}/my.test=junit,ALL-UNNAMED"/>
         <modulepath>
             <pathelement path="${modules}:${build.classes}:${libs.junit}"/>
         </modulepath>
@@ -850,8 +850,8 @@ The -XaddExports java option makes the non-exported test package 
 

Runs my.test.TestCase as a black-box test in the forked VM given by the platform.java property. The junit library is used as an automatic module. The tests module-info requires the tested module and junit.
-The -addmods java option enables the test module.
-The -XaddExports java option makes the non-exported test package my.test accessible from the junit module and Ant's test runner. +The --add-modules java option enables the test module.
+The --add-exports java option makes the non-exported test package my.test accessible from the junit module and Ant's test runner. Another possibility is to export the test package in the tests module-info by exports my.test directive.
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index 5f1f1f78d..f13b3e5fa 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -401,12 +401,12 @@ public abstract class DefaultCompilerAdapter } final Path msp = getModulesourcepath(); if (msp.size() > 0) { - cmd.createArgument().setValue("-modulesourcepath"); + cmd.createArgument().setValue("--module-source-path"); cmd.createArgument().setPath(msp); } final Path mp = getModulepath(); if (mp.size() > 0) { - cmd.createArgument().setValue("-modulepath"); + cmd.createArgument().setValue("--module-path"); cmd.createArgument().setPath(mp); } final Path ump = getUpgrademodulepath(); diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index 5bf91c71f..d811633e3 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -520,13 +520,13 @@ public class CommandlineJava implements Cloneable { } //module path if (haveModulepath()) { - listIterator.add("-modulepath"); + listIterator.add("--module-path"); listIterator.add( modulepath.concatSystemClasspath("ignore").toString()); } //upgrade module path if (haveUpgrademodulepath()) { - listIterator.add("-upgrademodulepath"); + listIterator.add("--upgrade-module-path"); listIterator.add( upgrademodulepath.concatSystemClasspath("ignore").toString()); } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java index 3064876df..7ed5b3fab 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java @@ -249,13 +249,13 @@ public class DefaultCompilerAdapterTest { Assert.assertNotNull(cmd[0]); final List cmdLine = Arrays.asList(cmd[0].getCommandline()); //No modulesourcepath - assertEquals(-1, cmdLine.indexOf("-modulesourcepath")); + assertEquals(-1, cmdLine.indexOf("--module-source-path")); //The -sourcepath has to be followed by src int index = cmdLine.indexOf("-sourcepath"); Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); assertEquals(src.getAbsolutePath(), cmdLine.get(index + 1)); - //The -modulepath has to be followed by modules - index = cmdLine.indexOf("-modulepath"); + //The --module-path has to be followed by modules + index = cmdLine.indexOf("--module-path"); Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); assertEquals(modules.getAbsolutePath(), cmdLine.get(index + 1)); //J1.java & J2.java has to be in files list @@ -308,8 +308,8 @@ public class DefaultCompilerAdapterTest { final List cmdLine = Arrays.asList(cmd[0].getCommandline()); //No sourcepath assertEquals(-1, cmdLine.indexOf("-sourcepath")); - //The -modulesourcepath has to be followed by the pattern - int index = cmdLine.indexOf("-modulesourcepath"); + //The --module-source-path has to be followed by the pattern + int index = cmdLine.indexOf("--module-source-path"); Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); String expectedModSrcPath = String.format("%s/%s", workDir.getAbsolutePath(), @@ -317,8 +317,8 @@ public class DefaultCompilerAdapterTest { .replace('/', File.separatorChar) .replace('\\', File.separatorChar); assertEquals(expectedModSrcPath, cmdLine.get(index + 1)); - //The -modulepath has to be followed by modules - index = cmdLine.indexOf("-modulepath"); + //The --module-path has to be followed by modules + index = cmdLine.indexOf("--module-path"); Assert.assertTrue(index != -1 && index < cmdLine.size() - 1); assertEquals(modules.getAbsolutePath(), cmdLine.get(index + 1)); //J1.java, J2.java & J3.java has to be in files list diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java index 5284d567c..d817cb10d 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java @@ -476,10 +476,10 @@ public class JUnitTaskTest { for (int i = 1; i< mockProcLauncher.cmd.length; i++) { if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N resCp = mockProcLauncher.cmd[++i]; - } else if ("-modulepath".equals(mockProcLauncher.cmd[i])) { //NOI18N + } else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N resMp = mockProcLauncher.cmd[++i]; - } else if (mockProcLauncher.cmd[i].startsWith("-XaddExports:")) { //NOI18N - resExports.add(mockProcLauncher.cmd[i]); + } else if (mockProcLauncher.cmd[i].equals("--add-exports")) { //NOI18N + resExports.add(mockProcLauncher.cmd[++i]); } else if (JUnitTestRunner.class.getName().equals(mockProcLauncher.cmd[i])) { break; } @@ -530,10 +530,10 @@ public class JUnitTaskTest { for (int i = 1; i< mockProcLauncher.cmd.length; i++) { if ("-classpath".equals(mockProcLauncher.cmd[i])) { //NOI18N resCp = mockProcLauncher.cmd[++i]; - } else if ("-modulepath".equals(mockProcLauncher.cmd[i])) { //NOI18N + } else if ("--module-path".equals(mockProcLauncher.cmd[i])) { //NOI18N resMp = mockProcLauncher.cmd[++i]; - } else if (mockProcLauncher.cmd[i].startsWith("-XaddExports:")) { //NOI18N - resExports.add(mockProcLauncher.cmd[i]); + } else if (mockProcLauncher.cmd[i].equals("--add-exports")) { //NOI18N + resExports.add(mockProcLauncher.cmd[++i]); } else if (JUnitTestRunner.class.getName().equals(mockProcLauncher.cmd[i])) { break; }