Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test |
aoqi@0 | 26 | * @bug 4098712 6304984 6388453 |
aoqi@0 | 27 | * @summary check that source files inside zip files on the class path are ignored |
aoqi@0 | 28 | * @library /tools/javac/lib |
aoqi@0 | 29 | * @build ToolBox |
aoqi@0 | 30 | * @run main JavaZipTest |
aoqi@0 | 31 | */ |
aoqi@0 | 32 | |
aoqi@0 | 33 | import java.io.File; |
aoqi@0 | 34 | import java.nio.file.Paths; |
aoqi@0 | 35 | |
aoqi@0 | 36 | //original test: test/tools/javac/javazip/Test.sh |
aoqi@0 | 37 | public class JavaZipTest { |
aoqi@0 | 38 | |
aoqi@0 | 39 | private static final String ASrc = |
aoqi@0 | 40 | "class A {\n" + |
aoqi@0 | 41 | " B b;\n" + |
aoqi@0 | 42 | "}"; |
aoqi@0 | 43 | |
aoqi@0 | 44 | private static final String BGoodSrc = |
aoqi@0 | 45 | "public class B {}"; |
aoqi@0 | 46 | |
aoqi@0 | 47 | private static final String BBadSrc = |
aoqi@0 | 48 | "class B"; |
aoqi@0 | 49 | |
aoqi@0 | 50 | private static final String[][] jarArgs = { |
aoqi@0 | 51 | {"cf", "good.jar", "-C", "good", "B.java"}, |
aoqi@0 | 52 | {"cf", "good.zip", "-C", "good", "B.java"}, |
aoqi@0 | 53 | {"cf", "bad.jar", "-C", "bad", "B.java"}, |
aoqi@0 | 54 | {"cf", "bad.zip", "-C", "bad", "B.java"}, |
aoqi@0 | 55 | }; |
aoqi@0 | 56 | |
aoqi@0 | 57 | private static final String[][] successfulCompilationArgs = { |
aoqi@0 | 58 | {"-d", "output", "A.java", "good/B.java"}, |
aoqi@0 | 59 | {"-d", "output", "-cp", "good", "A.java"}, |
aoqi@0 | 60 | {"-d", "output", "-sourcepath", "good", "A.java"}, |
aoqi@0 | 61 | {"-d", "output", "-cp", "good.zip", "A.java"}, |
aoqi@0 | 62 | {"-d", "output", "-cp", "good.jar", "A.java"}, |
aoqi@0 | 63 | }; |
aoqi@0 | 64 | |
aoqi@0 | 65 | private static final String[][] unSuccessfulCompilationArgs = { |
aoqi@0 | 66 | {"-d", "output", "A.java", "bad/B.java"}, |
aoqi@0 | 67 | {"-d", "output", "-cp", "bad", "A.java"}, |
aoqi@0 | 68 | {"-d", "output", "-sourcepath", "bad", "A.java"}, |
aoqi@0 | 69 | {"-d", "output", "-sourcepath", "bad.zip", "A.java"}, |
aoqi@0 | 70 | {"-d", "output", "-sourcepath", "bad.jar", "A.java"}, |
aoqi@0 | 71 | }; |
aoqi@0 | 72 | |
aoqi@0 | 73 | public static void main(String[] args) throws Exception { |
aoqi@0 | 74 | new JavaZipTest().test(); |
aoqi@0 | 75 | } |
aoqi@0 | 76 | |
aoqi@0 | 77 | public void test() throws Exception { |
aoqi@0 | 78 | createOutputDirAndSourceFiles(); |
aoqi@0 | 79 | createZipsAndJars(); |
aoqi@0 | 80 | check(ToolBox.Expect.SUCCESS, successfulCompilationArgs); |
aoqi@0 | 81 | check(ToolBox.Expect.FAIL, unSuccessfulCompilationArgs); |
aoqi@0 | 82 | } |
aoqi@0 | 83 | |
aoqi@0 | 84 | void createOutputDirAndSourceFiles() throws Exception { |
aoqi@0 | 85 | //create output dir |
aoqi@0 | 86 | new File("output").mkdir(); |
aoqi@0 | 87 | |
aoqi@0 | 88 | //source file creation |
aoqi@0 | 89 | ToolBox.createJavaFileFromSource(Paths.get("good"), BGoodSrc); |
aoqi@0 | 90 | ToolBox.createJavaFileFromSource(Paths.get("bad"), BBadSrc); |
aoqi@0 | 91 | ToolBox.createJavaFileFromSource(ASrc); |
aoqi@0 | 92 | } |
aoqi@0 | 93 | |
aoqi@0 | 94 | void createZipsAndJars() throws Exception { |
aoqi@0 | 95 | //jar and zip creation |
aoqi@0 | 96 | // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}good.jar" -C "${TESTSRC}${FS}good" B.java |
aoqi@0 | 97 | // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}good.zip" -C "${TESTSRC}${FS}good" B.java |
aoqi@0 | 98 | // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}bad.jar" -C "${TESTSRC}${FS}bad" B.java |
aoqi@0 | 99 | // check ok "${TESTJAVA}${FS}bin${FS}jar" cf "${SCR}${FS}bad.zip" -C "${TESTSRC}${FS}bad" B.java |
aoqi@0 | 100 | for (String[] args: jarArgs) { |
aoqi@0 | 101 | ToolBox.jar(args); |
aoqi@0 | 102 | } |
aoqi@0 | 103 | } |
aoqi@0 | 104 | |
aoqi@0 | 105 | void check(ToolBox.Expect whatToExpect, String[][] theArgs) throws Exception { |
aoqi@0 | 106 | // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} "${TESTSRC}${FS}A.java" "${TESTSRC}${FS}good${FS}B.java" |
aoqi@0 | 107 | // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${TESTSRC}${FS}good" "${TESTSRC}${FS}A.java" |
aoqi@0 | 108 | // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${TESTSRC}${FS}good" "${TESTSRC}${FS}A.java" |
aoqi@0 | 109 | // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${SCR}${FS}good.zip" "${TESTSRC}${FS}A.java" |
aoqi@0 | 110 | // check ok "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${SCR}${FS}good.jar" "${TESTSRC}${FS}A.java" |
aoqi@0 | 111 | |
aoqi@0 | 112 | // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} "${TESTSRC}${FS}A.java" "${TESTSRC}${FS}bad${FS}B.java" |
aoqi@0 | 113 | // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -classpath "${TESTSRC}${FS}bad" "${TESTSRC}${FS}A.java" |
aoqi@0 | 114 | // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${TESTSRC}${FS}bad" "${TESTSRC}${FS}A.java" |
aoqi@0 | 115 | // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${SCR}${FS}bad.zip" "${TESTSRC}${FS}A.java" |
aoqi@0 | 116 | // check err "${TESTJAVA}${FS}bin${FS}javac" ${TESTTOOLVMOPTS} -d ${TC} -sourcepath "${SCR}${FS}bad.jar" "${TESTSRC}${FS}A.java" |
aoqi@0 | 117 | ToolBox.JavaToolArgs args = |
aoqi@0 | 118 | new ToolBox.JavaToolArgs(whatToExpect); |
aoqi@0 | 119 | |
aoqi@0 | 120 | for (String[] allArgs: theArgs) { |
aoqi@0 | 121 | args.setAllArgs(allArgs); |
aoqi@0 | 122 | ToolBox.javac(args); |
aoqi@0 | 123 | } |
aoqi@0 | 124 | } |
aoqi@0 | 125 | |
aoqi@0 | 126 | } |