6577
|
1 |
/*
|
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 6604599
|
|
27 |
* @summary ToolProvider should be less compiler-specific
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.io.*;
|
|
31 |
import java.util.*;
|
|
32 |
|
|
33 |
// verify that running a simple program, such as this one, does not trigger
|
|
34 |
// the loading of ToolProvider or any com.sun.tools.javac class
|
|
35 |
public class HelloWorldTest {
|
|
36 |
public static void main(String... args) throws Exception {
|
|
37 |
if (args.length > 0) {
|
|
38 |
System.err.println(Arrays.asList(args));
|
|
39 |
return;
|
|
40 |
}
|
|
41 |
|
|
42 |
new HelloWorldTest().run();
|
|
43 |
}
|
|
44 |
|
|
45 |
void run() throws Exception {
|
|
46 |
File javaHome = new File(System.getProperty("java.home"));
|
|
47 |
if (javaHome.getName().equals("jre"))
|
|
48 |
javaHome = javaHome.getParentFile();
|
|
49 |
File javaExe = new File(new File(javaHome, "bin"), "java");
|
|
50 |
String classpath = System.getProperty("java.class.path");
|
|
51 |
|
|
52 |
String[] cmd = {
|
|
53 |
javaExe.getPath(),
|
|
54 |
"-verbose:class",
|
|
55 |
"-classpath", classpath,
|
|
56 |
HelloWorldTest.class.getName(),
|
|
57 |
"Hello", "World"
|
|
58 |
};
|
|
59 |
|
|
60 |
ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
|
|
61 |
Process p = pb.start();
|
|
62 |
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
63 |
String line;
|
|
64 |
while ((line = r.readLine()) != null) {
|
|
65 |
System.err.println(line);
|
|
66 |
if (line.contains("javax.tools.ToolProvider") || line.contains("com.sun.tools.javac."))
|
|
67 |
error(">>> " + line);
|
|
68 |
}
|
|
69 |
int rc = p.waitFor();
|
|
70 |
if (rc != 0)
|
|
71 |
error("Unexpected exit code: " + rc);
|
|
72 |
|
|
73 |
if (errors > 0)
|
|
74 |
throw new Exception(errors + " errors occurred");
|
|
75 |
}
|
|
76 |
|
|
77 |
void error(String msg) {
|
|
78 |
System.err.println(msg);
|
|
79 |
errors++;
|
|
80 |
}
|
|
81 |
|
|
82 |
int errors;
|
|
83 |
}
|