test/tools/javac/api/ToolProvider/ToolProviderTest1.java

changeset 659
cfd047f3cf60
parent 0
959103a6100f
equal deleted inserted replaced
658:ecff24121064 659:cfd047f3cf60
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
32 // verify that running accessing ToolProvider by itself does not
33 // trigger loading com.sun.tools.javac.*
34 public class ToolProviderTest1 {
35 public static void main(String... args) throws Exception {
36 if (args.length > 0) {
37 System.err.println(Class.forName(args[0], true, null));
38 return;
39 }
40
41 new ToolProviderTest1().run();
42 }
43
44 void run() throws Exception {
45 File javaHome = new File(System.getProperty("java.home"));
46 if (javaHome.getName().equals("jre"))
47 javaHome = javaHome.getParentFile();
48 File javaExe = new File(new File(javaHome, "bin"), "java");
49 String classpath = System.getProperty("java.class.path");
50
51 String[] cmd = {
52 javaExe.getPath(),
53 "-verbose:class",
54 "-classpath", classpath,
55 ToolProviderTest1.class.getName(),
56 "javax.tools.ToolProvider"
57 };
58
59 ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
60 Process p = pb.start();
61 BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
62 String line;
63 while ((line = r.readLine()) != null) {
64 System.err.println(line);
65 if (line.contains("com.sun.tools.javac."))
66 error(">>> " + line);
67 }
68 int rc = p.waitFor();
69 if (rc != 0)
70 error("Unexpected exit code: " + rc);
71
72 if (errors > 0)
73 throw new Exception(errors + " errors occurred");
74 }
75
76 void error(String msg) {
77 System.err.println(msg);
78 errors++;
79 }
80
81 int errors;
82 }

mercurial