--- a/langtools/test/tools/javac/api/ToolProvider/ToolProviderTest1.java Mon Dec 16 14:32:12 2013 +0000
+++ b/langtools/test/tools/javac/api/ToolProvider/ToolProviderTest1.java Mon Dec 16 15:07:13 2013 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, 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
@@ -25,9 +25,13 @@
* @test
* @bug 6604599
* @summary ToolProvider should be less compiler-specific
+ * @library /tools/javac/lib
+ * @build ToolBox
+ * @run main ToolProviderTest1
*/
-import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
// verify that running accessing ToolProvider by itself does not
// trigger loading com.sun.tools.javac.*
@@ -42,32 +46,28 @@
}
void run() throws Exception {
- File javaHome = new File(System.getProperty("java.home"));
- if (javaHome.getName().equals("jre"))
- javaHome = javaHome.getParentFile();
- File javaExe = new File(new File(javaHome, "bin"), "java");
String classpath = System.getProperty("java.class.path");
- String[] cmd = {
- javaExe.getPath(),
- "-verbose:class",
- "-classpath", classpath,
- ToolProviderTest1.class.getName(),
- "javax.tools.ToolProvider"
- };
+ List<String> output = new ArrayList<>();
+ ToolBox.AnyToolArgs javaParams =
+ new ToolBox.AnyToolArgs()
+ .appendArgs(ToolBox.javaBinary)
+ .appendArgs(ToolBox.testVMOpts)
+ .appendArgs(ToolBox.testJavaOpts)
+ .appendArgs("-verbose:class",
+ "-classpath", classpath,
+ ToolProviderTest1.class.getName(),
+ "javax.tools.ToolProvider")
+ .setErrOutput(output)
+ .setStdOutput(output);
- ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
- Process p = pb.start();
- BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String line;
- while ((line = r.readLine()) != null) {
+ ToolBox.executeCommand(javaParams);
+
+ for (String line : output) {
System.err.println(line);
if (line.contains("com.sun.tools.javac."))
error(">>> " + line);
}
- int rc = p.waitFor();
- if (rc != 0)
- error("Unexpected exit code: " + rc);
if (errors > 0)
throw new Exception(errors + " errors occurred");