changeset 14289:8e9e10f00315

Merge
author chegar
date Mon, 19 Oct 2015 14:04:34 +0100
parents 03b57356b5c9 611f51c4a887
children b9faea9a4ea2
files
diffstat 6 files changed, 99 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/make/launcher/Launcher-java.desktop.gmk	Mon Oct 19 14:04:21 2015 +0100
+++ b/make/launcher/Launcher-java.desktop.gmk	Mon Oct 19 14:04:34 2015 +0100
@@ -30,7 +30,8 @@
 
 ifndef BUILD_HEADLESS_ONLY
   $(eval $(call SetupLauncher,appletviewer, \
-      -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "-m"$(COMMA) "java.desktop/sun.applet.Main"$(COMMA) }',, \
+      -DJAVA_ARGS='{ "-J-ms8m"$(COMMA) "-addmods"$(COMMA) "ALL-SYSTEM"$(COMMA) \
+          "-m"$(COMMA) "java.desktop/sun.applet.Main"$(COMMA) }',, \
       $(XLIBS)))
 endif
 
--- a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Mon Oct 19 14:04:21 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Mon Oct 19 14:04:34 2015 +0100
@@ -66,6 +66,10 @@
     // the token for "all unnamed modules"
     private static final String ALL_UNNAMED = "ALL-UNNAMED";
 
+    // the token for "all system modules"
+    private static final String ALL_SYSTEM = "ALL-SYSTEM";
+
+
     /**
      * Initialize the module system, returning the boot Layer.
      *
@@ -108,12 +112,17 @@
         String mainModule = System.getProperty("jdk.module.main");
 
         // additional module(s) specified by -addmods
-        Set<String> additionalMods = null;
+        boolean addAllSystemModules = false;
+        Set<String> addModules = null;
         String propValue = System.getProperty("jdk.launcher.addmods");
         if (propValue != null) {
-            additionalMods = new HashSet<>();
+            addModules = new HashSet<>();
             for (String mod: propValue.split(",")) {
-                additionalMods.add(mod);
+                if (mod.equals(ALL_SYSTEM)) {
+                    addAllSystemModules = true;
+                } else {
+                    addModules.add(mod);
+                }
             }
         }
 
@@ -127,26 +136,31 @@
             }
             if (mainModule != null)
                 mods.add(mainModule);
+            if (addModules != null)
+                mods.addAll(addModules);
             finder = limitFinder(finder, mods);
             limitmods = true;
         }
 
         // The root modules to resolve
         Set<String> roots = new HashSet<>();
-        if (mainModule != null) {
 
-            // main/initial module
+        // main/initial module
+        if (mainModule != null)
             roots.add(mainModule);
 
-        } else {
+        // If -addmods is specified then those modules need to be resolved
+        if (addModules != null)
+            roots.addAll(addModules);
 
-            // If there is no initial module specified then assume that the
-            // initial module is the unnamed module of the application class
-            // loader. By convention, and for compatibility, this is
-            // implemented by putting the names of all modules on the system
-            // module path into the set of modules to resolve. If the
-            // -limitmods option is specified then it may be a subset of the
-            // system module path.
+        // If there is no initial module specified then assume that the
+        // initial module is the unnamed module of the application class
+        // loader. By convention, and for compatibility, this is
+        // implemented by putting the names of all modules on the system
+        // module path into the set of modules to resolve. If the
+        // -limitmods option is specified then it may be a subset of the
+        // system module path.
+        if (mainModule == null || addAllSystemModules) {
             Set<ModuleReference> mrefs = systemModulePath.findAll();
             if (limitmods) {
                 ModuleFinder f = finder;
@@ -160,10 +174,6 @@
             }
         }
 
-        // If -addmods is specified then these module names must be resolved
-        if (additionalMods != null)
-            roots.addAll(additionalMods);
-
         long t1 = System.nanoTime();
 
         // run the resolver to create the configuration
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/JlinkTask.java	Mon Oct 19 14:04:21 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/JlinkTask.java	Mon Oct 19 14:04:34 2015 +0100
@@ -309,7 +309,7 @@
         ImageProvider imageProvider
                 = createImageProvider(config.getOutput(),
                         finder,
-                        checkAddMods(config.getModules(), config.getLimitmods()),
+                        checkAddMods(config.getModules()),
                         config.getLimitmods(),
                         genBOMContent(config, plugins), config.getByteOrder());
 
@@ -368,7 +368,7 @@
         createOutputDirectory(options.output);
         ModuleFinder finder = newModuleFinder(options.modulePath, options.limitMods);
         try {
-            options.addMods = checkAddMods(options.addMods, options.limitMods);
+            options.addMods = checkAddMods(options.addMods);
         } catch (IllegalArgumentException ex) {
             throw taskHelper.newBadArgs("err.mods.must.be.specified", "--addmods")
                     .showUsage(true);
@@ -401,12 +401,9 @@
         Files.createDirectories(output);
     }
 
-    private static Set<String> checkAddMods(Set<String> addMods, Set<String> limitMods) {
+    private static Set<String> checkAddMods(Set<String> addMods) {
         if (addMods.isEmpty()) {
-            if (limitMods.isEmpty()) {
-                throw new IllegalArgumentException("empty modules and limitmodules");
-            }
-            addMods = limitMods;
+            throw new IllegalArgumentException("no modules to add");
         }
         return addMods;
     }
@@ -433,17 +430,13 @@
             ByteOrder order)
             throws IOException {
         if (addMods.isEmpty()) {
-            if (limitMods.isEmpty()) {
-                throw new IllegalArgumentException("empty modules and limitmods");
-            }
-            addMods = limitMods;
+            throw new IllegalArgumentException("empty modules and limitmods");
         }
         Configuration cf
                 = Configuration.resolve(finder,
                         Layer.empty(),
                         ModuleFinder.empty(),
                         addMods);
-        cf = cf.bind();
         Map<String, Path> mods = modulesToPath(finder, cf.descriptors());
         return new ImageHelper(cf, mods, output, bom, order);
     }
--- a/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties	Mon Oct 19 14:04:21 2015 +0100
+++ b/src/jdk.jlink/share/classes/jdk/tools/jlink/resources/jlink.properties	Mon Oct 19 14:04:34 2015 +0100
@@ -1,9 +1,9 @@
 main.usage.summary=\
-Usage: {0} <options> --modulepath <modulepath> --output <path>\n\
+Usage: {0} <options> --modulepath <modulepath> --addmods <mods> --output <path>\n\
 use --help for a list of possible options
 
 main.usage=\
-Usage: {0} <options> --modulepath <modulepath> --output <path>\n\
+Usage: {0} <options> --modulepath <modulepath> --addmods <mods> --output <path>\n\
 Possible options include:
 
 error.prefix=Error:
--- a/test/jdk/jigsaw/launcher/addmods/AddModsTest.java	Mon Oct 19 14:04:21 2015 +0100
+++ b/test/jdk/jigsaw/launcher/addmods/AddModsTest.java	Mon Oct 19 14:04:34 2015 +0100
@@ -80,6 +80,66 @@
         assertTrue(compiled, "app did not compile");
     }
 
+
+    /**
+     * Basic test of -addmods, using the output of -listmods to check that the
+     * module is resolved.
+     */
+    public void testAddOneModule() throws Exception {
+
+        int exitValue
+            = executeTestJava("-limitmods", "java.base",
+                              "-addmods", "java.sql",
+                              "-listmods")
+                .outputTo(System.out)
+                .errorTo(System.out)
+                .shouldContain("java.sql")
+                .shouldNotContain("java.corba")
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+
+    /**
+     * Basic test of -addmods, using the output of -listmods to check that the
+     * module is resolved.
+     */
+    public void testAddTwoModules() throws Exception {
+
+        int exitValue
+            = executeTestJava("-limitmods", "java.base",
+                              "-addmods", "java.sql,java.naming",
+                              "-listmods")
+                .outputTo(System.out)
+                .errorTo(System.out)
+                .shouldContain("java.sql")
+                .shouldContain("java.naming")
+                .shouldNotContain("java.corba")
+                .getExitValue();
+
+        assertTrue(exitValue == 0);
+    }
+
+
+    /**
+     * Basic test of -addmods ALL-SYSTEM, using the output of -listmods to
+     * check that the a sample of the system modules are resolved
+     */
+    public void testAddSystemModules() throws Exception {
+
+        executeTestJava("-addmods", "ALL-SYSTEM",
+                        "-listmods",
+                        "-m", "java.base")
+            .outputTo(System.out)
+            .errorTo(System.out)
+            .shouldContain("java.sql")
+            .shouldContain("java.corba");
+
+        // no exit value to check as -m java.base will likely fail
+    }
+
+
     /**
      * Run application on class path that makes use of module on the
      * application module path. Uses -addmods.
@@ -133,7 +193,7 @@
             = executeTestJava("-mp", MODS_DIR.toString(),
                               "-addmods", LIB_MODULE + ",DoesNotExist",
                               "-cp", CLASSES_DIR.toString(),
-                MAIN_CLASS)
+                              MAIN_CLASS)
                 .outputTo(System.out)
                 .errorTo(System.out)
                 .getExitValue();
--- a/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java	Mon Oct 19 14:04:21 2015 +0100
+++ b/test/lib/testlibrary/jdk/testlibrary/OutputAnalyzer.java	Mon Oct 19 14:04:34 2015 +0100
@@ -145,7 +145,7 @@
      * @throws RuntimeException
      *             If the string was found
      */
-    public void shouldNotContain(String notExpectedString) {
+    public OutputAnalyzer shouldNotContain(String notExpectedString) {
         if (getStdout().contains(notExpectedString)) {
             reportDiagnosticSummary();
             throw new RuntimeException("'" + notExpectedString
@@ -156,6 +156,7 @@
             throw new RuntimeException("'" + notExpectedString
                     + "' found in stderr \n");
         }
+        return this;
     }
 
     /**