8183536: Update jdk tests to allow for unique test classes directory
authoralanb
Wed, 05 Jul 2017 13:30:22 +0100
changeset 45833 882f4885ec80
parent 45832 f77d4be2786a
child 45834 76aad47edd31
child 46875 df84256498ae
child 47149 cc7390224989
8183536: Update jdk tests to allow for unique test classes directory Reviewed-by: lancea
jdk/test/java/lang/ModuleTests/AnnotationsTest.java
jdk/test/java/lang/invoke/DefineClassTest.java
jdk/test/java/lang/module/ConfigurationTest.java
jdk/test/java/lang/module/customfs/ModulesInCustomFileSystem.java
jdk/test/java/nio/channels/AsynchronousChannelGroup/SetupJar.java
jdk/test/java/util/ServiceLoader/ModulesTest.java
--- a/jdk/test/java/lang/ModuleTests/AnnotationsTest.java	Tue Jul 04 18:49:16 2017 -0700
+++ b/jdk/test/java/lang/ModuleTests/AnnotationsTest.java	Wed Jul 05 13:30:22 2017 +0100
@@ -28,6 +28,7 @@
 import java.lang.module.ModuleFinder;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -74,7 +75,7 @@
     public void testNamedModule() throws IOException {
 
         // "deprecate" java.xml
-        Path dir = Files.createTempDirectory("mods");
+        Path dir = Files.createTempDirectory(Paths.get(""), "mods");
         deprecateModule("java.xml", true, "9", dir);
 
         // "load" the cloned java.xml
--- a/jdk/test/java/lang/invoke/DefineClassTest.java	Tue Jul 04 18:49:16 2017 -0700
+++ b/jdk/test/java/lang/invoke/DefineClassTest.java	Wed Jul 05 13:30:22 2017 +0100
@@ -37,6 +37,7 @@
 import java.net.URLClassLoader;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.MethodVisitor;
@@ -164,14 +165,16 @@
      */
     @Test
     public void testTwoProtectionDomains() throws Exception {
+        Path here = Paths.get("");
+
         // p.C1 in one exploded directory
-        Path dir1 = Files.createTempDirectory("classes");
+        Path dir1 = Files.createTempDirectory(here, "classes");
         Path p = Files.createDirectory(dir1.resolve("p"));
         Files.write(p.resolve("C1.class"), generateClass("p.C1"));
         URL url1 = dir1.toUri().toURL();
 
         // p.C2 in another exploded directory
-        Path dir2 = Files.createTempDirectory("classes");
+        Path dir2 = Files.createTempDirectory(here, "classes");
         p = Files.createDirectory(dir2.resolve("p"));
         Files.write(p.resolve("C2.class"), generateClass("p.C2"));
         URL url2 = dir2.toUri().toURL();
--- a/jdk/test/java/lang/module/ConfigurationTest.java	Tue Jul 04 18:49:16 2017 -0700
+++ b/jdk/test/java/lang/module/ConfigurationTest.java	Wed Jul 05 13:30:22 2017 +0100
@@ -42,6 +42,7 @@
 import java.lang.module.ResolvedModule;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
@@ -2117,7 +2118,7 @@
             target = null;
         }
         String name = descriptor.name();
-        Path dir = Files.createTempDirectory(name);
+        Path dir = Files.createTempDirectory(Paths.get(""), name);
         Path mi = dir.resolve("module-info.class");
         try (OutputStream out = Files.newOutputStream(mi)) {
             ModuleInfoWriter.write(descriptor, target, out);
--- a/jdk/test/java/lang/module/customfs/ModulesInCustomFileSystem.java	Tue Jul 04 18:49:16 2017 -0700
+++ b/jdk/test/java/lang/module/customfs/ModulesInCustomFileSystem.java	Wed Jul 05 13:30:22 2017 +0100
@@ -48,6 +48,7 @@
 
 @Test
 public class ModulesInCustomFileSystem {
+    private static final Path HERE = Paths.get("");
 
     /**
      * Test exploded modules in a JAR file system.
@@ -59,7 +60,7 @@
         assertEquals(mlib, m2.getParent());
 
         // create JAR file containing m1/** and m2/**
-        Path jar = Files.createTempDirectory("mlib").resolve("modules.jar");
+        Path jar = Files.createTempDirectory(HERE, "mlib").resolve("modules.jar");
         JarUtils.createJarFile(jar, mlib);
         testJarFileSystem(jar);
     }
@@ -70,12 +71,12 @@
     public void testModularJARsInJarFileSystem() throws Exception {
         Path m1 = findModuleDirectory("m1");
         Path m2 = findModuleDirectory("m2");
-        Path contents = Files.createTempDirectory("contents");
+        Path contents = Files.createTempDirectory(HERE, "contents");
         JarUtils.createJarFile(contents.resolve("m1.jar"), m1);
         JarUtils.createJarFile(contents.resolve("m2.jar"), m2);
 
         // create JAR file containing m1.jar and m2.jar
-        Path jar = Files.createTempDirectory("mlib").resolve("modules.jar");
+        Path jar = Files.createTempDirectory(HERE, "mlib").resolve("modules.jar");
         JarUtils.createJarFile(jar, contents);
         testJarFileSystem(jar);
     }
--- a/jdk/test/java/nio/channels/AsynchronousChannelGroup/SetupJar.java	Tue Jul 04 18:49:16 2017 -0700
+++ b/jdk/test/java/nio/channels/AsynchronousChannelGroup/SetupJar.java	Wed Jul 05 13:30:22 2017 +0100
@@ -21,14 +21,19 @@
  * questions.
  */
 
+import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.stream.Stream;
 
 public class SetupJar {
-
     public static void main(String args[]) throws Exception {
-        Path classes = Paths.get(System.getProperty("test.classes", ""));
-        JarUtils.createJarFile(Paths.get("privileged.jar"),
-                               classes.resolve("bootlib"));
+        String cp = System.getProperty("test.class.path");
+        Path bootlib = Stream.of(cp.split(File.pathSeparator))
+                .map(Paths::get)
+                .filter(e -> e.endsWith("bootlib"))  // file name
+                .findAny()
+                .orElseThrow(() -> new InternalError("bootlib not found"));
+        JarUtils.createJarFile(Paths.get("privileged.jar"), bootlib);
     }
 }
--- a/jdk/test/java/util/ServiceLoader/ModulesTest.java	Tue Jul 04 18:49:16 2017 -0700
+++ b/jdk/test/java/util/ServiceLoader/ModulesTest.java	Wed Jul 05 13:30:22 2017 +0100
@@ -33,6 +33,7 @@
  * @summary Basic test for ServiceLoader with a provider deployed as a module.
  */
 
+import java.io.File;
 import java.lang.module.Configuration;
 import java.lang.module.ModuleFinder;
 import java.nio.file.Files;
@@ -49,6 +50,7 @@
 import java.util.ServiceLoader.Provider;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import javax.script.ScriptEngineFactory;
 
 import org.testng.annotations.Test;
@@ -236,8 +238,10 @@
      */
     @Test
     public void testWithAutomaticModule() throws Exception {
+        Path here = Paths.get("");
+        Path jar = Files.createTempDirectory(here, "lib").resolve("pearscript.jar");
         Path classes = Paths.get(System.getProperty("test.classes"));
-        Path jar = Files.createTempDirectory("lib").resolve("pearscript.jar");
+
         JarUtils.createJarFile(jar, classes, "META-INF", "org");
 
         ModuleFinder finder = ModuleFinder.of(jar);
@@ -353,8 +357,7 @@
                 .isPresent());
 
         ClassLoader scl = ClassLoader.getSystemClassLoader();
-        Path dir = Paths.get(System.getProperty("test.classes", "."), "modules");
-        ModuleFinder finder = ModuleFinder.of(dir);
+        ModuleFinder finder = ModuleFinder.of(testModulePath());
 
         // layer1
         Configuration cf1 = cf0.resolveAndBind(finder, ModuleFinder.of(), Set.of());
@@ -451,11 +454,10 @@
 
     /**
      * Create a custom layer by resolving the given module names. The modules
-     * are located in the {@code ${test.classes}/modules} directory.
+     * are located on the test module path ({@code ${test.module.path}}).
      */
     private ModuleLayer createCustomLayer(String... modules) {
-        Path dir = Paths.get(System.getProperty("test.classes", "."), "modules");
-        ModuleFinder finder = ModuleFinder.of(dir);
+        ModuleFinder finder = ModuleFinder.of(testModulePath());
         Set<String> roots = new HashSet<>();
         Collections.addAll(roots, modules);
         ModuleLayer bootLayer = ModuleLayer.boot();
@@ -467,6 +469,13 @@
         return layer;
     }
 
+    private Path[] testModulePath() {
+        String mp = System.getProperty("test.module.path");
+        return Stream.of(mp.split(File.pathSeparator))
+                .map(Paths::get)
+                .toArray(Path[]::new);
+    }
+
     private <E> List<E> collectAll(ServiceLoader<E> loader) {
         List<E> list = new ArrayList<>();
         Iterator<E> iterator = loader.iterator();