Thu, 07 Mar 2013 10:04:28 +0000
8009138: javac, equals-hashCode warning tuning
Reviewed-by: mcimadamore
1 /*
2 * Copyright (c) 2013, 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 */
24 /*
25 * @test
26 * @bug 4241229 4785453
27 * @summary Test -classpath option and classpath defaults.
28 * @library /tools/javac/lib
29 * @build ToolBox
30 * @run main ClassPathTest
31 */
33 import java.nio.file.Paths;
34 import java.util.Map;
35 import java.util.TreeMap;
36 import com.sun.tools.javac.util.ArrayUtils;
38 //original test: test/tools/javac/ClassPathTest/ClassPathTest.sh
39 public class ClassPathTest {
41 private static final String ClassPathTest1Src =
42 "import pkg.*;\n" +
43 "public class ClassPathTest1 {\n" +
44 " ClassPathTestAux1 x;\n" +
45 "}";
47 private static final String ClassPathTest2Src =
48 "import pkg.*;\n" +
49 "public class ClassPathTest2 {\n" +
50 " ClassPathTestAux2 x;\n" +
51 "}";
53 private static final String ClassPathTest3Src =
54 "import pkg.*;\n" +
55 "public class ClassPathTest3 {\n" +
56 " ClassPathTestAux3 x;\n" +
57 "}";
59 private static final String fooPkgClassPathTestAux1Src =
60 "package pkg;\n" +
61 "public class ClassPathTestAux1 {}";
63 private static final String barPkgClassPathTestAux2Src =
64 "package pkg;\n" +
65 "public class ClassPathTestAux2 {}";
67 private static final String pkgClassPathTestAux3Src =
68 "package pkg;\n" +
69 "public class ClassPathTestAux3 {}";
71 ProcessBuilder pb = null;
73 public static void main(String[] args) throws Exception {
74 new ClassPathTest().test();
75 }
77 public void test() throws Exception {
78 createOutputDirAndSourceFiles();
79 checkCompileCommands();
80 }
82 void createOutputDirAndSourceFiles() throws Exception {
83 //dirs and files creation
84 ToolBox.createJavaFileFromSource(ClassPathTest1Src);
85 ToolBox.createJavaFileFromSource(ClassPathTest2Src);
86 ToolBox.createJavaFileFromSource(ClassPathTest3Src);
87 ToolBox.createJavaFileFromSource(Paths.get("foo"),
88 fooPkgClassPathTestAux1Src);
89 ToolBox.createJavaFileFromSource(Paths.get("bar"),
90 barPkgClassPathTestAux2Src);
91 ToolBox.createJavaFileFromSource(pkgClassPathTestAux3Src);
92 }
94 void checkCompileCommands() throws Exception {
95 String[] mainArgs = ToolBox.getJavacBin();
97 // Without the -cp . parameter the command will fail seems like when called
98 // from the command line, the current dir is added to the classpath
99 // automatically but this is not happening when called using ProcessBuilder
101 // testJavac success ClassPathTest3.java
102 String[] commonArgs = ArrayUtils.concatOpen(mainArgs, "-cp", ".");
104 ToolBox.AnyToolArgs successParams =
105 new ToolBox.AnyToolArgs()
106 .setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest3.java"));
107 ToolBox.executeCommand(successParams);
109 // testJavac failure ClassPathTest1.java
110 ToolBox.AnyToolArgs failParams =
111 new ToolBox.AnyToolArgs(ToolBox.Expect.FAIL)
112 .setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest1.java"));
113 ToolBox.executeCommand(failParams);
115 // This is done inside the executeCommand method
116 // CLASSPATH=bar; export CLASSPATH
118 Map<String, String> extVars = new TreeMap<>();
119 extVars.put("CLASSPATH", "bar");
121 // testJavac success ClassPathTest2.java
122 successParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest2.java")).set(extVars);
123 ToolBox.executeCommand(successParams);
125 // testJavac failure ClassPathTest1.java
126 failParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest1.java")).set(extVars);
127 ToolBox.executeCommand(failParams);
129 // testJavac failure ClassPathTest3.java
130 failParams.setAllArgs(ArrayUtils.concatOpen(mainArgs, "ClassPathTest3.java"));
131 ToolBox.executeCommand(failParams);
133 // testJavac success -classpath foo ClassPathTest1.java
135 commonArgs = ArrayUtils.concatOpen(mainArgs, "-cp", "foo");
136 successParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest1.java"));
137 ToolBox.executeCommand(successParams);
139 // testJavac failure -classpath foo ClassPathTest2.java
140 failParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest2.java"));
141 ToolBox.executeCommand(failParams);
143 // testJavac failure -classpath foo ClassPathTest3.java
144 failParams.setAllArgs(ArrayUtils.concatOpen(commonArgs, "ClassPathTest3.java"));
145 ToolBox.executeCommand(failParams);
146 }
148 }