8186610: move ModuleUtils to top-level testlibrary
authormli
Fri, 12 Oct 2018 10:35:24 +0800
changeset 52102 19f6b12df31a
parent 52101 5fcf63f0d86c
child 52103 4acfd9b6c2f9
8186610: move ModuleUtils to top-level testlibrary Reviewed-by: alanb, iignatyev
test/jdk/java/lang/ModuleLayer/BasicLayerTest.java
test/jdk/java/lang/ModuleLayer/LayerAndLoadersTest.java
test/jdk/java/lang/ModuleLayer/LayerControllerTest.java
test/jdk/java/lang/module/AutomaticModulesTest.java
test/jdk/java/lang/module/ConfigurationTest.java
test/jdk/lib/testlibrary/ModuleTargetHelper.java
test/jdk/lib/testlibrary/ModuleUtils.java
test/jdk/tools/jlink/plugins/SystemModuleDescriptors/ModuleTargetHelper.java
test/jdk/tools/jlink/plugins/SystemModuleDescriptors/SystemModulesTest.java
test/jdk/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java
test/lib/jdk/test/lib/util/ModuleUtils.java
--- a/test/jdk/java/lang/ModuleLayer/BasicLayerTest.java	Thu Oct 11 15:49:23 2018 -0700
+++ b/test/jdk/java/lang/ModuleLayer/BasicLayerTest.java	Fri Oct 12 10:35:24 2018 +0800
@@ -23,9 +23,10 @@
 
 /**
  * @test
- * @library /lib/testlibrary
+ * @library /test/lib
  * @modules java.base/jdk.internal.misc
- * @build BasicLayerTest ModuleUtils
+ * @build BasicLayerTest
+ *        jdk.test.lib.util.ModuleUtils
  * @compile layertest/Test.java
  * @run testng BasicLayerTest
  * @summary Basic tests for java.lang.ModuleLayer
@@ -41,6 +42,8 @@
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import jdk.test.lib.util.ModuleUtils;
+
 import jdk.internal.misc.SharedSecrets;
 
 import org.testng.annotations.DataProvider;
--- a/test/jdk/java/lang/ModuleLayer/LayerAndLoadersTest.java	Thu Oct 11 15:49:23 2018 -0700
+++ b/test/jdk/java/lang/ModuleLayer/LayerAndLoadersTest.java	Fri Oct 12 10:35:24 2018 +0800
@@ -23,9 +23,11 @@
 
 /**
  * @test
- * @library /lib/testlibrary /test/lib
+ * @library /test/lib
  * @modules jdk.compiler
- * @build LayerAndLoadersTest jdk.test.lib.compiler.CompilerUtils ModuleUtils
+ * @build LayerAndLoadersTest
+ *        jdk.test.lib.compiler.CompilerUtils
+ *        jdk.test.lib.util.ModuleUtils
  * @run testng LayerAndLoadersTest
  * @summary Tests for java.lang.ModuleLayer@defineModulesWithXXX methods
  */
@@ -54,6 +56,7 @@
 import java.util.stream.Collectors;
 
 import jdk.test.lib.compiler.CompilerUtils;
+import jdk.test.lib.util.ModuleUtils;
 
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
--- a/test/jdk/java/lang/ModuleLayer/LayerControllerTest.java	Thu Oct 11 15:49:23 2018 -0700
+++ b/test/jdk/java/lang/ModuleLayer/LayerControllerTest.java	Fri Oct 12 10:35:24 2018 +0800
@@ -23,8 +23,9 @@
 
 /**
  * @test
- * @library /lib/testlibrary
- * @build LayerControllerTest ModuleUtils
+ * @library /test/lib
+ * @build LayerControllerTest
+ *        jdk.test.lib.util.ModuleUtils
  * @run testng LayerControllerTest
  * @summary Basic tests for java.lang.ModuleLayer.Controller
  */
@@ -35,6 +36,8 @@
 import java.util.List;
 import java.util.Set;
 
+import jdk.test.lib.util.ModuleUtils;
+
 import org.testng.annotations.Test;
 import static org.testng.Assert.*;
 
--- a/test/jdk/java/lang/module/AutomaticModulesTest.java	Thu Oct 11 15:49:23 2018 -0700
+++ b/test/jdk/java/lang/module/AutomaticModulesTest.java	Fri Oct 12 10:35:24 2018 +0800
@@ -23,9 +23,10 @@
 
 /**
  * @test
- * @library /lib/testlibrary /test/lib
- * @build AutomaticModulesTest ModuleUtils
+ * @library /test/lib
+ * @build AutomaticModulesTest
  *        jdk.test.lib.util.JarUtils
+ *        jdk.test.lib.util.ModuleUtils
  * @run testng AutomaticModulesTest
  * @summary Basic tests for automatic modules
  */
