author | lancea |
Thu, 14 Nov 2019 10:54:32 -0500 | |
changeset 59083 | 3e4d8b5856f3 |
parent 50603 | 95c0644a1c47 |
permissions | -rw-r--r-- |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
1 |
/* |
36111
00ec08e93b0c
8149154: tools/pack200/Pack200Test.java failed with NullPointerException
amlu
parents:
28255
diff
changeset
|
2 |
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
4 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
8 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
13 |
* accompanied this code). |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
14 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
18 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
21 |
* questions. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
22 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
23 |
|
9009
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
24 |
import java.nio.file.Path; |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
25 |
import java.io.BufferedReader; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
26 |
import java.io.ByteArrayOutputStream; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
27 |
import java.io.Closeable; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
28 |
import java.io.File; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
29 |
import java.io.FileFilter; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
30 |
import java.io.FileOutputStream; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
31 |
import java.io.IOException; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
32 |
import java.io.InputStream; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
33 |
import java.io.InputStreamReader; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
34 |
import java.io.PrintStream; |
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
35 |
import java.net.URI; |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
36 |
import java.nio.charset.Charset; |
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
37 |
import java.nio.file.attribute.BasicFileAttributes; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
38 |
import java.nio.file.FileSystem; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
39 |
import java.nio.file.FileSystems; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
40 |
import java.nio.file.FileVisitResult; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
41 |
import java.nio.file.FileVisitor; |
9009
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
42 |
import java.nio.file.Files; |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
43 |
import java.util.ArrayList; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
44 |
import java.util.Arrays; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
45 |
import java.util.Collections; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
46 |
import java.util.List; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
47 |
import java.util.Map; |
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
48 |
import java.util.HashMap; |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
49 |
import java.util.jar.JarFile; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
50 |
import java.util.jar.JarOutputStream; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
51 |
import java.util.jar.Pack200; |
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
52 |
import java.util.regex.Matcher; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
53 |
import java.util.regex.Pattern; |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
54 |
import java.util.zip.ZipEntry; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
55 |
import java.util.zip.ZipFile; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
56 |
|
9009
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
57 |
import static java.nio.file.StandardCopyOption.*; |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
58 |
import static java.nio.file.StandardOpenOption.*; |
9009
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
59 |
|
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
60 |
|
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
61 |
/** |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
62 |
* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
63 |
* @author ksrini |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
64 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
65 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
66 |
/* |
27565 | 67 |
* This class contains the commonly used utilities. |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
68 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
69 |
class Utils { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
70 |
static final String JavaHome = System.getProperty("test.java", |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
71 |
System.getProperty("java.home")); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
72 |
static final boolean IsWindows = |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
73 |
System.getProperty("os.name").startsWith("Windows"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
74 |
static final boolean Is64Bit = |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
75 |
System.getProperty("sun.arch.data.model", "32").equals("64"); |
28255
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
76 |
static final File JavaSDK = new File(JavaHome); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
77 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
78 |
static final String PACK_FILE_EXT = ".pack"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
79 |
static final String JAVA_FILE_EXT = ".java"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
80 |
static final String CLASS_FILE_EXT = ".class"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
81 |
static final String JAR_FILE_EXT = ".jar"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
82 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
83 |
static final File TEST_SRC_DIR = new File(System.getProperty("test.src")); |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
84 |
static final File TEST_CLS_DIR = new File(System.getProperty("test.classes")); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
85 |
static final String VERIFIER_DIR_NAME = "pack200-verifier"; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
86 |
static final File VerifierJar = new File(VERIFIER_DIR_NAME + JAR_FILE_EXT); |
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
87 |
static final File XCLASSES = new File("xclasses"); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
88 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
89 |
private Utils() {} // all static |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
90 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
91 |
private static void init() throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
92 |
if (VerifierJar.exists()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
93 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
94 |
} |
28255
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
95 |
File srcDir = new File(getVerifierDir(), "src"); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
96 |
List<File> javaFileList = findFiles(srcDir, createFilter(JAVA_FILE_EXT)); |
41752
0c5a98b2e56c
8160213: tools/pack200/Utils.java should clean up javac*.tmp files
ksrini
parents:
40261
diff
changeset
|
97 |
File tmpFile = File.createTempFile("javac", ".tmp", new File(".")); |
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
98 |
XCLASSES.mkdirs(); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
99 |
FileOutputStream fos = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
100 |
PrintStream ps = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
101 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
102 |
fos = new FileOutputStream(tmpFile); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
103 |
ps = new PrintStream(fos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
104 |
for (File f : javaFileList) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
105 |
ps.println(f.getAbsolutePath()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
106 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
107 |
} finally { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
108 |
close(ps); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
109 |
close(fos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
110 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
111 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
112 |
compiler("-d", |
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
113 |
XCLASSES.getName(), |
43185 | 114 |
"--add-modules=jdk.jdeps", |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38421
diff
changeset
|
115 |
"--add-exports=jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED", |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
116 |
"@" + tmpFile.getAbsolutePath()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
117 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
118 |
jar("cvfe", |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
119 |
VerifierJar.getName(), |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
120 |
"sun.tools.pack.verify.Main", |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
121 |
"-C", |
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
122 |
XCLASSES.getName(), |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
123 |
"."); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
124 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
125 |
|
28255
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
126 |
private static File getVerifierDir() { |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
127 |
File srcDir = new File(TEST_SRC_DIR, VERIFIER_DIR_NAME); |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
128 |
if (!srcDir.exists()) { |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
129 |
// if not available try one level above |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
130 |
srcDir = new File(TEST_SRC_DIR.getParentFile(), VERIFIER_DIR_NAME); |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
131 |
} |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
132 |
return srcDir; |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
133 |
} |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
134 |
|
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
135 |
static File getGoldenJar() { |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
136 |
return new File(new File(getVerifierDir(), "data"), "golden.jar"); |
ddb0157601ed
8067889: 4 pack200 tests fail on mac since jdk became modular
ksrini
parents:
27565
diff
changeset
|
137 |
} |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
138 |
static void dirlist(File dir) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
139 |
File[] files = dir.listFiles(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
140 |
System.out.println("--listing " + dir.getAbsolutePath() + "---"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
141 |
for (File f : files) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
142 |
StringBuffer sb = new StringBuffer(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
143 |
sb.append(f.isDirectory() ? "d " : "- "); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
144 |
sb.append(f.getName()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
145 |
System.out.println(sb); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
146 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
147 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
148 |
static void doCompareVerify(File reference, File specimen) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
149 |
init(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
150 |
List<String> cmds = new ArrayList<String>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
151 |
cmds.add(getJavaCmd()); |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38421
diff
changeset
|
152 |
cmds.add("--add-exports=jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED"); |
12544 | 153 |
cmds.add("-cp"); |
27565 | 154 |
cmds.add(VerifierJar.getName()); |
12544 | 155 |
cmds.add("sun.tools.pack.verify.Main"); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
156 |
cmds.add(reference.getAbsolutePath()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
157 |
cmds.add(specimen.getAbsolutePath()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
158 |
cmds.add("-O"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
159 |
runExec(cmds); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
160 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
161 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
162 |
static void doCompareBitWise(File reference, File specimen) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
163 |
throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
164 |
init(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
165 |
List<String> cmds = new ArrayList<String>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
166 |
cmds.add(getJavaCmd()); |
12544 | 167 |
cmds.add("-cp"); |
27565 | 168 |
cmds.add(VerifierJar.getName()); |
12544 | 169 |
cmds.add("sun.tools.pack.verify.Main"); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
170 |
cmds.add(reference.getName()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
171 |
cmds.add(specimen.getName()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
172 |
cmds.add("-O"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
173 |
cmds.add("-b"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
174 |
runExec(cmds); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
175 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
176 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
177 |
static FileFilter createFilter(final String extension) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
178 |
return new FileFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
179 |
@Override |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
180 |
public boolean accept(File pathname) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
181 |
String name = pathname.getName(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
182 |
if (name.endsWith(extension)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
183 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
184 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
185 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
186 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
187 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
188 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
189 |
|
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
190 |
/* |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
191 |
* clean up all the usual suspects |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
192 |
*/ |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
193 |
static void cleanup() throws IOException { |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
194 |
recursiveDelete(XCLASSES); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
195 |
List<File> toDelete = new ArrayList<>(); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
196 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
197 |
Utils.createFilter(".out"))); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
198 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
199 |
Utils.createFilter(".bak"))); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
200 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
201 |
Utils.createFilter(".jar"))); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
202 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
203 |
Utils.createFilter(".pack"))); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
204 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
205 |
Utils.createFilter(".bnd"))); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
206 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
207 |
Utils.createFilter(".txt"))); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
208 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
209 |
Utils.createFilter(".idx"))); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
210 |
toDelete.addAll(Utils.findFiles(new File("."), |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
211 |
Utils.createFilter(".gidx"))); |
41752
0c5a98b2e56c
8160213: tools/pack200/Utils.java should clean up javac*.tmp files
ksrini
parents:
40261
diff
changeset
|
212 |
toDelete.addAll(Utils.findFiles(new File("."), |
0c5a98b2e56c
8160213: tools/pack200/Utils.java should clean up javac*.tmp files
ksrini
parents:
40261
diff
changeset
|
213 |
Utils.createFilter(".tmp"))); |
0c5a98b2e56c
8160213: tools/pack200/Utils.java should clean up javac*.tmp files
ksrini
parents:
40261
diff
changeset
|
214 |
toDelete.addAll(Utils.findFiles(new File("."), |
0c5a98b2e56c
8160213: tools/pack200/Utils.java should clean up javac*.tmp files
ksrini
parents:
40261
diff
changeset
|
215 |
Utils.createFilter(".class"))); |
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
216 |
for (File f : toDelete) { |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
217 |
f.delete(); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
218 |
} |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
219 |
} |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
220 |
|
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
221 |
static final FileFilter DIR_FILTER = new FileFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
222 |
public boolean accept(File pathname) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
223 |
if (pathname.isDirectory()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
224 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
225 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
226 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
227 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
228 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
229 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
230 |
static final FileFilter FILE_FILTER = new FileFilter() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
231 |
public boolean accept(File pathname) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
232 |
if (pathname.isFile()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
233 |
return true; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
234 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
235 |
return false; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
236 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
237 |
}; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
238 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
239 |
static void copyFile(File src, File dst) throws IOException { |
9009
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
240 |
Path parent = dst.toPath().getParent(); |
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
241 |
if (parent != null) { |
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
242 |
Files.createDirectories(parent); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
243 |
} |
9009
e7036c254324
7031166: (pack200) tools/pack200/CommandLineTests.java fail with testsdk on RO filesystem
ksrini
parents:
6323
diff
changeset
|
244 |
Files.copy(src.toPath(), dst.toPath(), COPY_ATTRIBUTES, REPLACE_EXISTING); |
18594
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
245 |
if (dst.isDirectory() && !dst.canWrite()) { |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
246 |
dst.setWritable(true); |
b6a3c9f71ac8
8017463: [TEST_BUG] 2 tests from tools/pack200/ remain about 1 GB of data in work directory after execution
ksrini
parents:
17490
diff
changeset
|
247 |
} |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
248 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
249 |
|
6320 | 250 |
static String baseName(File file, String extension) { |
251 |
return baseName(file.getAbsolutePath(), extension); |
|
252 |
} |
|
253 |
||
254 |
static String baseName(String name, String extension) { |
|
255 |
int cut = name.length() - extension.length(); |
|
256 |
return name.lastIndexOf(extension) == cut |
|
257 |
? name.substring(0, cut) |
|
258 |
: name; |
|
259 |
||
260 |
} |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
261 |
static void createFile(File outFile, List<String> content) throws IOException { |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
262 |
Files.write(outFile.getAbsoluteFile().toPath(), content, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
263 |
Charset.defaultCharset(), CREATE_NEW, TRUNCATE_EXISTING); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16050
diff
changeset
|
264 |
} |
6320 | 265 |
|
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
266 |
/* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
267 |
* Suppose a path is provided which consists of a full path |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
268 |
* this method returns the sub path for a full path ex: /foo/bar/baz/foobar.z |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
269 |
* and the base path is /foo/bar it will will return baz/foobar.z. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
270 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
271 |
private static String getEntryPath(String basePath, String fullPath) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
272 |
if (!fullPath.startsWith(basePath)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
273 |
return null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
274 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
275 |
return fullPath.substring(basePath.length()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
276 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
277 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
278 |
static String getEntryPath(File basePathFile, File fullPathFile) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
279 |
return getEntryPath(basePathFile.toString(), fullPathFile.toString()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
280 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
281 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
282 |
public static void recursiveCopy(File src, File dest) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
283 |
if (!src.exists() || !src.canRead()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
284 |
throw new IOException("file not found or readable: " + src); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
285 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
286 |
if (dest.exists() && !dest.isDirectory() && !dest.canWrite()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
287 |
throw new IOException("file not found or writeable: " + dest); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
288 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
289 |
if (!dest.exists()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
290 |
dest.mkdirs(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
291 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
292 |
List<File> a = directoryList(src); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
293 |
for (File f : a) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
294 |
copyFile(f, new File(dest, getEntryPath(src, f))); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
295 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
296 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
297 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
298 |
static List<File> directoryList(File dirname) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
299 |
List<File> dirList = new ArrayList<File>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
300 |
return directoryList(dirname, dirList, null); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
301 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
302 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
303 |
private static List<File> directoryList(File dirname, List<File> dirList, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
304 |
File[] dirs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
305 |
dirList.addAll(Arrays.asList(dirname.listFiles(FILE_FILTER))); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
306 |
dirs = dirname.listFiles(DIR_FILTER); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
307 |
for (File f : dirs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
308 |
if (f.isDirectory() && !f.equals(dirname)) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
309 |
dirList.add(f); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
310 |
directoryList(f, dirList, dirs); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
311 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
312 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
313 |
return dirList; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
314 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
315 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
316 |
static void recursiveDelete(File dir) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
317 |
if (dir.isFile()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
318 |
dir.delete(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
319 |
} else if (dir.isDirectory()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
320 |
File[] entries = dir.listFiles(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
321 |
for (int i = 0; i < entries.length; i++) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
322 |
if (entries[i].isDirectory()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
323 |
recursiveDelete(entries[i]); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
324 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
325 |
entries[i].delete(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
326 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
327 |
dir.delete(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
328 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
329 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
330 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
331 |
static List<File> findFiles(File startDir, FileFilter filter) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
332 |
throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
333 |
List<File> list = new ArrayList<File>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
334 |
findFiles0(startDir, list, filter); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
335 |
return list; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
336 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
337 |
/* |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
338 |
* finds files in the start directory using the the filter, appends |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
339 |
* the files to the dirList. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
340 |
*/ |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
341 |
private static void findFiles0(File startDir, List<File> list, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
342 |
FileFilter filter) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
343 |
File[] foundFiles = startDir.listFiles(filter); |
36111
00ec08e93b0c
8149154: tools/pack200/Pack200Test.java failed with NullPointerException
amlu
parents:
28255
diff
changeset
|
344 |
if (foundFiles == null) { |
00ec08e93b0c
8149154: tools/pack200/Pack200Test.java failed with NullPointerException
amlu
parents:
28255
diff
changeset
|
345 |
return; |
00ec08e93b0c
8149154: tools/pack200/Pack200Test.java failed with NullPointerException
amlu
parents:
28255
diff
changeset
|
346 |
} |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
347 |
list.addAll(Arrays.asList(foundFiles)); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
348 |
File[] dirs = startDir.listFiles(DIR_FILTER); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
349 |
for (File dir : dirs) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
350 |
findFiles0(dir, list, filter); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
351 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
352 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
353 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
354 |
static void close(Closeable c) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
355 |
if (c == null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
356 |
return; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
357 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
358 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
359 |
c.close(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
360 |
} catch (IOException ignore) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
361 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
362 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
363 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
364 |
static void compiler(String... javacCmds) { |
27565 | 365 |
List<String> cmdList = new ArrayList<>(); |
366 |
cmdList.add(getJavacCmd()); |
|
367 |
for (String x : javacCmds) { |
|
368 |
cmdList.add(x); |
|
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
369 |
} |
27565 | 370 |
runExec(cmdList); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
371 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
372 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
373 |
static void jar(String... jargs) { |
27565 | 374 |
List<String> cmdList = new ArrayList<>(); |
375 |
cmdList.add(getJarCmd()); |
|
376 |
for (String x : jargs) { |
|
377 |
cmdList.add(x); |
|
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
378 |
} |
27565 | 379 |
runExec(cmdList); |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
380 |
} |
16050
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
381 |
|
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
382 |
static void testWithRepack(File inFile, String... repackOpts) throws IOException { |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
383 |
File cwd = new File("."); |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
384 |
// pack using --repack in native mode |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
385 |
File nativejarFile = new File(cwd, "out-n" + Utils.JAR_FILE_EXT); |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
386 |
repack(inFile, nativejarFile, false, repackOpts); |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
387 |
doCompareVerify(inFile, nativejarFile); |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
388 |
|
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
389 |
// ensure bit compatibility between the unpacker variants |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
390 |
File javajarFile = new File(cwd, "out-j" + Utils.JAR_FILE_EXT); |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
391 |
repack(inFile, javajarFile, true, repackOpts); |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
392 |
doCompareBitWise(javajarFile, nativejarFile); |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
393 |
} |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
394 |
|
16013
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
395 |
static List<String> repack(File inFile, File outFile, |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
396 |
boolean disableNative, String... extraOpts) { |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
397 |
List<String> cmdList = new ArrayList<>(); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
398 |
cmdList.clear(); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
399 |
cmdList.add(Utils.getJavaCmd()); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
400 |
cmdList.add("-ea"); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
401 |
cmdList.add("-esa"); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
402 |
if (disableNative) { |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
403 |
cmdList.add("-Dcom.sun.java.util.jar.pack.disable.native=true"); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
404 |
} |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
405 |
cmdList.add("com.sun.java.util.jar.pack.Driver"); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
406 |
cmdList.add("--repack"); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
407 |
if (extraOpts != null) { |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
408 |
for (String opt: extraOpts) { |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
409 |
cmdList.add(opt); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
410 |
} |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
411 |
} |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
412 |
cmdList.add(outFile.getName()); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
413 |
cmdList.add(inFile.getName()); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
414 |
return Utils.runExec(cmdList); |
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
12544
diff
changeset
|
415 |
} |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
416 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
417 |
// given a jar file foo.jar will write to foo.pack |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
418 |
static void pack(JarFile jarFile, File packFile) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
419 |
Pack200.Packer packer = Pack200.newPacker(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
420 |
Map<String, String> p = packer.properties(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
421 |
// Take the time optimization vs. space |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
422 |
p.put(packer.EFFORT, "1"); // CAUTION: do not use 0. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
423 |
// Make the memory consumption as effective as possible |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
424 |
p.put(packer.SEGMENT_LIMIT, "10000"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
425 |
// ignore all JAR deflation requests to save time |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
426 |
p.put(packer.DEFLATE_HINT, packer.FALSE); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
427 |
// save the file ordering of the original JAR |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
428 |
p.put(packer.KEEP_FILE_ORDER, packer.TRUE); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
429 |
FileOutputStream fos = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
430 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
431 |
// Write out to a jtreg scratch area |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
432 |
fos = new FileOutputStream(packFile); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
433 |
// Call the packer |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
434 |
packer.pack(jarFile, fos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
435 |
} finally { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
436 |
close(fos); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
437 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
438 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
439 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
440 |
// uses java unpacker, slow but useful to discover issues with the packer |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
441 |
static void unpackj(File inFile, JarOutputStream jarStream) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
442 |
throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
443 |
unpack0(inFile, jarStream, true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
444 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
445 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
446 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
447 |
// uses native unpacker using the java APIs |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
448 |
static void unpackn(File inFile, JarOutputStream jarStream) |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
449 |
throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
450 |
unpack0(inFile, jarStream, false); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
451 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
452 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
453 |
// given a packed file, create the jar file in the current directory. |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
454 |
private static void unpack0(File inFile, JarOutputStream jarStream, |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
455 |
boolean useJavaUnpack) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
456 |
// Unpack the files |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
457 |
Pack200.Unpacker unpacker = Pack200.newUnpacker(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
458 |
Map<String, String> props = unpacker.properties(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
459 |
if (useJavaUnpack) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
460 |
props.put("com.sun.java.util.jar.pack.disable.native", "true"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
461 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
462 |
// Call the unpacker |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
463 |
unpacker.unpack(inFile, jarStream); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
464 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
465 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
466 |
static byte[] getBuffer(ZipFile zf, ZipEntry ze) throws IOException { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
467 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
468 |
byte buf[] = new byte[8192]; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
469 |
InputStream is = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
470 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
471 |
is = zf.getInputStream(ze); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
472 |
int n = is.read(buf); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
473 |
while (n > 0) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
474 |
baos.write(buf, 0, n); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
475 |
n = is.read(buf); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
476 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
477 |
return baos.toByteArray(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
478 |
} finally { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
479 |
close(is); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
480 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
481 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
482 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
483 |
static ArrayList<String> getZipFileEntryNames(ZipFile z) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
484 |
ArrayList<String> out = new ArrayList<String>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
485 |
for (ZipEntry ze : Collections.list(z.entries())) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
486 |
out.add(ze.getName()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
487 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
488 |
return out; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
489 |
} |
38421 | 490 |
|
491 |
static List<String> runExec(String... cmds) { |
|
492 |
return runExec(Arrays.asList(cmds)); |
|
493 |
} |
|
494 |
||
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
495 |
static List<String> runExec(List<String> cmdsList) { |
6323
1cdec3dff0a3
6966740: (pack200) need to add the timezone regression test
ksrini
parents:
6320
diff
changeset
|
496 |
return runExec(cmdsList, null); |
1cdec3dff0a3
6966740: (pack200) need to add the timezone regression test
ksrini
parents:
6320
diff
changeset
|
497 |
} |
38421 | 498 |
|
6323
1cdec3dff0a3
6966740: (pack200) need to add the timezone regression test
ksrini
parents:
6320
diff
changeset
|
499 |
static List<String> runExec(List<String> cmdsList, Map<String, String> penv) { |
50603 | 500 |
return runExec(cmdsList, penv, false); |
501 |
} |
|
502 |
||
503 |
static List<String> runExec(List<String> cmdsList, Map<String, String> penv, boolean ignoreReturnValue) { |
|
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
504 |
ArrayList<String> alist = new ArrayList<String>(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
505 |
ProcessBuilder pb = |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
506 |
new ProcessBuilder(cmdsList); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
507 |
Map<String, String> env = pb.environment(); |
6323
1cdec3dff0a3
6966740: (pack200) need to add the timezone regression test
ksrini
parents:
6320
diff
changeset
|
508 |
if (penv != null && !penv.isEmpty()) { |
1cdec3dff0a3
6966740: (pack200) need to add the timezone regression test
ksrini
parents:
6320
diff
changeset
|
509 |
env.putAll(penv); |
1cdec3dff0a3
6966740: (pack200) need to add the timezone regression test
ksrini
parents:
6320
diff
changeset
|
510 |
} |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
511 |
pb.directory(new File(".")); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
512 |
dirlist(new File(".")); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
513 |
for (String x : cmdsList) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
514 |
System.out.print(x + " "); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
515 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
516 |
System.out.println(""); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
517 |
int retval = 0; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
518 |
Process p = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
519 |
InputStreamReader ir = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
520 |
BufferedReader rd = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
521 |
InputStream is = null; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
522 |
try { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
523 |
pb.redirectErrorStream(true); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
524 |
p = pb.start(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
525 |
is = p.getInputStream(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
526 |
ir = new InputStreamReader(is); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
527 |
rd = new BufferedReader(ir, 8192); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
528 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
529 |
String in = rd.readLine(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
530 |
while (in != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
531 |
alist.add(in); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
532 |
System.out.println(in); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
533 |
in = rd.readLine(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
534 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
535 |
retval = p.waitFor(); |
50603 | 536 |
if (!ignoreReturnValue && retval != 0) { |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
537 |
throw new RuntimeException("process failed with non-zero exit"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
538 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
539 |
} catch (Exception ex) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
540 |
throw new RuntimeException(ex.getMessage()); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
541 |
} finally { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
542 |
close(rd); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
543 |
close(ir); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
544 |
close(is); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
545 |
if (p != null) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
546 |
p.destroy(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
547 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
548 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
549 |
return alist; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
550 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
551 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
552 |
static String getUnpack200Cmd() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
553 |
return getAjavaCmd("unpack200"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
554 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
555 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
556 |
static String getPack200Cmd() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
557 |
return getAjavaCmd("pack200"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
558 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
559 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
560 |
static String getJavaCmd() { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
561 |
return getAjavaCmd("java"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
562 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
563 |
|
27565 | 564 |
static String getJavacCmd() { |
565 |
return getAjavaCmd("javac"); |
|
566 |
} |
|
567 |
||
568 |
static String getJarCmd() { |
|
569 |
return getAjavaCmd("jar"); |
|
570 |
} |
|
571 |
||
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
572 |
static String getAjavaCmd(String cmdStr) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
573 |
File binDir = new File(JavaHome, "bin"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
574 |
File unpack200File = IsWindows |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
575 |
? new File(binDir, cmdStr + ".exe") |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
576 |
: new File(binDir, cmdStr); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
577 |
|
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
578 |
String cmd = unpack200File.getAbsolutePath(); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
579 |
if (!unpack200File.canExecute()) { |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
580 |
throw new RuntimeException("please check" + |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
581 |
cmd + " exists and is executable"); |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
582 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
583 |
return cmd; |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
584 |
} |
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
585 |
|
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
586 |
// used to get all classes |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
587 |
static File createRtJar() throws Exception { |
27565 | 588 |
File rtJar = new File("rt.jar"); |
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
589 |
new JrtToZip(".*\\.class", rtJar).run(); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
590 |
return rtJar; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
591 |
} |
27565 | 592 |
|
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
593 |
// used to select the contents |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
594 |
static File createRtJar(String pattern) throws Exception { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
595 |
File rtJar = new File("rt.jar"); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
596 |
new JrtToZip(pattern, rtJar).run(); |
27565 | 597 |
return rtJar; |
598 |
} |
|
36948
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
599 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
600 |
/* |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
601 |
* A helper class to create a pseudo rt.jar. |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
602 |
*/ |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
603 |
static class JrtToZip { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
604 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
605 |
final File outFile; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
606 |
final Pattern pattern; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
607 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
608 |
public static void main(String[] args) throws Exception { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
609 |
new JrtToZip(args[0], new File(args[1])).run(); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
610 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
611 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
612 |
JrtToZip(String pattern, File outFile) throws Exception { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
613 |
this.pattern = Pattern.compile(pattern); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
614 |
this.outFile = outFile; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
615 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
616 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
617 |
void run() throws Exception { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
618 |
URI uri = URI.create("jar:" + outFile.toURI()); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
619 |
Map<String, String> env = new HashMap<>(); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
620 |
env.put("create", "true"); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
621 |
try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
622 |
toZipfs(zipfs); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
623 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
624 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
625 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
626 |
void toZipfs(FileSystem zipfs) throws Exception { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
627 |
FileSystem jrtfs = FileSystems.getFileSystem(URI.create("jrt:/")); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
628 |
for (Path root : jrtfs.getRootDirectories()) { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
629 |
Files.walkFileTree(root, new FileVisitor<Path>() { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
630 |
@Override |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
631 |
public FileVisitResult preVisitDirectory(Path dir, |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
632 |
BasicFileAttributes attrs) throws IOException { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
633 |
// ignore unneeded directory |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
634 |
if (dir.startsWith("/packages")) |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
635 |
return FileVisitResult.SKIP_SUBTREE; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
636 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
637 |
// pre-create required directories |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
638 |
Path zpath = zipfs.getPath(dir.toString()); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
639 |
Files.createDirectories(zpath); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
640 |
return FileVisitResult.CONTINUE; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
641 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
642 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
643 |
@Override |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
644 |
public FileVisitResult visitFile(Path file, |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
645 |
BasicFileAttributes attrs) throws IOException { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
646 |
Matcher matcher = pattern.matcher(file.toString()); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
647 |
if (matcher.matches()) { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
648 |
// System.out.println("x: " + file); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
649 |
Path zpath = zipfs.getPath(file.toString()); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
650 |
Files.copy(file, zpath, REPLACE_EXISTING); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
651 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
652 |
return FileVisitResult.CONTINUE; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
653 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
654 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
655 |
@Override |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
656 |
public FileVisitResult visitFileFailed(Path file, |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
657 |
IOException exc) throws IOException { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
658 |
return FileVisitResult.CONTINUE; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
659 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
660 |
|
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
661 |
@Override |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
662 |
public FileVisitResult postVisitDirectory(Path dir, |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
663 |
IOException exc) throws IOException { |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
664 |
return FileVisitResult.CONTINUE; |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
665 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
666 |
}); |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
667 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
668 |
} |
8727362c1c78
8152622: tools/pack200/Pack200Props.java timed out
ksrini
parents:
36511
diff
changeset
|
669 |
} |
6314
8ab691ddb904
6966737: (pack200) the pack200 regression tests need to be more robust.
ksrini
parents:
diff
changeset
|
670 |
} |