changeset 17225:28d099962ee2

8182032: Make java.compiler upgradeable Reviewed-by: alanb, erikj
author mchung
date Thu, 15 Jun 2017 11:54:49 -0700
parents 6b8f8ab175ff
children dfeb383db3bb
files test/jdk/modules/etc/UpgradeableModules.java test/jdk/modules/etc/VerifyModuleDelegation.java
diffstat 2 files changed, 108 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/modules/etc/UpgradeableModules.java	Thu Jun 15 11:54:49 2017 -0700
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017, 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 Verify that upgradeable modules are not hashed in java.base
+ *          whereas non-upgradeable modules are.
+ * @modules java.base/jdk.internal.module
+ * @run main UpgradeableModules
+ */
+
+import jdk.internal.module.ModuleHashes;
+import jdk.internal.module.ModuleReferenceImpl;
+
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReference;
+import java.lang.module.ResolvedModule;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class UpgradeableModules {
+    private static final List<String> UPGRADEABLE_MODULES =
+        List.of("java.activation",
+                "java.compiler",
+                "java.corba",
+                "java.jnlp",
+                "java.transaction",
+                "java.xml.bind",
+                "java.xml.ws",
+                "java.xml.ws.annotation",
+                "jdk.internal.vm.compiler",
+                "jdk.deploy",
+                "jdk.javaws",
+                "jdk.plugin",
+                "jdk.plugin.dom",
+                "jdk.xml.bind",
+                "jdk.xml.ws");
+
+    public static void main(String... args) {
+        Set<String> hashedModules = hashedModules();
+        if (hashedModules.isEmpty())
+            return;
+
+        if (UPGRADEABLE_MODULES.stream().anyMatch(hashedModules::contains)) {
+            throw new RuntimeException("upgradeable modules are hashed: " +
+                UPGRADEABLE_MODULES.stream()
+                    .filter(hashedModules::contains)
+                    .collect(Collectors.joining(" ")));
+        }
+
+        Set<String> nonUpgradeableModules =
+            ModuleFinder.ofSystem().findAll().stream()
+                .map(mref -> mref.descriptor().name())
+                .filter(mn -> !UPGRADEABLE_MODULES.contains(mn))
+                .collect(Collectors.toSet());
+
+        if (nonUpgradeableModules.stream().anyMatch(mn -> !hashedModules.contains(mn))) {
+            throw new RuntimeException("non-upgradeable modules are not hashed: " +
+                nonUpgradeableModules.stream()
+                    .filter(mn -> !hashedModules.contains(mn))
+                    .collect(Collectors.joining(" ")));
+        }
+    }
+
+    private static Set<String> hashedModules() {
+        Optional<ResolvedModule> resolvedModule = ModuleLayer.boot()
+            .configuration()
+            .findModule("java.base");
+        assert resolvedModule.isPresent();
+        ModuleReference mref = resolvedModule.get().reference();
+        assert mref instanceof ModuleReferenceImpl;
+        ModuleHashes hashes = ((ModuleReferenceImpl) mref).recordedHashes();
+        if (hashes != null) {
+            Set<String> names = new HashSet<>(hashes.names());
+            names.add("java.base");
+            return names;
+        }
+
+        return Set.of();
+    }
+}
--- a/test/jdk/modules/etc/VerifyModuleDelegation.java	Thu Jun 15 17:43:21 2017 +0000
+++ b/test/jdk/modules/etc/VerifyModuleDelegation.java	Thu Jun 15 11:54:49 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, 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
@@ -29,13 +29,9 @@
  */
 
 import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleReference;
 import java.util.Set;
 import static java.util.stream.Collectors.toSet;
 
-import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
-
 import org.testng.annotations.*;
 
 import static org.testng.Assert.*;
@@ -76,8 +72,9 @@
                      ClassLoader loader1 = boot.findLoader(md.name());
                      ClassLoader loader2 = boot.findLoader(req.name());
                      if (loader1 != loader2 && !isAncestor(loader2, loader1)) {
-                         throw new Error(md.name() + " can't delegate to " +
-                                         "find classes from " + req.name());
+                         throw new Error(loader1.getName() + "/" + md.name() +
+                             " can't delegate to find classes from " +
+                             loader2.getName() + "/" + req.name());
                      }
                  }));
     }