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