author | alanb |
Mon, 21 Jan 2013 23:23:12 -0500 | |
changeset 15684 | e5b41bd22ec9 |
parent 12544 | 5768f2e096de |
child 15261 | c5b882836677 |
permissions | -rw-r--r-- |
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
1 |
/* |
12544 | 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 | 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 | 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 | 39 |
test6746111(); |
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
40 |
} |
6901 | 41 |
|
42 |
/* |
|
43 |
* this test checks to see if we get the expected strings for output |
|
44 |
*/ |
|
45 |
static void test6746111() throws Exception { |
|
46 |
String pack200Cmd = Utils.getPack200Cmd(); |
|
47 |
File badAttrJar = new File(".", "badattr.jar"); |
|
48 |
Utils.copyFile(new File(Utils.TEST_SRC_DIR, "badattr.jar"), badAttrJar); |
|
49 |
File testJar = new File(".", "test.jar"); |
|
50 |
List<String> cmds = new ArrayList<String>(); |
|
51 |
cmds.add(pack200Cmd); |
|
52 |
cmds.add("--repack"); |
|
53 |
cmds.add("-v"); |
|
54 |
cmds.add(testJar.getAbsolutePath()); |
|
55 |
cmds.add(badAttrJar.getAbsolutePath()); |
|
56 |
List<String> output = Utils.runExec(cmds); |
|
57 |
/* |
|
58 |
* compare the repacked jar bit-wise, as all the files |
|
59 |
* should be transmitted "as-is". |
|
60 |
*/ |
|
61 |
Utils.doCompareBitWise(badAttrJar.getAbsoluteFile(), testJar.getAbsoluteFile()); |
|
62 |
String[] expectedStrings = { |
|
63 |
"WARNING: Passing class file uncompressed due to unrecognized" + |
|
64 |
" attribute: Foo.class", |
|
65 |
"INFO: com.sun.java.util.jar.pack.Attribute$FormatException: " + |
|
66 |
"class attribute \"XourceFile\": is unknown attribute " + |
|
67 |
"in class Foo", |
|
68 |
"INFO: com.sun.java.util.jar.pack.ClassReader$ClassFormatException: " + |
|
69 |
"AnnotationDefault: attribute length cannot be zero, in Test.message()", |
|
70 |
"WARNING: Passing class file uncompressed due to unknown class format: Test.class" |
|
71 |
}; |
|
72 |
List<String> notfoundList = new ArrayList<String>(); |
|
73 |
notfoundList.addAll(Arrays.asList(expectedStrings)); |
|
74 |
// make sure the expected messages are emitted |
|
75 |
for (String x : output) { |
|
76 |
findString(x, notfoundList, expectedStrings); |
|
77 |
} |
|
78 |
if (!notfoundList.isEmpty()) { |
|
79 |
System.out.println("Not found:"); |
|
80 |
for (String x : notfoundList) { |
|
81 |
System.out.println(x); |
|
82 |
} |
|
83 |
throw new Exception("Test fails: " + notfoundList.size() + |
|
84 |
" expected strings not found"); |
|
85 |
} |
|
86 |
testJar.delete(); |
|
87 |
badAttrJar.delete(); |
|
88 |
} |
|
89 |
||
90 |
private static void findString(String outputStr, List<String> notfoundList, |
|
91 |
String[] expectedStrings) { |
|
92 |
for (String y : expectedStrings) { |
|
93 |
if (outputStr.contains(y)) { |
|
94 |
notfoundList.remove(y); |
|
95 |
return; |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
99 |
} |