7802
|
1 |
/*
|
|
2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
import java.io.File;
|
|
24 |
import java.io.FileOutputStream;
|
|
25 |
import java.io.IOException;
|
|
26 |
import java.util.Map;
|
|
27 |
import java.util.jar.JarFile;
|
|
28 |
import java.util.jar.Pack200;
|
|
29 |
/*
|
|
30 |
* @test
|
|
31 |
* @bug 7007157
|
|
32 |
* @summary make sure the strip command works on an attribute
|
|
33 |
* @compile -XDignore.symbol.file Utils.java T7007157.java
|
|
34 |
* @run main T7007157
|
|
35 |
* @author ksrini
|
|
36 |
*/
|
|
37 |
public class T7007157 {
|
|
38 |
|
|
39 |
public static void main(String... args) throws IOException {
|
|
40 |
File sdkHome = Utils.JavaSDK;
|
|
41 |
File testJar = new File(new File(sdkHome, "lib"), "tools.jar");
|
|
42 |
JarFile jarFile = new JarFile(testJar);
|
|
43 |
File packFile = new File("foo.pack");
|
|
44 |
Pack200.Packer packer = Pack200.newPacker();
|
|
45 |
Map<String, String> p = packer.properties();
|
|
46 |
// Take the time optimization vs. space
|
|
47 |
p.put(packer.EFFORT, "1"); // CAUTION: do not use 0.
|
|
48 |
// Make the memory consumption as effective as possible
|
|
49 |
p.put(packer.SEGMENT_LIMIT, "10000");
|
|
50 |
// ignore all JAR deflation requests to save time
|
|
51 |
p.put(packer.DEFLATE_HINT, packer.FALSE);
|
|
52 |
// save the file ordering of the original JAR
|
|
53 |
p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
|
|
54 |
// strip the StackMapTables
|
|
55 |
p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
|
|
56 |
FileOutputStream fos = null;
|
|
57 |
try {
|
|
58 |
// Write out to a jtreg scratch area
|
|
59 |
fos = new FileOutputStream(packFile);
|
|
60 |
// Call the packer
|
|
61 |
packer.pack(jarFile, fos);
|
|
62 |
} finally {
|
|
63 |
Utils.close(fos);
|
|
64 |
Utils.close(jarFile);
|
|
65 |
}
|
|
66 |
}
|
|
67 |
}
|