From dd8b5f45ddc0d1693ab7132c14f02e2d2d09c850 Mon Sep 17 00:00:00 2001
From: Tomas Zezula null
.
+ * @return the main module with optional classname command line argument.
+ * @since ???
+ */
+ private static String createModuleClassPair(final String module, final String classname) {
+ return classname == null ?
+ module :
+ String.format("%s/%s", module, classname); //NOI18N
+ }
+
+ /**
+ * Parses a module name from JDK 9 main module command line argument.
+ * @param moduleClassPair a module with optional classname or null
.
+ * @return the module name or null
.
+ * @since ???
+ */
+ private static String parseModuleFromModuleClassPair(final String moduleClassPair) {
+ if (moduleClassPair == null) {
+ return null;
+ }
+ final String[] moduleAndClass = moduleClassPair.split("/"); //NOI18N
+ return moduleAndClass[0];
+ }
+
+ /**
+ * Parses a classname from JDK 9 main module command line argument.
+ * @param moduleClassPair a module with optional classname or null
.
+ * @return the classname or null
.
+ * @since ???
+ */
+ private static String parseClassFromModuleClassPair(final String moduleClassPair) {
+ if (moduleClassPair == null) {
+ return null;
+ }
+ final String[] moduleAndClass = moduleClassPair.split("/"); //NOI18N
+ return moduleAndClass.length == 2 ?
+ moduleAndClass[1] :
+ null;
+ }
+
+ /**
+ * Type of execution.
+ * @since ???
+ */
+ private enum ExecutableType {
+ /**
+ * Main class execution.
+ */
+ CLASS,
+ /**
+ * Jar file execution.
+ */
+ JAR,
+ /**
+ * Module execution.
+ */
+ MODULE
+ }
}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
index d54b8f28e..8d9957180 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java
@@ -41,6 +41,8 @@ import org.junit.Test;
import org.junit.internal.AssumptionViolatedException;
import static org.apache.tools.ant.AntAssert.assertContains;
+import org.apache.tools.ant.types.Path;
+import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -118,10 +120,94 @@ public class JavaTest {
buildRule.executeTarget("testClassnameAndJar");
fail("Build exception should have been thrown - both classname and JAR are not allowed");
} catch (BuildException ex) {
- assertEquals("Cannot use 'jar' and 'classname' attributes in same command.", ex.getMessage());
+ assertEquals("Cannot use 'jar' with 'classname' or 'module' attributes in same command.", ex.getMessage());
}
}
+ @Test
+ public void testJarAndModule() {
+ try {
+ buildRule.executeTarget("testJarAndModule");
+ fail("Build exception should have been thrown - both module and JAR are not allowed");
+ } catch (BuildException ex) {
+ assertEquals("Cannot use 'jar' and 'module' attributes in same command", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testModuleAndJar() {
+ try {
+ buildRule.executeTarget("testModuleAndJar");
+ fail("Build exception should have been thrown - both module and JAR are not allowed");
+ } catch (BuildException ex) {
+ assertEquals("Cannot use 'jar' with 'classname' or 'module' attributes in same command.", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testClassnameAndModule() {
+ buildRule.executeTarget("testClassnameAndModule");
+ }
+
+ @Test
+ public void testModuleAndClassname() {
+ buildRule.executeTarget("testModuleAndClassname");
+ }
+
+ @Test
+ public void testModule() {
+ buildRule.executeTarget("testModule");
+ }
+
+ @Test
+ public void testModuleCommandLine() {
+ final String moduleName = "TestModule"; //NOI18N
+ final String arg = "appArg"; //NOI18N
+ final Java java = new Java();
+ java.setFork(true);
+ java.setModule(moduleName);
+ java.setJvmargs("-Xmx128M");
+ java.setArgs(arg);
+ final String[] cmdLine = java.getCommandLine().getCommandline();
+ Assert.assertNotNull("Has command line.", cmdLine);
+ assertEquals("Command line should have 5 elements", 5, cmdLine.length);
+ assertEquals("Last command line element should be java argument: " + arg,
+ arg,
+ cmdLine[cmdLine.length-1]);
+ assertEquals("The command line element at index 3 should be module name: " + moduleName,
+ moduleName,
+ cmdLine[cmdLine.length-2]);
+ assertEquals("The command line element at index 2 should be -m",
+ "-m",
+ cmdLine[cmdLine.length-3]);
+ }
+
+ @Test
+ public void testModuleAndClassnameCommandLine() {
+ final String moduleName = "TestModule"; //NOI18N
+ final String className = "org.apache.Test"; //NOI18N
+ final String moduleClassPair= String.format("%s/%s", moduleName, className);
+ final String arg = "appArg"; //NOI18N
+ final Java java = new Java();
+ java.setFork(true);
+ java.setModule(moduleName);
+ java.setClassname(className);
+ java.setJvmargs("-Xmx128M"); //NOI18N
+ java.setArgs(arg);
+ final String[] cmdLine = java.getCommandLine().getCommandline();
+ Assert.assertNotNull("Has command line.", cmdLine);
+ assertEquals("Command line should have 5 elements", 5, cmdLine.length);
+ assertEquals("Last command line element should be java argument: " + arg,
+ arg,
+ cmdLine[cmdLine.length-1]);
+ assertEquals("The command line element at index 3 should be module class pair: " + moduleClassPair,
+ moduleClassPair,
+ cmdLine[cmdLine.length-2]);
+ assertEquals("The command line element at index 2 should be -m",
+ "-m",
+ cmdLine[cmdLine.length-3]);
+ }
+
@Test
public void testRun() {
buildRule.executeTarget("testRun");
From aef407be4d33de09861a1f9677b2f15ea5ea8fdf Mon Sep 17 00:00:00 2001
From: Tomas Zezula
<java>
must return 0 otherwise the build will
exit, as the class was run by the build JVM.
+Java
's modulepath attribute is a PATH like structure and can also be set via a nested
+modulepath element.
The location of modules that replace upgradeable modules in the runtime image +can be specified using this PATH like structure.
+ +The parameter of the jar attribute is of type File;
@@ -400,6 +431,31 @@ log-prefix to [java1.4]
.
JVM, as it takes different parameters for other JVMs,
That JVM can be started from <exec>
if required.
+ <java + fork="true" + failonerror="true" + maxmemory="128m" + module="TestModule" + modulepath="lib:dist/test.jar"/> ++Runs the module TestModule resolved on the modulepath lib/:dist/test.jar +with a maximum memory of 128MB. Any non zero return code breaks the build. +
+ <java + fork="true" + failonerror="true" + maxmemory="128m" + module="TestModule" + classname="Main"> + <modulepath> + <pathelement location="lib"/> + <pathelement location="dist/test.jar"/> + </modulepath> + </java> ++Runs the class Main in module TestModule resolved on the modulepath lib/:dist/test.jar +with a maximum memory of 128MB. Any non zero return code breaks the build.