hotspot/test/compiler/profiling/spectrapredefineclass_classloaders/Launcher.java
changeset 40651 998e35976abf
parent 40059 c2304140ed64
child 40652 9e6d111b4089
--- a/hotspot/test/compiler/profiling/spectrapredefineclass_classloaders/Launcher.java	Wed Aug 17 22:34:33 2016 +0200
+++ b/hotspot/test/compiler/profiling/spectrapredefineclass_classloaders/Launcher.java	Thu Aug 18 11:26:35 2016 +0300
@@ -39,26 +39,36 @@
  *                   -XX:ReservedCodeCacheSize=3M
  *                   compiler.profiling.spectrapredefineclass_classloaders.Agent
  */
+
 package compiler.profiling.spectrapredefineclass_classloaders;
 
-import jdk.test.lib.JDKToolFinder;
+import jdk.test.lib.JDKToolLauncher;
+import jdk.test.lib.OutputAnalyzer;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.PrintWriter;
 
 public class Launcher {
-    public static void main(String[] args) throws Exception {
-
-        PrintWriter pw = new PrintWriter("MANIFEST.MF");
+    private static final String MANIFEST = "MANIFEST.MF";
+    public static void main(String[] args) throws Exception  {
+        try (PrintWriter pw = new PrintWriter(MANIFEST)) {
+            pw.println("Agent-Class: " + Agent.class.getName());
+            pw.println("Can-Retransform-Classes: true");
+        }
 
-        pw.println("Agent-Class: " + Launcher.class.getPackage().getName() + ".Agent");
-        pw.println("Can-Retransform-Classes: true");
-        pw.close();
+        JDKToolLauncher jar = JDKToolLauncher.create("jar")
+                .addToolArg("cmf")
+                .addToolArg(MANIFEST)
+                .addToolArg(Agent.AGENT_JAR)
+                .addToolArg(Agent.class.getName().replace('.', File.separatorChar) + ".class");
 
-        ProcessBuilder pb = new ProcessBuilder();
-        pb.command(new String[]{JDKToolFinder.getJDKTool("jar"), "cmf", "MANIFEST.MF",
-                System.getProperty("test.classes", ".") + "/agent.jar",
-                "compiler/profiling/spectrapredefineclass/Agent.class".replace('/', File.separatorChar)});
-        pb.start().waitFor();
+        ProcessBuilder pb = new ProcessBuilder(jar.getCommand());
+        try {
+            OutputAnalyzer output = new OutputAnalyzer(pb.start());
+            output.shouldHaveExitValue(0);
+        } catch (IOException ex) {
+            throw new Error("TESTBUG: jar failed.", ex);
+        }
     }
 }