jdk/test/sun/security/tools/jarsigner/LargeJarEntry.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 14342 8435a30053c1
child 42338 a60f280f803c
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 14182
diff changeset
     2
 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6405538 6474350
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Make sure jar files with large entries (more than max heap size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *    can be signed
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 14342
diff changeset
    29
 * @modules jdk.jartool/sun.security.tools.jarsigner
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run main/othervm -Xmx8M LargeJarEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.jar.JarEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.jar.JarOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.zip.CRC32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class LargeJarEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        String srcDir = System.getProperty("test.src", ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        String keystore = srcDir + "/JarSigning.keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        String jarName = "largeJarEntry.jar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        // Set java.io.tmpdir to the current working dir (see 6474350)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        // first, create jar file with 8M uncompressed entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        // note, we set the max heap size to 8M in @run tag above
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        byte[] bytes = new byte[1000000];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        CRC32 crc = new CRC32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        for (int i=0; i<8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            crc.update(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        JarEntry je = new JarEntry("large");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        je.setSize(8000000l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        je.setMethod(JarEntry.STORED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        je.setCrc(crc.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        File file = new File(jarName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        FileOutputStream os = new FileOutputStream(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        JarOutputStream jos = new JarOutputStream(os);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        jos.setMethod(JarEntry.STORED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        jos.putNextEntry(je);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        for (int i=0; i<8; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            jos.write(bytes, 0, bytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        jos.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                jarName, "b" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        // now, try to sign it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        try {
14182
3041082abb40 7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents: 5506
diff changeset
    76
            sun.security.tools.jarsigner.Main.main(jsArgs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } catch (OutOfMemoryError err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new Exception("Test failed with OutOfMemoryError", err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            // remove jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            file.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}