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 javax.tools.*;
|
|
32 |
|
|
33 |
// control for ToolProviderTest1 -- verify that using ToolProvider to
|
|
34 |
// access the compiler does trigger loading com.sun.tools.javac.*
|
|
35 |
public class ToolProviderTest2 {
|
|
36 |
public static void main(String... args) throws Exception {
|
|
37 |
if (args.length > 0) {
|
|
38 |
System.err.println(ToolProvider.getSystemJavaCompiler());
|
|
39 |
return;
|
|
40 |
}
|
|
41 |
|
|
42 |
new ToolProviderTest2().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 |
ToolProviderTest2.class.getName(),
|
|
57 |
"javax.tools.ToolProvider"
|
|
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 |
boolean found = false;
|
|
65 |
while ((line = r.readLine()) != null) {
|
|
66 |
System.err.println(line);
|
|
67 |
if (line.contains("com.sun.tools.javac."))
|
|
68 |
found = true;
|
|
69 |
}
|
|
70 |
int rc = p.waitFor();
|
|
71 |
if (rc != 0)
|
|
72 |
error("Unexpected exit code: " + rc);
|
|
73 |
|
|
74 |
if (!found)
|
|
75 |
System.err.println("expected class name not found");
|
|
76 |
|
|
77 |
if (errors > 0)
|
|
78 |
throw new Exception(errors + " errors occurred");
|
|
79 |
}
|
|
80 |
|
|
81 |
void error(String msg) {
|
|
82 |
System.err.println(msg);
|
|
83 |
errors++;
|
|
84 |
}
|
|
85 |
|
|
86 |
int errors;
|
|
87 |
}
|