jdk/test/tools/pack200/AttributeTests.java
author alanb
Mon, 21 Jan 2013 23:23:12 -0500
changeset 15684 e5b41bd22ec9
parent 12544 5768f2e096de
child 15261 c5b882836677
permissions -rw-r--r--
8004931: add/removePropertyChangeListener should not exist in subset Profiles of Java SE Reviewed-by: dholmes, mchung, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     1
/*
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 6901
diff changeset
     2
 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     4
 *
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     8
 *
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    13
 * accompanied this code).
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    14
 *
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    18
 *
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    21
 * questions.
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    22
 */
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    23
import java.io.File;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    24
import java.io.IOException;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    25
import java.util.ArrayList;
6901
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    26
import java.util.Arrays;
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    27
import java.util.List;
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    28
/*
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    29
 * @test
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 6901
diff changeset
    30
 * @bug 6746111
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    31
 * @summary tests various classfile format and attribute handling by pack200
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    32
 * @compile -XDignore.symbol.file Utils.java AttributeTests.java
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    33
 * @run main AttributeTests
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    34
 * @author ksrini
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    35
 */
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    36
public class AttributeTests {
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    37
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    38
    public static void main(String... args) throws Exception {
6901
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    39
        test6746111();
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    40
    }
6901
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    41
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    42
    /*
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    43
     * this test checks to see if we get the expected strings for output
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    44
     */
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    45
    static void test6746111() throws Exception {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    46
        String pack200Cmd = Utils.getPack200Cmd();
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    47
        File badAttrJar = new File(".", "badattr.jar");
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    48
        Utils.copyFile(new File(Utils.TEST_SRC_DIR, "badattr.jar"), badAttrJar);
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    49
        File testJar = new File(".", "test.jar");
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    50
        List<String> cmds = new ArrayList<String>();
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    51
        cmds.add(pack200Cmd);
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    52
        cmds.add("--repack");
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    53
        cmds.add("-v");
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    54
        cmds.add(testJar.getAbsolutePath());
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    55
        cmds.add(badAttrJar.getAbsolutePath());
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    56
        List<String> output = Utils.runExec(cmds);
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    57
        /*
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    58
         * compare the repacked jar bit-wise, as all the files
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    59
         * should be transmitted "as-is".
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    60
         */
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    61
        Utils.doCompareBitWise(badAttrJar.getAbsoluteFile(), testJar.getAbsoluteFile());
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    62
        String[] expectedStrings = {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    63
            "WARNING: Passing class file uncompressed due to unrecognized" +
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    64
                    " attribute: Foo.class",
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    65
            "INFO: com.sun.java.util.jar.pack.Attribute$FormatException: " +
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    66
                    "class attribute \"XourceFile\":  is unknown attribute " +
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    67
                    "in class Foo",
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    68
            "INFO: com.sun.java.util.jar.pack.ClassReader$ClassFormatException: " +
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    69
                    "AnnotationDefault: attribute length cannot be zero, in Test.message()",
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    70
            "WARNING: Passing class file uncompressed due to unknown class format: Test.class"
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    71
        };
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    72
        List<String> notfoundList = new ArrayList<String>();
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    73
        notfoundList.addAll(Arrays.asList(expectedStrings));
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    74
        // make sure the expected messages are emitted
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    75
        for (String x : output) {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    76
            findString(x, notfoundList, expectedStrings);
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    77
        }
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    78
        if (!notfoundList.isEmpty()) {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    79
            System.out.println("Not found:");
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    80
            for (String x : notfoundList) {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    81
                System.out.println(x);
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    82
            }
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    83
            throw new Exception("Test fails: " + notfoundList.size() +
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    84
                    " expected strings not found");
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    85
        }
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    86
        testJar.delete();
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    87
        badAttrJar.delete();
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    88
    }
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    89
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    90
    private static void findString(String outputStr, List<String> notfoundList,
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    91
            String[] expectedStrings) {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    92
        for (String y : expectedStrings) {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    93
            if (outputStr.contains(y)) {
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    94
                notfoundList.remove(y);
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    95
                return;
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    96
            }
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    97
        }
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6900
diff changeset
    98
    }
6900
a3ca67586333 6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff changeset
    99
}