jdk/test/tools/pack200/T7007157.java
author michaelm
Tue, 06 Mar 2012 20:34:38 +0000
changeset 12047 320a714614e9
parent 7802 74f2ee2b62ba
child 18594 b6a3c9f71ac8
permissions -rw-r--r--
7113349: Initial changeset for Macosx port to jdk Reviewed-by: jjh, alanb, dholmes, anthony, ohrstrom, ksrini, jrose, weijun, smarks Contributed-by: Alan Bateman <alan.bateman@oracle.com>, Alexander Potochkin <alexander.potochkin@oracle.com>, Alexander Zuev <alexander.zuev@oracle.com>, Andrew Brygin <andrew.brygin@oracle.com>, Artem Ananiev <artem.ananiev@oracle.com>, Alex Strange <astrange@apple.com>, Bino George <bino@apple.com>, Christine Lu <christine.lu@oracle.com>, David Katleman <david.katleman@oracle.com>, David Durrence <david_durrence@apple.com>, Dmitry Cherepanov <dmitry.cherepanov@oracle.com>, Greg Lewis <glewis@eyesbeyond.com>, Kevin Miller <kevin_m_miller@apple.com>, Kurt Miller <kurt@intricatesoftware.com>, Landon Fuller <landonf@plausiblelabs.com>, Leonid Romanov <leonid.romanov@oracle.com>, Loefty Walkowiak <loefty@apple.com>, Mark Reinhold <mark.reinhold@oracle.com>, Naoto Sato <naoto.sato@oracle.com>, Philip Race <philip.race@oracle.com>, Roger Hoover <rhoover@apple.com>, Scott Kovatch <scott.kovatch@oracle.com>, Sergey ByloKhov <sergey.bylokhov@oracle.com>, Mike Swingler <swingler@apple.com>, Tomas Hurka <tomas.hurka@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
/*
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    41
        File testJar = new File(new File(sdkHome, "lib"), "tools.jar");
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    42
        JarFile jarFile = new JarFile(testJar);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    43
        File packFile = new File("foo.pack");
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    44
        Pack200.Packer packer = Pack200.newPacker();
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    45
        Map<String, String> p = packer.properties();
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    46
        // Take the time optimization vs. space
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    47
        p.put(packer.EFFORT, "1");  // CAUTION: do not use 0.
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    48
        // Make the memory consumption as effective as possible
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    49
        p.put(packer.SEGMENT_LIMIT, "10000");
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    50
        // ignore all JAR deflation requests to save time
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    51
        p.put(packer.DEFLATE_HINT, packer.FALSE);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    52
        // save the file ordering of the original JAR
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    53
        p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    54
        // strip the StackMapTables
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    55
        p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    56
        FileOutputStream fos = null;
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    57
        try {
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    58
            // Write out to a jtreg scratch area
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    59
            fos = new FileOutputStream(packFile);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    60
            // Call the packer
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    61
            packer.pack(jarFile, fos);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    62
        } finally {
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    63
            Utils.close(fos);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    64
            Utils.close(jarFile);
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    65
        }
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    66
    }
74f2ee2b62ba 7007157: (pack200) stripping attributes causes a NPE
ksrini
parents:
diff changeset
    67
}