jdk/test/tools/pack200/T7007157.java
author chegar
Wed, 03 Dec 2014 14:22:58 +0000
changeset 27565 729f9700483a
parent 18594 b6a3c9f71ac8
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: chegar, dfuchs, ihse, joehw, mullan, psandoz, wetmore Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7802
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     1
/*
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 18594
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
7802
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     4
 *
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     8
 *
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    13
 * accompanied this code).
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    14
 *
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    18
 *
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    21
 * questions.
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    22
 */
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    23
import java.io.File;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    24
import java.io.FileOutputStream;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    25
import java.io.IOException;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    26
import java.util.Map;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    27
import java.util.jar.JarFile;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    28
import java.util.jar.Pack200;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    29
/*
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    30
 * @test
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    31
 * @bug 7007157
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    32
 * @summary make sure the strip command works on an attribute
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    33
 * @compile -XDignore.symbol.file Utils.java T7007157.java
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    34
 * @run main T7007157
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    35
 * @author ksrini
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    36
 */
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    37
public class T7007157 {
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    38
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    39
    public static void main(String... args) throws IOException {
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    40
        File sdkHome = Utils.JavaSDK;
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 18594
diff changeset
    41
        File testJar = new File("test.jar");
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 18594
diff changeset
    42
        Utils.jar("cvf", testJar.getName(), Utils.TEST_CLS_DIR.getAbsolutePath());
7802
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    43
        JarFile jarFile = new JarFile(testJar);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    44
        File packFile = new File("foo.pack");
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    45
        Pack200.Packer packer = Pack200.newPacker();
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    46
        Map<String, String> p = packer.properties();
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    47
        // Take the time optimization vs. space
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    48
        p.put(packer.EFFORT, "1");  // CAUTION: do not use 0.
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    49
        // Make the memory consumption as effective as possible
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    50
        p.put(packer.SEGMENT_LIMIT, "10000");
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    51
        // ignore all JAR deflation requests to save time
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    52
        p.put(packer.DEFLATE_HINT, packer.FALSE);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    53
        // save the file ordering of the original JAR
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    54
        p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    55
        // strip the StackMapTables
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    56
        p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    57
        FileOutputStream fos = null;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    58
        try {
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    59
            // Write out to a jtreg scratch area
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    60
            fos = new FileOutputStream(packFile);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    61
            // Call the packer
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    62
            packer.pack(jarFile, fos);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    63
        } finally {
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    64
            Utils.close(fos);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    65
            Utils.close(jarFile);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    66
        }
18594
b6a3c9f71ac8 8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents: 7802
diff changeset
    67
        Utils.cleanup();
7802
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    68
    }
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    69
}