author | simonis |
Fri, 17 Jan 2014 21:54:30 +0100 | |
changeset 22602 | 0d9a07b0d7e9 |
parent 13675 | c2999ee84468 |
child 45944 | 882cea808912 |
permissions | -rw-r--r-- |
13675
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
1 |
/* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
4 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
8 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
13 |
* accompanied this code). |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
14 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
18 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
21 |
* questions. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
22 |
*/ |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
23 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
24 |
/* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
25 |
* @test |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
26 |
* @bug 7194005 |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
27 |
* @summary launcher handling of zip64 archives (Scenario A and B) |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
28 |
* @compile -XDignore.symbol.file BigJar.java |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
29 |
* @run main/timeout=600 BigJar |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
30 |
*/ |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
31 |
/* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
32 |
* This test consists of two scenarios: |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
33 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
34 |
* Scenario A: create a jar with entries exceeding 64K, add a main class and |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
35 |
* see if the launcher can handle it. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
36 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
37 |
* Scenario A1: create a jar as in A, but add a zipfile comment as well. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
38 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
39 |
* Scenario B: create a jar with a large enough file exceeding 4GB, and |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
40 |
* similarly test the launcher. This test can be run optionally by using the |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
41 |
* following jtreg option: |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
42 |
* "-javaoptions:-DBigJar_testScenarioB=true" |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
43 |
* or set |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
44 |
* "BigJar_testScenarioB" environment variable. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
45 |
* |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
46 |
* Note this test will only run iff all the disk requirements are met at runtime. |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
47 |
*/ |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
48 |
import java.io.BufferedInputStream; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
49 |
import java.io.BufferedOutputStream; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
50 |
import java.io.File; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
51 |
import java.io.FileInputStream; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
52 |
import java.io.FileOutputStream; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
53 |
import java.io.IOException; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
54 |
import java.io.OutputStream; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
55 |
import java.nio.file.Files; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
56 |
import java.nio.file.Path; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
57 |
import java.util.ArrayList; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
58 |
import java.util.List; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
59 |
import java.util.jar.Attributes; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
60 |
import java.util.jar.JarEntry; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
61 |
import java.util.jar.JarOutputStream; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
62 |
import java.util.jar.Manifest; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
63 |
import java.util.zip.CRC32; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
64 |
import java.util.zip.ZipEntry; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
65 |
import java.util.zip.ZipOutputStream; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
66 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
67 |
public class BigJar extends TestHelper { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
68 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
69 |
private static final long GIGA = 1024 * 1024 * 1024; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
70 |
private static final int BUFFER_LEN = Short.MAX_VALUE * 2; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
71 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
72 |
long getCount(long minlength) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
73 |
return (minlength / BUFFER_LEN) + 1; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
74 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
75 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
76 |
long computeCRC(long minlength) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
77 |
CRC32 crc = new CRC32(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
78 |
byte[] buffer = new byte[BUFFER_LEN]; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
79 |
long count = getCount(minlength); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
80 |
for (long i = 0; i < count; i++) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
81 |
crc.update(buffer); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
82 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
83 |
return crc.getValue(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
84 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
85 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
86 |
long computeCRC(File inFile) throws IOException { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
87 |
byte[] buffer = new byte[8192]; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
88 |
CRC32 crc = new CRC32(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
89 |
try (FileInputStream fis = new FileInputStream(inFile); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
90 |
BufferedInputStream bis = new BufferedInputStream(fis)) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
91 |
int n = bis.read(buffer); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
92 |
while (n > 0) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
93 |
crc.update(buffer, 0, n); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
94 |
n = bis.read(buffer); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
95 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
96 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
97 |
return crc.getValue(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
98 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
99 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
100 |
void createLargeFile(OutputStream os, long minlength) throws IOException { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
101 |
byte[] buffer = new byte[BUFFER_LEN]; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
102 |
long count = getCount(minlength); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
103 |
for (long i = 0; i < count; i++) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
104 |
os.write(buffer); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
105 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
106 |
os.flush(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
107 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
108 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
109 |
Manifest createMainClass(File javaFile) throws IOException { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
110 |
javaFile.delete(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
111 |
List<String> content = new ArrayList<>(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
112 |
content.add("public class " + baseName(javaFile) + "{"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
113 |
content.add("public static void main(String... args) {"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
114 |
content.add("System.out.println(\"Hello World\\n\");"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
115 |
content.add("System.exit(0);"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
116 |
content.add("}"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
117 |
content.add("}"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
118 |
createFile(javaFile, content); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
119 |
compile(javaFile.getName()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
120 |
Manifest manifest = new Manifest(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
121 |
manifest.clear(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
122 |
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
123 |
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, baseName(javaFile)); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
124 |
System.out.println(manifest.getMainAttributes().keySet()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
125 |
System.out.println(manifest.getMainAttributes().values()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
126 |
return manifest; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
127 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
128 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
129 |
void createJarWithLargeFile(File jarFile, long minlength) throws IOException { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
130 |
File javaFile = new File("Foo.java"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
131 |
Manifest manifest = createMainClass(javaFile); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
132 |
File classFile = getClassFile(javaFile); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
133 |
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
134 |
BufferedOutputStream bos = new BufferedOutputStream(jos); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
135 |
FileInputStream fis = new FileInputStream(classFile);) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
136 |
jos.setLevel(ZipOutputStream.STORED); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
137 |
jos.setMethod(0); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
138 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
139 |
JarEntry je = new JarEntry("large.data"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
140 |
je.setCompressedSize(getCount(minlength) * BUFFER_LEN); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
141 |
je.setSize(getCount(minlength) * BUFFER_LEN); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
142 |
je.setCrc(computeCRC(minlength)); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
143 |
je.setMethod(ZipEntry.STORED); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
144 |
jos.putNextEntry(je); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
145 |
createLargeFile(bos, minlength); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
146 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
147 |
je = new JarEntry(classFile.getName()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
148 |
je.setCompressedSize(classFile.length()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
149 |
je.setSize(classFile.length()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
150 |
je.setCrc(computeCRC(classFile)); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
151 |
je.setMethod(ZipEntry.STORED); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
152 |
jos.putNextEntry(je); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
153 |
copyStream(fis, bos); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
154 |
bos.flush(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
155 |
jos.closeEntry(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
156 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
157 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
158 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
159 |
void createLargeJar(File jarFile, String comment) throws IOException { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
160 |
final int MAX = Short.MAX_VALUE * 2 + 10; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
161 |
JarEntry je = null; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
162 |
File javaFile = new File("Foo.java"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
163 |
File classFile = getClassFile(javaFile); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
164 |
Manifest manifest = createMainClass(javaFile); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
165 |
try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
166 |
FileInputStream fis = new FileInputStream(classFile)) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
167 |
jos.setLevel(JarOutputStream.STORED); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
168 |
jos.setMethod(JarOutputStream.STORED); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
169 |
for (int i = 0; i < MAX; i++) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
170 |
je = new JarEntry("X" + i + ".txt"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
171 |
je.setSize(0); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
172 |
je.setCompressedSize(0); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
173 |
je.setCrc(0); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
174 |
jos.putNextEntry(je); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
175 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
176 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
177 |
// add a class file |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
178 |
je = new JarEntry(classFile.getName()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
179 |
je.setCompressedSize(classFile.length()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
180 |
je.setSize(classFile.length()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
181 |
je.setCrc(computeCRC(classFile)); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
182 |
jos.putNextEntry(je); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
183 |
copyStream(fis, jos); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
184 |
jos.closeEntry(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
185 |
if (comment != null) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
186 |
jos.setComment(comment); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
187 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
188 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
189 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
190 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
191 |
void testTheJar(File theJar) throws Exception { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
192 |
try { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
193 |
TestResult tr = doExec(javaCmd, "-jar", theJar.getName()); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
194 |
tr.checkPositive(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
195 |
if (!tr.testStatus) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
196 |
System.out.println(tr); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
197 |
throw new Exception("Failed"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
198 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
199 |
} finally { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
200 |
theJar.delete(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
201 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
202 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
203 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
204 |
// a jar with entries exceeding 64k + a class file for the existential test |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
205 |
@Test |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
206 |
void testScenarioA() throws Exception { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
207 |
File largeJar = new File("large.jar"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
208 |
createLargeJar(largeJar, null); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
209 |
testTheJar(largeJar); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
210 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
211 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
212 |
// a jar with entries exceeding 64k and zip comment |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
213 |
@Test |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
214 |
void testScenarioA1() throws Exception { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
215 |
File largeJar = new File("largewithcomment.jar"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
216 |
createLargeJar(largeJar, "A really large jar with a comment"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
217 |
testTheJar(largeJar); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
218 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
219 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
220 |
// a jar with an enormous file + a class file for the existential test |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
221 |
@Test |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
222 |
void testScenarioB() throws Exception { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
223 |
final String testString = "BigJar_testScenarioB"; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
224 |
if (Boolean.getBoolean(testString) == false && |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
225 |
System.getenv(testString) == null) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
226 |
System.out.println("Warning: testScenarioB passes vacuously"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
227 |
return; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
228 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
229 |
final File largeJar = new File("huge.jar"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
230 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
231 |
final Path path = largeJar.getAbsoluteFile().getParentFile().toPath(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
232 |
final long available = Files.getFileStore(path).getUsableSpace(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
233 |
final long MAX_VALUE = 0xFFFF_FFFFL; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
234 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
235 |
final long absolute = MAX_VALUE + 1L; |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
236 |
final long required = (long) (absolute * 1.1); // pad for sundries |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
237 |
System.out.println("\tavailable: " + available / GIGA + " GB"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
238 |
System.out.println("\trequired: " + required / GIGA + " GB"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
239 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
240 |
if (available > required) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
241 |
createJarWithLargeFile(largeJar, absolute); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
242 |
testTheJar(largeJar); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
243 |
} else { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
244 |
System.out.println("Warning: testScenarioB passes vacuously," |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
245 |
+ " requirements exceeds available space"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
246 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
247 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
248 |
|
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
249 |
public static void main(String... args) throws Exception { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
250 |
BigJar bj = new BigJar(); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
251 |
bj.run(args); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
252 |
if (testExitValue > 0) { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
253 |
System.out.println("Total of " + testExitValue + " failed"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
254 |
System.exit(1); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
255 |
} else { |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
256 |
System.out.println("All tests pass"); |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
257 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
258 |
} |
c2999ee84468
7194005: (launcher) needs to be enhanced for 64-bit jar file handling
ksrini
parents:
diff
changeset
|
259 |
} |