ClassPathTest.java revision 3294:9adfb22ff08f
1336815Sdim/* 2336815Sdim * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3353358Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4353358Sdim * 5353358Sdim * This code is free software; you can redistribute it and/or modify it 6336815Sdim * under the terms of the GNU General Public License version 2 only, as 7336815Sdim * published by the Free Software Foundation. 8336815Sdim * 9336815Sdim * This code is distributed in the hope that it will be useful, but WITHOUT 10336815Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11336815Sdim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12336815Sdim * version 2 for more details (a copy is included in the LICENSE file that 13336815Sdim * accompanied this code). 14336815Sdim * 15336815Sdim * You should have received a copy of the GNU General Public License version 16336815Sdim * 2 along with this work; if not, write to the Free Software Foundation, 17336815Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18336815Sdim * 19336815Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20336815Sdim * or visit www.oracle.com if you need additional information or have any 21336815Sdim * questions. 22336815Sdim */ 23336815Sdim 24336815Sdim/* 25336815Sdim * @test 26336815Sdim * @bug 4241229 4785453 27336815Sdim * @summary Test -classpath option and classpath defaults. 28336815Sdim * @library /tools/lib 29336815Sdim * @modules jdk.compiler/com.sun.tools.javac.api 30336815Sdim * jdk.compiler/com.sun.tools.javac.file 31336815Sdim * jdk.compiler/com.sun.tools.javac.main 32336815Sdim * jdk.jdeps/com.sun.tools.javap 33336815Sdim * @build ToolBox 34336815Sdim * @run main ClassPathTest 35336815Sdim */ 36336815Sdim 37336815Sdimimport java.nio.file.Paths; 38336815Sdim 39336815Sdim// Original test: test/tools/javac/ClassPathTest/ClassPathTest.sh 40336815Sdimpublic class ClassPathTest { 41336815Sdim 42336815Sdim private static final String ClassPathTest1Src = 43336815Sdim "import pkg.*;\n" + 44336815Sdim "public class ClassPathTest1 {\n" + 45336815Sdim " ClassPathTestAux1 x;\n" + 46336815Sdim "}"; 47336815Sdim 48336815Sdim private static final String ClassPathTest2Src = 49336815Sdim "import pkg.*;\n" + 50336815Sdim "public class ClassPathTest2 {\n" + 51336815Sdim " ClassPathTestAux2 x;\n" + 52336815Sdim "}"; 53336815Sdim 54336815Sdim private static final String ClassPathTest3Src = 55336815Sdim "import pkg.*;\n" + 56336815Sdim "public class ClassPathTest3 {\n" + 57336815Sdim " ClassPathTestAux3 x;\n" + 58336815Sdim "}"; 59336815Sdim 60336815Sdim private static final String fooPkgClassPathTestAux1Src = 61336815Sdim "package pkg;\n" + 62336815Sdim "public class ClassPathTestAux1 {}"; 63336815Sdim 64336815Sdim private static final String barPkgClassPathTestAux2Src = 65336815Sdim "package pkg;\n" + 66336815Sdim "public class ClassPathTestAux2 {}"; 67336815Sdim 68336815Sdim private static final String pkgClassPathTestAux3Src = 69336815Sdim "package pkg;\n" + 70336815Sdim "public class ClassPathTestAux3 {}"; 71336815Sdim 72336815Sdim public static void main(String[] args) throws Exception { 73336815Sdim new ClassPathTest().test(); 74336815Sdim } 75336815Sdim 76336815Sdim ToolBox tb = new ToolBox(); 77336815Sdim 78336815Sdim public void test() throws Exception { 79336815Sdim createOutputDirAndSourceFiles(); 80336815Sdim checkCompileCommands(); 81336815Sdim } 82360784Sdim 83336815Sdim void createOutputDirAndSourceFiles() throws Exception { 84336815Sdim //dirs and files creation 85336815Sdim tb.writeJavaFiles(Paths.get("."), 86360784Sdim ClassPathTest1Src, 87336815Sdim ClassPathTest2Src, 88336815Sdim ClassPathTest3Src); 89336815Sdim tb.writeJavaFiles(Paths.get("foo"), 90336815Sdim fooPkgClassPathTestAux1Src); 91336815Sdim tb.writeJavaFiles(Paths.get("bar"), 92336815Sdim barPkgClassPathTestAux2Src); 93336815Sdim tb.writeJavaFiles(Paths.get("."), 94336815Sdim pkgClassPathTestAux3Src); 95336815Sdim } 96336815Sdim 97336815Sdim void checkCompileCommands() throws Exception { 98336815Sdim// Without the -cp . parameter the command will fail seems like when called 99336815Sdim// from the command line, the current dir is added to the classpath 100336815Sdim// automatically but this is not happening when called using ProcessBuilder 101336815Sdim 102336815Sdim// testJavac success ClassPathTest3.java 103336815Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 104336815Sdim .classpath(".") 105336815Sdim .files("ClassPathTest3.java") 106336815Sdim .run(); 107336815Sdim 108336815Sdim// testJavac failure ClassPathTest1.java 109336815Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 110336815Sdim .classpath(".") 111336815Sdim .files("ClassPathTest1.java") 112336815Sdim .run(ToolBox.Expect.FAIL); 113336815Sdim 114336815Sdim// testJavac success ClassPathTest2.java 115336815Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 116336815Sdim .envVar("CLASSPATH", "bar") 117336815Sdim .files("ClassPathTest2.java") 118336815Sdim .run(); 119336815Sdim 120336815Sdim// testJavac failure ClassPathTest1.java 121336815Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 122336815Sdim .envVar("CLASSPATH", "bar") 123336815Sdim .files("ClassPathTest1.java") 124336815Sdim .run(ToolBox.Expect.FAIL); 125336815Sdim 126336815Sdim// testJavac failure ClassPathTest3.java 127360784Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 128336815Sdim .envVar("CLASSPATH", "bar") 129336815Sdim .files("ClassPathTest3.java") 130336815Sdim .run(ToolBox.Expect.FAIL); 131336815Sdim 132336815Sdim// testJavac success -classpath foo ClassPathTest1.java 133336815Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 134336815Sdim .envVar("CLASSPATH", "bar") 135336815Sdim .classpath("foo") 136336815Sdim .files("ClassPathTest1.java") 137336815Sdim .run(); 138336815Sdim 139336815Sdim// testJavac failure -classpath foo ClassPathTest2.java 140336815Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 141336815Sdim .envVar("CLASSPATH", "bar") 142336815Sdim .classpath("foo") 143336815Sdim .files("ClassPathTest2.java") 144336815Sdim .run(ToolBox.Expect.FAIL); 145336815Sdim 146336815Sdim// testJavac failure -classpath foo ClassPathTest3.java 147336815Sdim tb.new JavacTask(ToolBox.Mode.EXEC) 148336815Sdim .envVar("CLASSPATH", "bar") 149336815Sdim .classpath("foo") 150336815Sdim .files("ClassPathTest3.java") 151336815Sdim .run(ToolBox.Expect.FAIL); 152336815Sdim } 153336815Sdim 154344779Sdim} 155336815Sdim