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 ToolProviderTest1
  33  */
  34 
  35 import java.util.List;
  36 
  37 import toolbox.JavaTask;
  38 import toolbox.Task;
  39 import toolbox.ToolBox;
  40 
  41 // verify that running accessing ToolProvider by itself does not
  42 // trigger loading com.sun.tools.javac.*
  43 public class ToolProviderTest1 {
  44     public static void main(String... args) throws Exception {
  45         if (args.length > 0) {
  46             System.err.println(Class.forName(args[0], true, ClassLoader.getSystemClassLoader()));
  47             return;
  48         }
  49 
  50         new ToolProviderTest1().run();
  51     }
  52 
  53     void run() throws Exception {
  54         ToolBox tb = new ToolBox();
  55         String classpath = System.getProperty("java.class.path");
  56 
  57         List<String> lines = new JavaTask(tb)
  58                 .vmOptions("-verbose:class")
  59                 .classpath(classpath)
  60                 .className(getClass().getName())
  61                 .classArgs("javax.tools.ToolProvider")
  62                 .run()
  63                 .getOutputLines(Task.OutputKind.STDOUT);
  64 
  65         for (String line : lines) {
  66             System.err.println(line);
  67             if (line.contains("com.sun.tools.javac."))
  68                 error(">>> " + line);
  69         }
  70 
  71         if (errors > 0)
  72             throw new Exception(errors + " errors occurred");
  73     }
  74 
  75     void error(String msg) {
  76         System.err.println(msg);
  77         errors++;
  78     }
  79 
  80     int errors;
  81 }