Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
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 4098712 6304984 6388453
27 * @summary check that source files inside zip files on the class path are ignored
28 * @library /tools/javac/lib
29 * @build ToolBox
30 * @run main JavaZipTest
31 */
33 import java.io.File;
34 import java.nio.file.Paths;
36 //original test: test/tools/javac/javazip/Test.sh
37 public class JavaZipTest {
39 private static final String ASrc =
40 "class A {\n" +
41 " B b;\n" +
42 "}";
44 private static final String BGoodSrc =
45 "public class B {}";
47 private static final String BBadSrc =
48 "class B";
50 private static final String[][] jarArgs = {
51 {"cf", "good.jar", "-C", "good", "B.java"},
52 {"cf", "good.zip", "-C", "good", "B.java"},
53 {"cf", "bad.jar", "-C", "bad", "B.java"},
54 {"cf", "bad.zip", "-C", "bad", "B.java"},
55 };
57 private static final String[][] successfulCompilationArgs = {
58 {"-d", "output", "A.java", "good/B.java"},
59 {"-d", "output", "-cp", "good", "A.java"},
60 {"-d", "output", "-sourcepath", "good", "A.java"},
61 {"-d", "output", "-cp", "good.zip", "A.java"},
62 {"-d", "output", "-cp", "good.jar", "A.java"},
63 };
65 private static final String[][] unSuccessfulCompilationArgs = {
66 {"-d", "output", "A.java", "bad/B.java"},
67 {"-d", "output", "-cp", "bad", "A.java"},
68 {"-d", "output", "-sourcepath", "bad", "A.java"},
69 {"-d", "output", "-sourcepath", "bad.zip", "A.java"},
70 {"-d", "output", "-sourcepath", "bad.jar", "A.java"},
71 };
73 public static void main(String[] args) throws Exception {
74 new JavaZipTest().test();
75 }
77 public void test() throws Exception {
78 createOutputDirAndSourceFiles();
79 createZipsAndJars();
80 check(ToolBox.Expect.SUCCESS, successfulCompilationArgs);
81 check(ToolBox.Expect.FAIL, unSuccessfulCompilationArgs);
82 }
84 void createOutputDirAndSourceFiles() throws Exception {
85 //create output dir
86 new File("output").mkdir();
88 //source file creation
89 ToolBox.createJavaFileFromSource(Paths.get("good"), BGoodSrc);
90 ToolBox.createJavaFileFromSource(Paths.get("bad"), BBadSrc);
91 ToolBox.createJavaFileFromSource(ASrc);
92 }
94 void createZipsAndJars() throws Exception {
95 //jar and zip creation
96 // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}good.jar" -C "${TESTSRC}${FS}good" B.java
97 // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}good.zip" -C "${TESTSRC}${FS}good" B.java
98 // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}bad.jar" -C "${TESTSRC}${FS}bad" B.java
99 // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}bad.zip" -C "${TESTSRC}${FS}bad" B.java
100 for (String[] args: jarArgs) {
101 ToolBox.jar(args);
102 }
103 }
105 void check(ToolBox.Expect whatToExpect, String[][] theArgs) throws Exception {
106 // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} "${TESTSRC}${FS}A.java" "${TESTSRC}${FS}good${FS}B.java"
107 // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${TESTSRC}${FS}good" "${TESTSRC}${FS}A.java"
108 // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${TESTSRC}${FS}good" "${TESTSRC}${FS}A.java"
109 // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${SCR}${FS}good.zip" "${TESTSRC}${FS}A.java"
110 // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${SCR}${FS}good.jar" "${TESTSRC}${FS}A.java"
112 // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} "${TESTSRC}${FS}A.java" "${TESTSRC}${FS}bad${FS}B.java"
113 // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${TESTSRC}${FS}bad" "${TESTSRC}${FS}A.java"
114 // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${TESTSRC}${FS}bad" "${TESTSRC}${FS}A.java"
115 // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${SCR}${FS}bad.zip" "${TESTSRC}${FS}A.java"
116 // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${SCR}${FS}bad.jar" "${TESTSRC}${FS}A.java"
117 ToolBox.JavaToolArgs args =
118 new ToolBox.JavaToolArgs(whatToExpect);
120 for (String[] allArgs: theArgs) {
121 args.setAllArgs(allArgs);
122 ToolBox.javac(args);
123 }
124 }
126 }