8028708: TEST_BUG, Tests should pass through VM options, langtools tests
Reviewed-by: jjg, vromero
Contributed-by: andrey.x.nazarov@oracle.com
--- a/langtools/test/tools/javac/api/ToolProvider/HelloWorldTest.java Mon Dec 16 14:32:12 2013 +0000
+++ b/langtools/test/tools/javac/api/ToolProvider/HelloWorldTest.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,10 +25,14 @@
* @test
* @bug 6604599
* @summary ToolProvider should be less compiler-specific
+ * @library /tools/javac/lib
+ * @build ToolBox
+ * @run main HelloWorldTest
*/
-import java.io.*;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
// verify that running a simple program, such as this one, does not trigger
// the loading of ToolProvider or any com.sun.tools.javac class
@@ -43,32 +47,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,
- HelloWorldTest.class.getName(),
- "Hello", "World"
- };
+ 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,
+ HelloWorldTest.class.getName(),
+ "Hello", "World")
+ .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("javax.tools.ToolProvider") || 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");
--- 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");
--- a/langtools/test/tools/javac/api/ToolProvider/ToolProviderTest2.java Mon Dec 16 14:32:12 2013 +0000
+++ b/langtools/test/tools/javac/api/ToolProvider/ToolProviderTest2.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,10 +25,14 @@
* @test
* @bug 6604599
* @summary ToolProvider should be less compiler-specific
+ * @library /tools/javac/lib
+ * @build ToolBox
+ * @run main ToolProviderTest2
*/
-import java.io.*;
-import javax.tools.*;
+import javax.tools.ToolProvider;
+import java.util.ArrayList;
+import java.util.List;
// control for ToolProviderTest1 -- verify that using ToolProvider to
// access the compiler does trigger loading com.sun.tools.javac.*
@@ -43,36 +47,32 @@
}
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,
- ToolProviderTest2.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,
+ ToolProviderTest2.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;
+ ToolBox.executeCommand(javaParams);
+
boolean found = false;
- while ((line = r.readLine()) != null) {
+ for (String line : output) {
System.err.println(line);
if (line.contains("com.sun.tools.javac."))
found = true;
}
- int rc = p.waitFor();
- if (rc != 0)
- error("Unexpected exit code: " + rc);
if (!found)
- System.err.println("expected class name not found");
+ error("expected class name not found");
if (errors > 0)
throw new Exception(errors + " errors occurred");
--- a/langtools/test/tools/javac/lib/ToolBox.java Mon Dec 16 14:32:12 2013 +0000
+++ b/langtools/test/tools/javac/lib/ToolBox.java Mon Dec 16 15:07:13 2013 +0000
@@ -69,27 +69,17 @@
public static final Path javaBinary = Paths.get(jdkUnderTest, "bin", "java");
public static final Path javacBinary = Paths.get(jdkUnderTest, "bin", "javac");
- public static final List<String> testToolVMOpts;
- public static final List<String> testVMOpts;
+ public static final List<String> testVMOpts = readOptions("test.vm.opts");
+ public static final List<String> testToolVMOpts = readOptions("test.tool.vm.opts");
+ public static final List<String> testJavaOpts = readOptions("test.java.opts");
private static final Charset defaultCharset = Charset.defaultCharset();
static final JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
- static {
- String sysProp = System.getProperty("test.tool.vm.opts");
- if (sysProp != null && sysProp.length() > 0) {
- testToolVMOpts = Arrays.asList(sysProp.split("\\s+"));
- } else {
- testToolVMOpts = Collections.<String>emptyList();
- }
-
- sysProp = System.getProperty("test.vm.opts");
- if (sysProp != null && sysProp.length() > 0) {
- testVMOpts = Arrays.asList(sysProp.split("\\s+"));
- } else {
- testVMOpts = Collections.<String>emptyList();
- }
+ private static List<String> readOptions(String property) {
+ String options = System.getProperty(property, "");
+ return options.length() > 0 ? Arrays.asList(options.split("\\s+")) : Collections.<String>emptyList();
}
/**