changeset 13545:d766c19978ef

Rename Configuration references/findReference to modules/findModule
author alanb
date Thu, 30 Jul 2015 10:42:32 +0100
parents 01989b3e4652
children aba5be17a1e8
files src/java.base/share/classes/java/lang/module/Configuration.java src/java.base/share/classes/java/lang/module/Layer.java src/java.base/share/classes/java/lang/module/Resolver.java src/java.base/share/classes/java/lang/reflect/Module.java src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java src/java.base/share/classes/sun/launcher/LauncherHelper.java test/jdk/jigsaw/launcher/upgrademodulepath/src/test/jdk/test/Main.java test/jdk/jigsaw/module/ConfigurationTest.java test/jdk/jigsaw/resources/basic/Basic.java test/jdk/jigsaw/services/layer/CustomLayerTest.java
diffstat 10 files changed, 55 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/module/Configuration.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/src/java.base/share/classes/java/lang/module/Configuration.java	Thu Jul 30 10:42:32 2015 +0100
@@ -140,7 +140,7 @@
     }
 
     /**
-     * Returns the {@code Layer} used when creating this configuration.
+     * Returns the parent {@code Layer} on which this configuration is based.
      */
     public Layer layer() {
         return parent;
@@ -177,24 +177,24 @@
      * Returns an immutable set of the module references in this
      * configuration.
      */
-    public Set<ModuleReference> references() {
+    public Set<ModuleReference> modules() {
         return resolution.references();
     }
 
     /**
-     * Returns the {@code ModuleReference} for the named module.
-     */
-    public Optional<ModuleReference> findReference(String name) {
-        return resolution.findReference(name);
-    }
-
-    /**
      * Returns the {@code ModuleDescriptor} for the named module.
      *
      * @apiNote It's not clear that this method is useful.
      */
     public Optional<ModuleDescriptor> findDescriptor(String name) {
-        return findReference(name).map(ModuleReference::descriptor);
+        return findModule(name).map(ModuleReference::descriptor);
+    }
+
+    /**
+     * Returns the {@code ModuleReference} for the named module.
+     */
+    public Optional<ModuleReference> findModule(String name) {
+        return resolution.findModule(name);
     }
 
     /**
--- a/src/java.base/share/classes/java/lang/module/Layer.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/src/java.base/share/classes/java/lang/module/Layer.java	Thu Jul 30 10:42:32 2015 +0100
@@ -268,7 +268,7 @@
     Optional<ModuleReference> findReference(String name) {
         if (cf == null)
             return Optional.empty();
-        Optional<ModuleReference> omref = cf.findReference(name);
+        Optional<ModuleReference> omref = cf.findModule(name);
         if (omref.isPresent())
             return omref;
         return parent().flatMap(l -> l.findReference(name));
--- a/src/java.base/share/classes/java/lang/module/Resolver.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/src/java.base/share/classes/java/lang/module/Resolver.java	Thu Jul 30 10:42:32 2015 +0100
@@ -98,7 +98,7 @@
             return references;
         }
 
-        Optional<ModuleReference> findReference(String name) {
+        Optional<ModuleReference> findModule(String name) {
             return Optional.ofNullable(nameToReference.get(name));
         }
 
@@ -749,7 +749,8 @@
 
     /**
      * Checks the readability graph to ensure that no two modules export the
-     * same package to a module.
+     * same package to a module. This includes the case where module M has
+     * a local package P and M reads another module that exports P to M.
      */
     private static void
     checkExportSuppliers(Map<ModuleDescriptor, Set<ModuleDescriptor>> graph) {
--- a/src/java.base/share/classes/java/lang/reflect/Module.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/src/java.base/share/classes/java/lang/reflect/Module.java	Thu Jul 30 10:42:32 2015 +0100
@@ -782,7 +782,7 @@
 
         // define each module in the configuration to the VM and register
         // with each class loader.
-        for (ModuleReference mref : cf.references()) {
+        for (ModuleReference mref : cf.modules()) {
             String name = mref.descriptor().name();
             ClassLoader loader = clf.loaderForModule(name);
             Module m = defineModule(loader, mref);
--- a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Thu Jul 30 10:42:32 2015 +0100
@@ -182,7 +182,7 @@
         // check that all modules to be mapped to the boot loader will be
         // loaded from the system module path
         if (finder != systemModulePath) {
-            for (ModuleReference mref : cf.references()) {
+            for (ModuleReference mref : cf.modules()) {
                 String name = mref.descriptor().name();
                 ClassLoader cl = clf.loaderForModule(name);
                 if (cl == null) {
--- a/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Thu Jul 30 10:42:32 2015 +0100
@@ -473,7 +473,7 @@
         // main module should be in the boot layer
         Layer layer = Layer.boot();
         ModuleReference mref
-            = layer.configuration().get().findReference(mainModule).orElse(null);
+            = layer.configuration().get().findModule(mainModule).orElse(null);
         if (mref == null)
             abort(null, "java.launcher.module.error1", mainModule);
 
@@ -885,7 +885,7 @@
         Configuration cf = layer.configuration().get();
         int colon = optionFlag.indexOf(':');
         if (colon == -1) {
-            cf.references().stream()
+            cf.modules().stream()
                 .sorted(Comparator.comparing(ModuleReference::descriptor))
                 .forEach(md -> {
                         ostream.println(midAndLocation(md.descriptor(),
@@ -894,7 +894,7 @@
         } else {
             String[] names = optionFlag.substring(colon+1).split(",");
             for (String name: names) {
-                ModuleReference mref = cf.findReference(name).orElse(null);
+                ModuleReference mref = cf.findModule(name).orElse(null);
                 if (mref == null) {
                     // skip as module is not in the boot Layer
                     continue;
--- a/test/jdk/jigsaw/launcher/upgrademodulepath/src/test/jdk/test/Main.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/test/jdk/jigsaw/launcher/upgrademodulepath/src/test/jdk/test/Main.java	Thu Jul 30 10:42:32 2015 +0100
@@ -37,7 +37,7 @@
 
         Configuration cf = Layer.boot().configuration().get();
         System.out.format("%s loaded from %s%n", m1,
-                          cf.findReference(m1.getName()).get().location().get());
+                          cf.findModule(m1.getName()).get().location().get());
 
         if (m1 != m2 || !m1.getName().equals("java.annotations.common"))
             throw new RuntimeException("java.annotations.common not upgraded");
--- a/test/jdk/jigsaw/module/ConfigurationTest.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/test/jdk/jigsaw/module/ConfigurationTest.java	Thu Jul 30 10:42:32 2015 +0100
@@ -75,11 +75,16 @@
         assertTrue(cf.descriptors().contains(descriptor2));
         assertTrue(cf.descriptors().contains(descriptor3));
 
-        assertEquals(cf.references().stream()
-                     .map(ModuleReference::descriptor)
-                     .collect(Collectors.toSet()),
+        assertEquals(cf.modules().stream()
+                        .map(ModuleReference::descriptor)
+                        .collect(Collectors.toSet()),
                      cf.descriptors());
 
+        assertTrue(cf.findModule("m1").isPresent());
+        assertTrue(cf.findModule("m2").isPresent());
+        assertTrue(cf.findModule("m3").isPresent());
+
+
         // m1 reads m2
         assertTrue(cf.reads(descriptor1).size() == 1);
         assertTrue(cf.reads(descriptor1).contains(descriptor2));
@@ -128,6 +133,14 @@
         assertTrue(cf.descriptors().contains(descriptor2));
         assertTrue(cf.descriptors().contains(descriptor3));
 
+        assertEquals(cf.modules().stream()
+                        .map(ModuleReference::descriptor)
+                        .collect(Collectors.toSet()),
+                cf.descriptors());
+
+        assertTrue(cf.findModule("m1").isPresent());
+        assertTrue(cf.findModule("m2").isPresent());
+
         // m1 reads m2 and m3
         assertTrue(cf.reads(descriptor1).size() == 2);
         assertTrue(cf.reads(descriptor1).contains(descriptor2));
@@ -182,6 +195,14 @@
         assertTrue(cf.descriptors().contains(descriptor1));
         assertTrue(cf.descriptors().contains(descriptor2));
 
+        assertEquals(cf.modules().stream()
+                        .map(ModuleReference::descriptor)
+                        .collect(Collectors.toSet()),
+                cf.descriptors());
+
+        assertTrue(cf.findModule("m1").isPresent());
+        assertTrue(cf.findModule("m2").isPresent());
+
         assertTrue(cf.reads(descriptor1).size() == 1);
         assertTrue(cf.reads(descriptor1).contains(descriptor2));
 
@@ -197,6 +218,15 @@
         assertTrue(cf.descriptors().contains(descriptor2));
         assertTrue(cf.descriptors().contains(descriptor3));
 
+        assertEquals(cf.modules().stream()
+                        .map(ModuleReference::descriptor)
+                        .collect(Collectors.toSet()),
+                cf.descriptors());
+
+        assertTrue(cf.findModule("m1").isPresent());
+        assertTrue(cf.findModule("m2").isPresent());
+        assertTrue(cf.findModule("m3").isPresent());
+
         assertTrue(cf.reads(descriptor1).size() == 1);
         assertTrue(cf.reads(descriptor1).contains(descriptor2));
 
--- a/test/jdk/jigsaw/resources/basic/Basic.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/test/jdk/jigsaw/resources/basic/Basic.java	Thu Jul 30 10:42:32 2015 +0100
@@ -103,7 +103,7 @@
      */
     static Path directoryFor(String name) {
         Configuration cf = Layer.boot().configuration().get();
-        ModuleReference mref = cf.findReference(name).orElse(null);
+        ModuleReference mref = cf.findModule(name).orElse(null);
         if (mref == null)
             throw new RuntimeException("not found: " + name);
         Path dir = Paths.get(mref.location().get());
--- a/test/jdk/jigsaw/services/layer/CustomLayerTest.java	Thu Jul 30 10:12:06 2015 +0100
+++ b/test/jdk/jigsaw/services/layer/CustomLayerTest.java	Thu Jul 30 10:42:32 2015 +0100
@@ -54,7 +54,7 @@
 
         // create the Layer with the module loaded by the system class loader
         ClassLoader scl = ClassLoader.getSystemClassLoader();
-        ModuleReference mref = cf.findReference(moduleName).get();
+        ModuleReference mref = cf.findModule(moduleName).get();
         Layer layer = Layer.create(cf, k -> scl);
 
         ServiceLoader<ScriptEngineFactory> sl;