changeset 10329:336eb9bb3d56

Restore binding of services Restore -mods handling until we have a way to make modules non-observable
author alanb
date Fri, 11 Jul 2014 08:33:21 +0100
parents 273fd40c2c90
children f8a3379d8b39
files src/share/classes/sun/launcher/ModuleLauncher.java test/jdk/jigsaw/etc/dashmods/Basic.java test/jdk/jigsaw/etc/services/basic.sh
diffstat 3 files changed, 66 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/launcher/ModuleLauncher.java	Tue Jul 08 20:00:20 2014 +0100
+++ b/src/share/classes/sun/launcher/ModuleLauncher.java	Fri Jul 11 08:33:21 2014 +0100
@@ -116,7 +116,7 @@
         } else {
             modulePath = systemLibrary;
         }
-        ModuleGraph graph = new Resolver(modulePath).resolve(input);
+        ModuleGraph graph = new Resolver(modulePath).resolve(input).bindServices();
         if (verbose) {
             graph.modules().stream()
                            .sorted()
@@ -143,8 +143,23 @@
             });
         }
 
-        // define to runtime.
-        ModuleRuntime.defineModules(graph, moduleToLoaders::get);
+        // define to runtime
+        Module base = graph.findModule("java.base");
+        if (base != null) {
+            ModuleRuntime.defineModule(graph, base, null);
+            ModuleRuntime.defineModules(graph, moduleToLoaders::get);
+        }
+
+        // if -mods is specified then we have to hide the linked modules
+        // that are not selected. For now we just define the modules without
+        // any readability relationship or exports. Yes, this is a hack.
+        if (!mods.isEmpty()) {
+            Set<Module> selected = graph.modules();
+            systemLibrary.allModules()
+                         .stream()
+                         .filter(m -> !selected.contains(m))
+                         .forEach(m -> ModuleRuntime.defineProtoModule(m, moduleToLoaders.get(m)));
+        }
 
         // reflection checks enabled?
         String s = System.getProperty("sun.reflect.enableModuleChecks");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/etc/dashmods/Basic.java	Fri Jul 11 08:33:21 2014 +0100
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @summary Basic test to exercise -mods (need to use internal properties
+ *    as jtreg doesn't allow -mods due to the option using spaces)
+ * @run main/othervm -Djdk.launcher.modules=java.base Basic expect-fail
+ * @run main/othervm -Djdk.launcher.modules=java.desktop Basic expect-pass
+ */
+
+public class Basic {
+    public static void main(String[] args) {
+        boolean expectFail = args[0].equals("expect-fail");
+        boolean expectPass = args[0].equals("expect-pass");
+        if (expectFail == expectPass)
+            throw new RuntimeException("Need to run with expect-* argument");
+
+        try {
+            Class<?> c = java.awt.Component.class;
+            if (expectFail) throw new RuntimeException("No Error thrown");
+        } catch (Error e) {
+            // exact Error is TBD, will likely be NoClassDefFoundError as
+            // class should not be observable
+            if (expectPass) throw new RuntimeException(e);
+        }
+    }
+}
--- a/test/jdk/jigsaw/etc/services/basic.sh	Tue Jul 08 20:00:20 2014 +0100
+++ b/test/jdk/jigsaw/etc/services/basic.sh	Fri Jul 11 08:33:21 2014 +0100
@@ -45,7 +45,7 @@
 $JAVAC -d mods/test `find $TESTSRC/src/test -name "*.java"`
 
 # not a module
-mkdir classes
+mkdir -p classes
 $JAVAC -d classes `find $TESTSRC/src/pearscript -name "*.java"`
 cp -r $TESTSRC/src/pearscript/META-INF classes