8183505: Update langtools tests to allow for unique test classes directory
authorjjg
Wed, 05 Jul 2017 14:36:54 -0700
changeset 45861 a82ccda077c9
parent 45860 0952e2c6545a
child 45862 c6827bac317d
8183505: Update langtools tests to allow for unique test classes directory Reviewed-by: alanb
langtools/test/tools/javadoc/8147801/T8147801.java
langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestLoad.java
langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestScan.java
langtools/test/tools/jdeps/MultiReleaseJar.java
--- a/langtools/test/tools/javadoc/8147801/T8147801.java	Wed Jul 05 13:46:05 2017 -0700
+++ b/langtools/test/tools/javadoc/8147801/T8147801.java	Wed Jul 05 14:36:54 2017 -0700
@@ -31,6 +31,7 @@
  * @run main T8147801
  */
 
+import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -42,6 +43,7 @@
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
+import java.util.stream.Stream;
 
 import com.sun.javadoc.ClassDoc;
 import com.sun.javadoc.FieldDoc;
@@ -143,13 +145,18 @@
     }
 
     void initJar() throws IOException {
-        Path testClasses = Paths.get(System.getProperty("test.classes"));
+        String testClassPath = System.getProperty("test.class.path", "");
+        Path jarsrc = Stream.of(testClassPath.split(File.pathSeparator))
+                .map(Paths::get)
+                .filter(e -> e.endsWith("jarsrc"))
+                .findAny()
+                .orElseThrow(() -> new InternalError("jarsrc not found"));
         jarPath = Paths.get("lib.jar");
         try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(jarPath))) {
             String[] classNames = {"Lib1.class", "Lib2.class"};
             for (String cn : classNames) {
                 out.putNextEntry(new JarEntry("lib/" + cn));
-                Path libClass = testClasses.resolve("jarsrc").resolve("lib").resolve(cn);
+                Path libClass = jarsrc.resolve("lib").resolve(cn);
                 out.write(Files.readAllBytes(libClass));
             }
         }
--- a/langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestLoad.java	Wed Jul 05 13:46:05 2017 -0700
+++ b/langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestLoad.java	Wed Jul 05 14:36:54 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -37,6 +37,7 @@
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
@@ -48,6 +49,7 @@
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import com.sun.tools.jdeprscan.Main;
 
@@ -63,8 +65,11 @@
 
     @Test
     public void test1() throws IOException, UnsupportedEncodingException {
-        String testclasses = System.getProperty("test.classes");
-        String deprcases = testclasses + "/../../../cases";
+        String testClassPath = System.getProperty("test.class.path", "");
+        String deprcases = Stream.of(testClassPath.split(File.pathSeparator))
+                .filter(e -> e.endsWith("cases"))
+                .findAny()
+                .orElseThrow(() -> new InternalError("cases not found"));
         boolean rval;
 
         System.out.println("test.src = " + System.getProperty("test.src"));
--- a/langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestScan.java	Wed Jul 05 13:46:05 2017 -0700
+++ b/langtools/test/tools/jdeprscan/tests/jdk/jdeprscan/TestScan.java	Wed Jul 05 14:36:54 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -40,6 +40,7 @@
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
@@ -50,6 +51,7 @@
 import java.util.HashSet;
 import java.util.Set;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import org.testng.Assert;
 
 import org.testng.annotations.Test;
@@ -65,9 +67,16 @@
 
     @Test
     public void testScanAgainstReferenceFile() throws IOException {
-        String testclasses = System.getProperty("test.classes");
-        String deprcases = testclasses + "/../../../cases";
-        String deprusage = testclasses + "/../../../usage";
+        String[] testClassPath = System.getProperty("test.class.path", "")
+                .split(File.pathSeparator);
+        String deprcases = Stream.of(testClassPath)
+                .filter(e -> e.endsWith("cases"))
+                .findAny()
+                .orElseThrow(() -> new InternalError("cases not found"));
+        String deprusage = Stream.of(testClassPath)
+                .filter(e -> e.endsWith("usage"))
+                .findAny()
+                .orElseThrow(() -> new InternalError("usage not found"));
 
         Set<String> expected = loadExpected();
         System.out.println("expected = " + expected);
--- a/langtools/test/tools/jdeps/MultiReleaseJar.java	Wed Jul 05 13:46:05 2017 -0700
+++ b/langtools/test/tools/jdeps/MultiReleaseJar.java	Wed Jul 05 14:36:54 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 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
@@ -36,11 +36,13 @@
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
 
 public class MultiReleaseJar {
     Path mrjar;
@@ -50,7 +52,12 @@
 
     @BeforeClass
     public void initialize() throws Exception {
-        mrjar = Paths.get(System.getProperty("test.classes", "."), "mrjar");
+        String testClassPath = System.getProperty("test.class.path", "");
+        mrjar = Stream.of(testClassPath.split(File.pathSeparator))
+                .map(Paths::get)
+                .filter(e -> e.endsWith("mrjar"))
+                .findAny()
+                .orElseThrow(() -> new InternalError("mrjar not found"));
         testJdk = System.getProperty("test.jdk");
         fileSep = System.getProperty("file.separator");
         cmdPath = Paths.get(testJdk, "bin");