changeset 56529:d22206f24d59

8212807: tools/jar/multiRelease/Basic.java times out Reviewed-by: bchristi
author lancea
date Sun, 02 Jun 2019 17:13:31 -0400
parents aa5eeb1a9871
children 0dab93cb3b0c 5f9ef936707c
files test/jdk/tools/jar/multiRelease/Basic.java test/jdk/tools/jar/multiRelease/MRTestBase.java test/lib/jdk/test/lib/process/OutputAnalyzer.java
diffstat 3 files changed, 80 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/tools/jar/multiRelease/Basic.java	Sun Jun 02 10:08:39 2019 +0200
+++ b/test/jdk/tools/jar/multiRelease/Basic.java	Sun Jun 02 17:13:31 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, 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
@@ -23,7 +23,7 @@
 
 /*
  * @test
- # @bug 8186087 8196748
+ # @bug 8186087 8196748 8212807
  * @library /test/lib
  * @modules java.base/jdk.internal.misc
  *          jdk.compiler
@@ -39,17 +39,20 @@
  * @run testng Basic
  */
 
-import static org.testng.Assert.*;
-
 import jdk.test.lib.util.FileUtils;
 import org.testng.annotations.*;
 
 import java.io.File;
-import java.nio.file.*;
-import java.util.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Map;
 import java.util.jar.JarFile;
 import java.util.zip.ZipFile;
 
+import static org.testng.Assert.*;
+
 public class Basic extends MRTestBase {
 
     @Test
@@ -60,7 +63,7 @@
         compile("test01");  //use same data as test01
 
         Path classes = Paths.get("classes");
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".")
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
         checkMultiRelease(jarfile, false);
@@ -87,7 +90,7 @@
         compile("test01");
 
         Path classes = Paths.get("classes");
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".",
                 "--release", "10", "-C", classes.resolve("v10").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
@@ -124,7 +127,7 @@
 
         // valid
         for (String release : List.of("10000", "09", "00010", "10")) {
-            jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+            jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                     "--release", release, "-C", classes.resolve("v10").toString(), ".")
                     .shouldHaveExitValue(SUCCESS)
                     .shouldBeEmptyIgnoreVMWarnings();
@@ -132,7 +135,7 @@
         // invalid
         for (String release : List.of("9.0", "8", "v9",
                 "9v", "0", "-10")) {
-            jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+            jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                     "--release", release, "-C", classes.resolve("v10").toString(), ".")
                     .shouldNotHaveExitValue(SUCCESS)
                     .shouldContain("release " + release + " not valid");
@@ -149,12 +152,12 @@
         compile("test01");  //use same data as test01
 
         Path classes = Paths.get("classes");
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".")
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
         checkMultiRelease(jarfile, false);
 
