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 ToolProviderTest2
33 */
34
35import javax.tools.ToolProvider;
36import java.util.List;
37
38import toolbox.JavaTask;
39import toolbox.Task;
40import toolbox.ToolBox;
41
42// control for ToolProviderTest1 -- verify that using ToolProvider to
43// access the compiler does trigger loading com.sun.tools.javac.*
44public class ToolProviderTest2 {
45    public static void main(String... args) throws Exception {
46        if (args.length > 0) {
47            System.err.println(ToolProvider.getSystemJavaCompiler());
48            return;
49        }
50
51        new ToolProviderTest2().run();
52    }
53
54    void run() throws Exception {
55        ToolBox tb = new ToolBox();
56        String classpath = System.getProperty("java.class.path");
57
58        List<String> lines = new JavaTask(tb)
59                .vmOptions("-verbose:class")
60                .classpath(classpath)
61                .className(getClass().getName())
62                .classArgs("javax.tools.ToolProvider")
63                .run()
64                .getOutputLines(Task.OutputKind.STDOUT);
65
66        boolean found = false;
67        for (String line : lines) {
68            System.err.println(line);
69            if (line.contains("com.sun.tools.javac."))
70                found = true;
71        }
72
73        if (!found)
74            error("expected class name not found");
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