1/*
2 * Copyright (c) 2010, 2016, 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 * @library /tools/lib
29 * @modules jdk.compiler/com.sun.tools.javac.api
30 *          jdk.compiler/com.sun.tools.javac.main
31 * @build toolbox.ToolBox toolbox.JavaTask
32 * @run main HelloWorldTest
33 */
34
35import java.util.Arrays;
36
37import toolbox.JavaTask;
38import toolbox.Task;
39import toolbox.ToolBox;
40
41// verify that running a simple program, such as this one, does not trigger
42// the loading of ToolProvider or any com.sun.tools.javac class
43public class HelloWorldTest {
44    public static void main(String... args) throws Exception {
45        if (args.length > 0) {
46            System.err.println(Arrays.toString(args));
47            return;
48        }
49
50        new HelloWorldTest().run();
51    }
52
53    void run() throws Exception {
54        ToolBox tb = new ToolBox();
55
56        String classpath = System.getProperty("java.class.path");
57
58        Task.Result tr = new JavaTask(tb)
59                .vmOptions("-verbose:class")
60                .classpath(classpath)
61                .className(HelloWorldTest.class.getName())
62                .classArgs("Hello", "World")
63                .run();
64
65        if (tr.getOutput(Task.OutputKind.STDOUT).contains("java.lang.Object")) {
66            for (String line : tr.getOutputLines(Task.OutputKind.STDOUT)) {
67                System.err.println(line);
68                if (line.contains("javax.tools.ToolProvider") || line.contains("com.sun.tools.javac."))
69                    error(">>> " + line);
70            }
71        } else {
72            tr.writeAll();
73            error("verbose output not as expected");
74        }
75
76        if (errors > 0)
77            throw new Exception(errors + " errors occurred");
78    }
79
80    void error(String msg) {
81        System.err.println(msg);
82        errors++;
83    }
84
85    int errors;
86}
87