-        jar("uf", jarfile,
+        jarTool("uf", jarfile,
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
@@ -185,7 +188,7 @@
         compile("test01");  //use same data as test01
 
         Path classes = Paths.get("classes");
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
@@ -206,7 +209,7 @@
 
         // write the v9 version/Version.class entry in base and the v10
         // version/Version.class entry in versions/9 section
-        jar("uf", jarfile, "-C", classes.resolve("v9").toString(), "version",
+        jarTool("uf", jarfile, "-C", classes.resolve("v9").toString(), "version",
                 "--release", "9", "-C", classes.resolve("v10").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
@@ -246,7 +249,7 @@
         Path source = Paths.get(src, "data", "test04", "v9", "version");
         javac(classes.resolve("v9"), source.resolve("Version.java"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldNotHaveExitValue(SUCCESS)
                 .shouldContain("different api from earlier");
@@ -268,7 +271,7 @@
         Path source = Paths.get(src, "data", "test05", "v9", "version");
         javac(classes.resolve("v9"), source.resolve("Extra.java"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldNotHaveExitValue(SUCCESS)
                 .shouldContain("contains a new public class");
@@ -290,7 +293,7 @@
         Path source = Paths.get(src, "data", "test06", "v9", "version");
         javac(classes.resolve("v9"), source.resolve("Extra.java"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
@@ -312,7 +315,7 @@
         Path source = Paths.get(src, "data", "test01", "base", "version");
         javac(classes.resolve("v9"), source.resolve("Version.java"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldHaveExitValue(SUCCESS)
                 .shouldContain("contains a class that")
@@ -332,11 +335,11 @@
 
         Path classes = Paths.get("classes");
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldHaveExitValue(SUCCESS)
                 .shouldBeEmptyIgnoreVMWarnings();
-        jar("uf", jarfile,
+        jarTool("uf", jarfile,
                 "--release", "10", "-C", classes.resolve("v9").toString(), ".")
                 .shouldHaveExitValue(SUCCESS)
                 .shouldContain("contains a class that")
@@ -359,7 +362,7 @@
 
         Files.copy(base.resolve("Main.class"), base.resolve("Foo.class"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldNotHaveExitValue(SUCCESS)
                 .shouldContain("names do not match");
@@ -385,7 +388,7 @@
         source = Paths.get(src, "data", "test10", "v9", "version");
         javac(classes.resolve("v9"), source.resolve("Nested.java"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
@@ -413,7 +416,7 @@
         source = Paths.get(src, "data", "test10", "v9", "version");
         javac(classes.resolve("v9"), source.resolve("Nested.java"));
 
-        List<String> output = jar("cf", jarfile,
+        List<String> output = jarTool("cf", jarfile,
                 "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldNotHaveExitValue(SUCCESS)
@@ -466,7 +469,7 @@
         // remove the top level class, thus isolating the nested class
         Files.delete(classes.resolve("v9").resolve("version").resolve("Nested.class"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "9", "-C", classes.resolve("v9").toString(), ".")
                 .shouldNotHaveExitValue(SUCCESS)
                 .shouldContain("an isolated nested class");
@@ -492,7 +495,7 @@
         source = Paths.get(src, "data", "test13", "v10", "version");
         javac(classes.resolve("v10"), source.resolve("Nested.java"));
 
-        jar("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
+        jarTool("cf", jarfile, "-C", classes.resolve("base").toString(), ".",
                 "--release", "10", "-C", classes.resolve("v10").toString(), ".")
                 .shouldHaveExitValue(SUCCESS);
 
@@ -512,7 +515,7 @@
         // create
         Files.write(manifest, "Class-Path: MyUtils.jar\n".getBytes());
 
-        jar("cfm", jarfile, manifest.toString(),
+        jarTool("cfm", jarfile, manifest.toString(),
                 "-C", classes.resolve("base").toString(), ".",
                 "--release", "10", "-C", classes.resolve("v10").toString(), ".")
                 .shouldHaveExitValue(SUCCESS)
--- a/test/jdk/tools/jar/multiRelease/MRTestBase.java	Sun Jun 02 10:08:39 2019 +0200
+++ b/test/jdk/tools/jar/multiRelease/MRTestBase.java	Sun Jun 02 17:13:31 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, 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
@@ -35,6 +35,7 @@
 import java.util.Map;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
+import java.util.spi.ToolProvider;
 import java.util.stream.Stream;
 import java.util.zip.ZipFile;
 
@@ -47,6 +48,16 @@
     protected final String src = System.getProperty("test.src", ".");
     protected final String usr = System.getProperty("user.dir", ".");
 
+    private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
+            .orElseThrow(()
+                    -> new RuntimeException("jar tool not found")
+            );
+
+    private static final ToolProvider JAVAC_TOOL = ToolProvider.findFirst("javac")
+            .orElseThrow(()
+                    -> new RuntimeException("javac tool not found")
+            );
+
     protected void compile(String test) throws Throwable {
         Path classes = Paths.get(usr, "classes", "base");
         Files.createDirectories(classes);
@@ -91,10 +102,8 @@
     }
 
     void javac(Path dest, Path... sourceFiles) throws Throwable {
-        String javac = JDKToolFinder.getJDKTool("javac");
 
         List<String> commands = new ArrayList<>();
-        commands.add(javac);
         String opts = System.getProperty("test.compiler.opts");
         if (!opts.isEmpty()) {
             commands.addAll(Arrays.asList(opts.split(" +")));
@@ -106,8 +115,14 @@
                 .map(Object::toString)
                 .forEach(x -> commands.add(x));
 
-        ProcessTools.executeCommand(new ProcessBuilder(commands))
-                .shouldHaveExitValue(SUCCESS);
+        StringWriter sw = new StringWriter();
+        try (PrintWriter pw = new PrintWriter(sw)) {
+            int rc = JAVAC_TOOL.run(pw, pw, commands.toArray(new String[0]));
+            if(rc != 0) {
+                throw new RuntimeException(sw.toString());
+            }
+        }
+
     }
 
     OutputAnalyzer jarWithStdin(File stdinSource,
@@ -127,4 +142,23 @@
     OutputAnalyzer jar(String... args) throws Throwable {
         return jarWithStdin(null, args);
     }
+
+    OutputAnalyzer jarTool(String... args) {
+        List<String> commands = new ArrayList<>();
+        commands.addAll(Utils.getForwardVmOptions());
+        Stream.of(args).forEach(x -> commands.add(x));
+        return run(JAR_TOOL, args);
+    }
+
+    OutputAnalyzer run(ToolProvider tp, String[] commands) {
+        int rc = 0;
+        StringWriter sw = new StringWriter();
+        StringWriter esw = new StringWriter();
+
+        try (PrintWriter pw = new PrintWriter(sw);
+             PrintWriter epw = new PrintWriter(esw)) {
+            rc = tp.run(pw, epw, commands);
+        }
+        return new OutputAnalyzer(sw.toString(), esw.toString(), rc);
+    }
 }
\ No newline at end of file
--- a/test/lib/jdk/test/lib/process/OutputAnalyzer.java	Sun Jun 02 10:08:39 2019 +0200
+++ b/test/lib/jdk/test/lib/process/OutputAnalyzer.java	Sun Jun 02 17:13:31 2019 -0400
@@ -78,6 +78,18 @@
     }
 
     /**
+     * Create an OutputAnalyzer, a utility class for verifying output
+     *
+     * @param stdout stdout buffer to analyze
+     * @param stderr stderr buffer to analyze
+     * @param stderr exitValue result to analyze
+     */
+    public OutputAnalyzer(String stdout, String stderr, int exitValue)
+    {
+        buffer = OutputBuffer.of(stdout, stderr, exitValue);
+    }
+
+    /**
      * Verify that the stdout contents of output buffer is empty
      *
      * @throws RuntimeException