|
1 /* |
|
2 * Copyright (c) 2011, 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 |
|
24 /* |
|
25 * @test |
|
26 * @bug 6836682 |
|
27 * @summary JavacFileManager handles zip64 archives (64K+ entries and large file support) |
|
28 * @compile -XDignore.symbol.file T6836682.java Utils.java |
|
29 * @run main T6836682 |
|
30 */ |
|
31 import java.io.BufferedOutputStream; |
|
32 import java.io.File; |
|
33 import java.io.FileInputStream; |
|
34 import java.io.FileOutputStream; |
|
35 import java.io.IOException; |
|
36 import java.nio.file.Files; |
|
37 import java.nio.file.Path; |
|
38 import java.util.jar.JarOutputStream; |
|
39 import java.util.zip.ZipEntry; |
|
40 |
|
41 public class T6836682 { |
|
42 |
|
43 private static final long GIGA = 1024 * 1024 * 1024; |
|
44 |
|
45 static void createLargeFile(File outFile, long minlength) throws IOException { |
|
46 FileOutputStream fos = null; |
|
47 BufferedOutputStream bos = null; |
|
48 byte[] buffer = new byte[Short.MAX_VALUE * 2]; |
|
49 try { |
|
50 fos = new FileOutputStream(outFile); |
|
51 bos = new BufferedOutputStream(fos); |
|
52 long count = minlength / ( Short.MAX_VALUE * 2) + 1; |
|
53 for (long i = 0 ; i < count ; i++) { |
|
54 bos.write(buffer); |
|
55 } |
|
56 } finally { |
|
57 Utils.close(bos); |
|
58 Utils.close(fos); |
|
59 } |
|
60 if (outFile.length() < minlength) { |
|
61 throw new RuntimeException("could not create large file " + outFile.getAbsolutePath()); |
|
62 } |
|
63 } |
|
64 |
|
65 static void createJarWithLargeFile(File jarFile, File javaFile, |
|
66 long minlength) throws IOException { |
|
67 Utils.createClassFile(javaFile, null, true); |
|
68 File largeFile = new File("large.data"); |
|
69 createLargeFile(largeFile, minlength); |
|
70 String[] jarArgs = { |
|
71 "0cvf", |
|
72 jarFile.getAbsolutePath(), |
|
73 largeFile.getName(), |
|
74 Utils.getClassFileName(javaFile) |
|
75 }; |
|
76 Utils.jarTool.run(jarArgs); |
|
77 // deleted to prevent accidental linkage |
|
78 new File(Utils.getClassFileName(javaFile)).delete(); |
|
79 } |
|
80 |
|
81 static void createLargeJar(File jarFile, File javaFile) throws IOException { |
|
82 File classFile = new File(Utils.getClassFileName(javaFile)); |
|
83 Utils.createClassFile(javaFile, null, true); |
|
84 JarOutputStream jos = null; |
|
85 FileInputStream fis = null; |
|
86 try { |
|
87 jos = new JarOutputStream(new FileOutputStream(jarFile)); |
|
88 |
|
89 for (int i = 0; i < Short.MAX_VALUE * 2 + 10; i++) { |
|
90 jos.putNextEntry(new ZipEntry("X" + i + ".txt")); |
|
91 } |
|
92 jos.putNextEntry(new ZipEntry(classFile.getName())); |
|
93 fis = new FileInputStream(classFile); |
|
94 Utils.copyStream(fis, jos); |
|
95 } finally { |
|
96 Utils.close(jos); |
|
97 Utils.close(fis); |
|
98 } |
|
99 // deleted to prevent accidental linkage |
|
100 new File(Utils.getClassFileName(javaFile)).delete(); |
|
101 } |
|
102 |
|
103 // a jar with entries exceeding 64k + a class file for the existential test |
|
104 public static void testLargeJar(String... args) throws IOException { |
|
105 File largeJar = new File("large.jar"); |
|
106 File javaFile = new File("Foo.java"); |
|
107 createLargeJar(largeJar, javaFile); |
|
108 |
|
109 File testFile = new File("Bar.java"); |
|
110 try { |
|
111 Utils.createJavaFile(testFile, javaFile); |
|
112 if (!Utils.compile("-doe", "-verbose", "-cp", |
|
113 largeJar.getAbsolutePath(), testFile.getAbsolutePath())) { |
|
114 throw new IOException("test failed"); |
|
115 } |
|
116 } finally { |
|
117 Utils.deleteFile(largeJar); |
|
118 } |
|
119 } |
|
120 |
|
121 // a jar with an enormous file + a class file for the existential test |
|
122 public static void testHugeJar(String... args) throws IOException { |
|
123 final File largeJar = new File("huge.jar"); |
|
124 final File javaFile = new File("Foo.java"); |
|
125 |
|
126 final Path path = largeJar.getAbsoluteFile().getParentFile().toPath(); |
|
127 final long available = Files.getFileStore(path).getUsableSpace(); |
|
128 final long MAX_VALUE = 0xFFFF_FFFFL; |
|
129 |
|
130 final long absolute = MAX_VALUE + 1L; |
|
131 final long required = (long)(absolute * 1.1); // pad for sundries |
|
132 System.out.println("\tavailable: " + available / GIGA + " GB"); |
|
133 System.out.println("\required: " + required / GIGA + " GB"); |
|
134 |
|
135 if (available > required) { |
|
136 createJarWithLargeFile(largeJar, javaFile, absolute); |
|
137 File testFile = new File("Bar.java"); |
|
138 Utils.createJavaFile(testFile, javaFile); |
|
139 try { |
|
140 if (!Utils.compile("-doe", "-verbose", "-cp", |
|
141 largeJar.getAbsolutePath(), testFile.getAbsolutePath())) { |
|
142 throw new IOException("test failed"); |
|
143 } |
|
144 } finally { |
|
145 Utils.deleteFile(largeJar); |
|
146 } |
|
147 } else { |
|
148 System.out.println("Warning: test passes vacuously, requirements exceeds available space"); |
|
149 } |
|
150 } |
|
151 |
|
152 public static void main(String... args) throws IOException { |
|
153 testLargeJar(); |
|
154 testHugeJar(); |
|
155 } |
|
156 } |