@@ -50,6 +51,7 @@
 import java.util.stream.Stream;
 
 import jdk.test.lib.util.JarUtils;
+import jdk.test.lib.util.ModuleUtils;
 
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
--- a/test/jdk/java/lang/module/ConfigurationTest.java	Thu Oct 11 15:49:23 2018 -0700
+++ b/test/jdk/java/lang/module/ConfigurationTest.java	Fri Oct 12 10:35:24 2018 +0800
@@ -23,10 +23,11 @@
 
 /**
  * @test
- * @library /lib/testlibrary
+ * @library /test/lib
  * @modules java.base/jdk.internal.misc
  *          java.base/jdk.internal.module
- * @build ConfigurationTest ModuleUtils
+ * @build ConfigurationTest
+ *        jdk.test.lib.util.ModuleUtils
  * @run testng ConfigurationTest
  * @summary Basic tests for java.lang.module.Configuration
  */
@@ -47,6 +48,8 @@
 import java.util.Optional;
 import java.util.Set;
 
+import jdk.test.lib.util.ModuleUtils;
+
 import jdk.internal.misc.SharedSecrets;
 import jdk.internal.module.ModuleInfoWriter;
 import jdk.internal.module.ModuleTarget;
--- a/test/jdk/lib/testlibrary/ModuleTargetHelper.java	Thu Oct 11 15:49:23 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/*
- * 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.
- */
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.lang.module.ModuleReader;
-import java.lang.module.ModuleReference;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-import jdk.internal.module.ModuleInfo;
-import jdk.internal.module.ModuleInfo.Attributes;
-
-public class ModuleTargetHelper {
-    private ModuleTargetHelper() {}
-
-    public static final class ModuleTarget {
-        private String targetPlatform;
-
-        public ModuleTarget(String targetPlatform) {
-            this.targetPlatform = targetPlatform;
-        }
-
-        public String targetPlatform() {
-            return targetPlatform;
-        }
-    }
-
-    public static ModuleTarget getJavaBaseTarget() throws IOException {
-        Path p = Paths.get(URI.create("jrt:/modules/java.base/module-info.class"));
-        try (InputStream in = Files.newInputStream(p)) {
-            return read(in);
-        }
-    }
-
-    public static ModuleTarget read(InputStream in) throws IOException {
-        ModuleInfo.Attributes attrs = ModuleInfo.read(in, null);
-        if (attrs.target() != null) {
-            return new ModuleTarget(attrs.target().targetPlatform());
-        } else {
-            return null;
-        }
-    }
-
-    public static ModuleTarget read(ModuleReference modRef) throws IOException {
-        ModuleReader reader = modRef.open();
-        try (InputStream in = reader.open("module-info.class").get()) {
-            return read(in);
-        } finally {
-            reader.close();
-        }
-    }
-}
--- a/test/jdk/lib/testlibrary/ModuleUtils.java	Thu Oct 11 15:49:23 2018 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2015, 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.
- */
-
-import java.lang.module.ModuleDescriptor;
-import java.lang.module.ModuleFinder;
-import java.lang.module.ModuleReader;
-import java.lang.module.ModuleReference;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-
-
-/**
- * This class consists exclusively of static utility methods that are useful
- * for creating tests for modules.
- */
-
-public final class ModuleUtils {
-    private ModuleUtils() { }
-
-
-    /**
-     * Returns a ModuleFinder that finds modules with the given module
-     * descriptors.
-     */
-    static ModuleFinder finderOf(ModuleDescriptor... descriptors) {
-
-        // Create a ModuleReference for each module
-        Map<String, ModuleReference> namesToReference = new HashMap<>();
-
-        for (ModuleDescriptor descriptor : descriptors) {
-            String name = descriptor.name();
-
-            URI uri = URI.create("module:/" + name);
-
-            ModuleReference mref = new ModuleReference(descriptor, uri) {
-                @Override
-                public ModuleReader open() {
-                    throw new UnsupportedOperationException();
-                }
-            };
-
-            namesToReference.put(name, mref);
-        }
-
-        return new ModuleFinder() {
-            @Override
-            public Optional<ModuleReference> find(String name) {
-                Objects.requireNonNull(name);
-                return Optional.ofNullable(namesToReference.get(name));
-            }
-            @Override
-            public Set<ModuleReference> findAll() {
-                return new HashSet<>(namesToReference.values());
-            }
-        };
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/tools/jlink/plugins/SystemModuleDescriptors/ModuleTargetHelper.java	Fri Oct 12 10:35:24 2018 +0800
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.lang.module.ModuleReader;
+import java.lang.module.ModuleReference;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import jdk.internal.module.ModuleInfo;
+import jdk.internal.module.ModuleInfo.Attributes;
+
+public class ModuleTargetHelper {
+    private ModuleTargetHelper() {}
+
+    public static final class ModuleTarget {
+        private String targetPlatform;
+
+        public ModuleTarget(String targetPlatform) {
+            this.targetPlatform = targetPlatform;
+        }
+
+        public String targetPlatform() {
+            return targetPlatform;
+        }
+    }
+
+    public static ModuleTarget getJavaBaseTarget() throws IOException {
+        Path p = Paths.get(URI.create("jrt:/modules/java.base/module-info.class"));
+        try (InputStream in = Files.newInputStream(p)) {
+            return read(in);
+        }
+    }
+
+    public static ModuleTarget read(InputStream in) throws IOException {
+        ModuleInfo.Attributes attrs = ModuleInfo.read(in, null);
+        if (attrs.target() != null) {
+            return new ModuleTarget(attrs.target().targetPlatform());
+        } else {
+            return null;
+        }
+    }
+
+    public static ModuleTarget read(ModuleReference modRef) throws IOException {
+        ModuleReader reader = modRef.open();
+        try (InputStream in = reader.open("module-info.class").get()) {
+            return read(in);
+        } finally {
+            reader.close();
+        }
+    }
+}
--- a/test/jdk/tools/jlink/plugins/SystemModuleDescriptors/SystemModulesTest.java	Thu Oct 11 15:49:23 2018 -0700
+++ b/test/jdk/tools/jlink/plugins/SystemModuleDescriptors/SystemModulesTest.java	Fri Oct 12 10:35:24 2018 +0800
@@ -42,7 +42,6 @@
 /**
  * @test
  * @bug 8142968 8173381
- * @library /lib/testlibrary
  * @modules java.base/jdk.internal.misc
  * @modules java.base/jdk.internal.module
  * @modules java.base/jdk.internal.org.objectweb.asm
--- a/test/jdk/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java	Thu Oct 11 15:49:23 2018 -0700
+++ b/test/jdk/tools/jlink/plugins/SystemModuleDescriptors/UserModuleTest.java	Fri Oct 12 10:35:24 2018 +0800
@@ -44,7 +44,7 @@
 /**
  * @test
  * @bug 8142968 8173381 8174740
- * @library /lib/testlibrary /test/lib
+ * @library /test/lib
  * @modules jdk.compiler jdk.jlink
  * @modules java.base/jdk.internal.module
  * @modules java.base/jdk.internal.org.objectweb.asm
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/lib/jdk/test/lib/util/ModuleUtils.java	Fri Oct 12 10:35:24 2018 +0800
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package jdk.test.lib.util;
+
+import java.lang.module.ModuleDescriptor;
+import java.lang.module.ModuleFinder;
+import java.lang.module.ModuleReader;
+import java.lang.module.ModuleReference;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+
+/**
+ * This class consists exclusively of static utility methods that are useful
+ * for creating tests for modules.
+ */
+
+public final class ModuleUtils {
+    private ModuleUtils() { }
+
+
+    /**
+     * Returns a ModuleFinder that finds modules with the given module
+     * descriptors.
+     */
+    public static ModuleFinder finderOf(ModuleDescriptor... descriptors) {
+
+        // Create a ModuleReference for each module
+        Map<String, ModuleReference> namesToReference = new HashMap<>();
+
+        for (ModuleDescriptor descriptor : descriptors) {
+            String name = descriptor.name();
+
+            URI uri = URI.create("module:/" + name);
+
+            ModuleReference mref = new ModuleReference(descriptor, uri) {
+                @Override
+                public ModuleReader open() {
+                    throw new UnsupportedOperationException();
+                }
+            };
+
+            namesToReference.put(name, mref);
+        }
+
+        return new ModuleFinder() {
+            @Override
+            public Optional<ModuleReference> find(String name) {
+                Objects.requireNonNull(name);
+                return Optional.ofNullable(namesToReference.get(name));
+            }
+            @Override
+            public Set<ModuleReference> findAll() {
+                return new HashSet<>(namesToReference.values());
+            }
+        };
+    }
+
+}