Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
vromero@1591 | 1 | /* |
vromero@1591 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
vromero@1591 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
vromero@1591 | 4 | * |
vromero@1591 | 5 | * This code is free software; you can redistribute it and/or modify it |
vromero@1591 | 6 | * under the terms of the GNU General Public License version 2 only, as |
vromero@1591 | 7 | * published by the Free Software Foundation. |
vromero@1591 | 8 | * |
vromero@1591 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
vromero@1591 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
vromero@1591 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
vromero@1591 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
vromero@1591 | 13 | * accompanied this code). |
vromero@1591 | 14 | * |
vromero@1591 | 15 | * You should have received a copy of the GNU General Public License version |
vromero@1591 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
vromero@1591 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
vromero@1591 | 18 | * |
vromero@1591 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
vromero@1591 | 20 | * or visit www.oracle.com if you need additional information or have any |
vromero@1591 | 21 | * questions. |
vromero@1591 | 22 | */ |
vromero@1591 | 23 | |
vromero@1591 | 24 | /* |
vromero@1591 | 25 | * @test |
vromero@1591 | 26 | * @bug 4241229 4785453 |
vromero@1591 | 27 | * @summary Test -classpath option and classpath defaults. |
vromero@1591 | 28 | * @library /tools/javac/lib |
vromero@1591 | 29 | * @build ToolBox |
vromero@1591 | 30 | * @run main ClassPathTest |
vromero@1591 | 31 | */ |
vromero@1591 | 32 | |
vromero@1591 | 33 | import java.nio.file.Paths; |
vromero@1637 | 34 | import java.util.ArrayList; |
vromero@1637 | 35 | import java.util.Arrays; |
vromero@1637 | 36 | import java.util.List; |
vromero@1591 | 37 | import java.util.Map; |
vromero@1591 | 38 | import java.util.TreeMap; |
vromero@1591 | 39 | |
vromero@1591 | 40 | //original test: test/tools/javac/ClassPathTest/ClassPathTest.sh |
vromero@1591 | 41 | public class ClassPathTest { |
vromero@1591 | 42 | |
vromero@1591 | 43 | private static final String ClassPathTest1Src = |
vromero@1591 | 44 | "import pkg.*;\n" + |
vromero@1591 | 45 | "public class ClassPathTest1 {\n" + |
vromero@1591 | 46 | " ClassPathTestAux1 x;\n" + |
vromero@1591 | 47 | "}"; |
vromero@1591 | 48 | |
vromero@1591 | 49 | private static final String ClassPathTest2Src = |
vromero@1591 | 50 | "import pkg.*;\n" + |
vromero@1591 | 51 | "public class ClassPathTest2 {\n" + |
vromero@1591 | 52 | " ClassPathTestAux2 x;\n" + |
vromero@1591 | 53 | "}"; |
vromero@1591 | 54 | |
vromero@1591 | 55 | private static final String ClassPathTest3Src = |
vromero@1591 | 56 | "import pkg.*;\n" + |
vromero@1591 | 57 | "public class ClassPathTest3 {\n" + |
vromero@1591 | 58 | " ClassPathTestAux3 x;\n" + |
vromero@1591 | 59 | "}"; |
vromero@1591 | 60 | |
vromero@1591 | 61 | private static final String fooPkgClassPathTestAux1Src = |
vromero@1591 | 62 | "package pkg;\n" + |
vromero@1591 | 63 | "public class ClassPathTestAux1 {}"; |
vromero@1591 | 64 | |
vromero@1591 | 65 | private static final String barPkgClassPathTestAux2Src = |
vromero@1591 | 66 | "package pkg;\n" + |
vromero@1591 | 67 | "public class ClassPathTestAux2 {}"; |
vromero@1591 | 68 | |
vromero@1591 | 69 | private static final String pkgClassPathTestAux3Src = |
vromero@1591 | 70 | "package pkg;\n" + |
vromero@1591 | 71 | "public class ClassPathTestAux3 {}"; |
vromero@1591 | 72 | |
vromero@1591 | 73 | ProcessBuilder pb = null; |
vromero@1591 | 74 | |
vromero@1591 | 75 | public static void main(String[] args) throws Exception { |
vromero@1591 | 76 | new ClassPathTest().test(); |
vromero@1591 | 77 | } |
vromero@1591 | 78 | |
vromero@1591 | 79 | public void test() throws Exception { |
vromero@1591 | 80 | createOutputDirAndSourceFiles(); |
vromero@1591 | 81 | checkCompileCommands(); |
vromero@1591 | 82 | } |
vromero@1591 | 83 | |
vromero@1591 | 84 | void createOutputDirAndSourceFiles() throws Exception { |
vromero@1591 | 85 | //dirs and files creation |
vromero@1591 | 86 | ToolBox.createJavaFileFromSource(ClassPathTest1Src); |
vromero@1591 | 87 | ToolBox.createJavaFileFromSource(ClassPathTest2Src); |
vromero@1591 | 88 | ToolBox.createJavaFileFromSource(ClassPathTest3Src); |
vromero@1591 | 89 | ToolBox.createJavaFileFromSource(Paths.get("foo"), |
vromero@1591 | 90 | fooPkgClassPathTestAux1Src); |
vromero@1591 | 91 | ToolBox.createJavaFileFromSource(Paths.get("bar"), |
vromero@1591 | 92 | barPkgClassPathTestAux2Src); |
vromero@1591 | 93 | ToolBox.createJavaFileFromSource(pkgClassPathTestAux3Src); |
vromero@1591 | 94 | } |
vromero@1591 | 95 | |
vromero@1591 | 96 | void checkCompileCommands() throws Exception { |
vromero@1591 | 97 | // Without the -cp . parameter the command will fail seems like when called |
vromero@1591 | 98 | // from the command line, the current dir is added to the classpath |
vromero@1591 | 99 | // automatically but this is not happening when called using ProcessBuilder |
vromero@1591 | 100 | |
vromero@1591 | 101 | // testJavac success ClassPathTest3.java |
vromero@1637 | 102 | List<String> mainArgs = new ArrayList<>(); |
vromero@1637 | 103 | mainArgs.add(ToolBox.javacBinary.toString()); |
vromero@1637 | 104 | if (ToolBox.testToolVMOpts != null) { |
vromero@1637 | 105 | mainArgs.addAll(ToolBox.testToolVMOpts); |
vromero@1637 | 106 | } |
vromero@1591 | 107 | |
vromero@1637 | 108 | List<String> commonArgs = new ArrayList<>(); |
vromero@1637 | 109 | commonArgs.addAll(mainArgs); |
vromero@1637 | 110 | commonArgs.addAll(Arrays.asList("-cp", ".")); |
vromero@1637 | 111 | |
vromero@1637 | 112 | ToolBox.AnyToolArgs successParams = new ToolBox.AnyToolArgs() |
vromero@1637 | 113 | .appendArgs(commonArgs) |
vromero@1637 | 114 | .appendArgs("ClassPathTest3.java"); |
vromero@1591 | 115 | ToolBox.executeCommand(successParams); |
vromero@1591 | 116 | |
vromero@1591 | 117 | // testJavac failure ClassPathTest1.java |
vromero@1591 | 118 | ToolBox.AnyToolArgs failParams = |
vromero@1591 | 119 | new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) |
vromero@1637 | 120 | .appendArgs(commonArgs) |
vromero@1637 | 121 | .appendArgs("ClassPathTest1.java"); |
vromero@1591 | 122 | ToolBox.executeCommand(failParams); |
vromero@1591 | 123 | |
vromero@1591 | 124 | // This is done inside the executeCommand method |
vromero@1591 | 125 | // CLASSPATH=bar; export CLASSPATH |
vromero@1591 | 126 | |
vromero@1591 | 127 | Map<String, String> extVars = new TreeMap<>(); |
vromero@1591 | 128 | extVars.put("CLASSPATH", "bar"); |
vromero@1591 | 129 | |
vromero@1591 | 130 | // testJavac success ClassPathTest2.java |
vromero@1637 | 131 | successParams = new ToolBox.AnyToolArgs() |
vromero@1637 | 132 | .appendArgs(mainArgs) |
vromero@1637 | 133 | .appendArgs("ClassPathTest2.java") |
vromero@1637 | 134 | .set(extVars); |
vromero@1591 | 135 | ToolBox.executeCommand(successParams); |
vromero@1591 | 136 | |
vromero@1591 | 137 | // testJavac failure ClassPathTest1.java |
vromero@1637 | 138 | failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) |
vromero@1637 | 139 | .appendArgs(mainArgs) |
vromero@1637 | 140 | .appendArgs("ClassPathTest1.java") |
vromero@1637 | 141 | .set(extVars); |
vromero@1591 | 142 | ToolBox.executeCommand(failParams); |
vromero@1591 | 143 | |
vromero@1591 | 144 | // testJavac failure ClassPathTest3.java |
vromero@1637 | 145 | failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) |
vromero@1637 | 146 | .appendArgs(mainArgs) |
vromero@1637 | 147 | .appendArgs("ClassPathTest3.java") |
vromero@1637 | 148 | .set(extVars); |
vromero@1591 | 149 | ToolBox.executeCommand(failParams); |
vromero@1591 | 150 | |
vromero@1591 | 151 | // testJavac success -classpath foo ClassPathTest1.java |
vromero@1591 | 152 | |
vromero@1637 | 153 | commonArgs.clear(); |
vromero@1637 | 154 | commonArgs.addAll(mainArgs); |
vromero@1637 | 155 | commonArgs.addAll(Arrays.asList("-cp", "foo")); |
vromero@1637 | 156 | |
vromero@1637 | 157 | successParams = new ToolBox.AnyToolArgs() |
vromero@1637 | 158 | .appendArgs(commonArgs) |
vromero@1637 | 159 | .appendArgs("ClassPathTest1.java") |
vromero@1637 | 160 | .set(extVars); |
vromero@1591 | 161 | ToolBox.executeCommand(successParams); |
vromero@1591 | 162 | |
vromero@1591 | 163 | // testJavac failure -classpath foo ClassPathTest2.java |
vromero@1637 | 164 | failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) |
vromero@1637 | 165 | .appendArgs(commonArgs) |
vromero@1637 | 166 | .appendArgs("ClassPathTest2.java") |
vromero@1637 | 167 | .set(extVars); |
vromero@1591 | 168 | ToolBox.executeCommand(failParams); |
vromero@1591 | 169 | |
vromero@1591 | 170 | // testJavac failure -classpath foo ClassPathTest3.java |
vromero@1637 | 171 | failParams = new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL) |
vromero@1637 | 172 | .appendArgs(commonArgs) |
vromero@1637 | 173 | .appendArgs("ClassPathTest3.java") |
vromero@1637 | 174 | .set(extVars); |
vromero@1591 | 175 | ToolBox.executeCommand(failParams); |
vromero@1591 | 176 | } |
vromero@1591 | 177 | |
vromero@1591 | 178 | } |