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