author | lancea |
Thu, 14 Nov 2019 10:54:32 -0500 | |
changeset 59083 | 3e4d8b5856f3 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
1 |
/* |
15261 | 2 |
* Copyright (c) 2010, 2013, 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.util.ArrayList; |
6901 | 25 |
import java.util.Arrays; |
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
26 |
import java.util.List; |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
27 |
/* |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
28 |
* @test |
16013
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
15261
diff
changeset
|
29 |
* @bug 6746111 8005252 8008262 |
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
30 |
* @summary tests various classfile format and attribute handling by pack200 |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
31 |
* @compile -XDignore.symbol.file Utils.java AttributeTests.java |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
32 |
* @run main AttributeTests |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
33 |
* @author ksrini |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
34 |
*/ |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
35 |
public class AttributeTests { |
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
36 |
|
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
37 |
public static void main(String... args) throws Exception { |
6901 | 38 |
test6746111(); |
15261 | 39 |
testMethodParameters(); |
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
40 |
Utils.cleanup(); |
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
41 |
} |
6901 | 42 |
|
43 |
/* |
|
15261 | 44 |
* this tests ensure that MethodParameters produces by javac is packed |
45 |
* correctly. Usually this is not the case as new attributes are available |
|
46 |
* in the sdk jars, since MethodParameters happens to be an optional |
|
47 |
* attribute, thus this test. |
|
48 |
*/ |
|
49 |
static void testMethodParameters() throws Exception { |
|
50 |
List<String> scratch = new ArrayList<>(); |
|
51 |
final String fname = "MP"; |
|
52 |
String javaFileName = fname + Utils.JAVA_FILE_EXT; |
|
53 |
String javaClassName = fname + Utils.CLASS_FILE_EXT; |
|
54 |
scratch.add("class " + fname + " {"); |
|
55 |
scratch.add("void foo2(int j, final int k){}"); |
|
56 |
scratch.add("}"); |
|
57 |
File cwd = new File("."); |
|
58 |
File javaFile = new File(cwd, javaFileName); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
59 |
Utils.createFile(javaFile, scratch); |
15261 | 60 |
|
61 |
Utils.compiler(javaFile.getName(), "-parameters"); |
|
62 |
||
63 |
// jar the file up |
|
64 |
File testjarFile = new File(cwd, "test" + Utils.JAR_FILE_EXT); |
|
65 |
Utils.jar("cvf", testjarFile.getName(), javaClassName); |
|
66 |
||
16050
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
67 |
Utils.testWithRepack(testjarFile, "--unknown-attribute=error"); |
15261 | 68 |
} |
69 |
/* |
|
6901 | 70 |
* this test checks to see if we get the expected strings for output |
71 |
*/ |
|
72 |
static void test6746111() throws Exception { |
|
73 |
String pack200Cmd = Utils.getPack200Cmd(); |
|
74 |
File badAttrJar = new File(".", "badattr.jar"); |
|
75 |
Utils.copyFile(new File(Utils.TEST_SRC_DIR, "badattr.jar"), badAttrJar); |
|
76 |
File testJar = new File(".", "test.jar"); |
|
77 |
List<String> cmds = new ArrayList<String>(); |
|
78 |
cmds.add(pack200Cmd); |
|
79 |
cmds.add("--repack"); |
|
80 |
cmds.add("-v"); |
|
81 |
cmds.add(testJar.getAbsolutePath()); |
|
82 |
cmds.add(badAttrJar.getAbsolutePath()); |
|
83 |
List<String> output = Utils.runExec(cmds); |
|
84 |
/* |
|
85 |
* compare the repacked jar bit-wise, as all the files |
|
86 |
* should be transmitted "as-is". |
|
87 |
*/ |
|
88 |
Utils.doCompareBitWise(badAttrJar.getAbsoluteFile(), testJar.getAbsoluteFile()); |
|
89 |
String[] expectedStrings = { |
|
90 |
"WARNING: Passing class file uncompressed due to unrecognized" + |
|
91 |
" attribute: Foo.class", |
|
92 |
"INFO: com.sun.java.util.jar.pack.Attribute$FormatException: " + |
|
93 |
"class attribute \"XourceFile\": is unknown attribute " + |
|
94 |
"in class Foo", |
|
95 |
"INFO: com.sun.java.util.jar.pack.ClassReader$ClassFormatException: " + |
|
96 |
"AnnotationDefault: attribute length cannot be zero, in Test.message()", |
|
97 |
"WARNING: Passing class file uncompressed due to unknown class format: Test.class" |
|
98 |
}; |
|
99 |
List<String> notfoundList = new ArrayList<String>(); |
|
100 |
notfoundList.addAll(Arrays.asList(expectedStrings)); |
|
101 |
// make sure the expected messages are emitted |
|
102 |
for (String x : output) { |
|
103 |
findString(x, notfoundList, expectedStrings); |
|
104 |
} |
|
105 |
if (!notfoundList.isEmpty()) { |
|
106 |
System.out.println("Not found:"); |
|
107 |
for (String x : notfoundList) { |
|
108 |
System.out.println(x); |
|
109 |
} |
|
110 |
throw new Exception("Test fails: " + notfoundList.size() + |
|
111 |
" expected strings not found"); |
|
112 |
} |
|
113 |
testJar.delete(); |
|
114 |
badAttrJar.delete(); |
|
115 |
} |
|
116 |
||
117 |
private static void findString(String outputStr, List<String> notfoundList, |
|
118 |
String[] expectedStrings) { |
|
119 |
for (String y : expectedStrings) { |
|
120 |
if (outputStr.contains(y)) { |
|
121 |
notfoundList.remove(y); |
|
122 |
return; |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
6900
a3ca67586333
6982312: (pack200) pack200 fails with the jdk7 class files
ksrini
parents:
diff
changeset
|
126 |
} |