author | duke |
Wed, 05 Jul 2017 20:24:54 +0200 | |
changeset 29530 | bfd405c818db |
parent 14856 | 92a1bcf46888 |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
14504
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
1 |
/* |
14856 | 2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
14504
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
4 |
* |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
8 |
* |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
13 |
* accompanied this code). |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
14 |
* |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
18 |
* |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
21 |
* questions. |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
22 |
*/ |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
23 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
24 |
/* |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
25 |
* Portions Copyright (c) 2012 IBM Corporation |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
26 |
*/ |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
27 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
28 |
/* |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
29 |
* @test |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
30 |
* @bug 7201156 |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
31 |
* @summary jar tool fails to convert file separation characters for list and extract |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
32 |
* @author Sean Chou |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
33 |
*/ |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
34 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
35 |
import java.io.File; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
36 |
import java.io.FileOutputStream; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
37 |
import java.io.IOException; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
38 |
import java.io.PipedInputStream; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
39 |
import java.io.PipedOutputStream; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
40 |
import java.io.PrintStream; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
41 |
import java.util.ArrayList; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
42 |
import java.util.List; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
43 |
import java.util.jar.JarEntry; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
44 |
import java.util.jar.JarOutputStream; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
45 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
46 |
import sun.tools.jar.Main; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
47 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
48 |
public class JarBackSlash { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
49 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
50 |
// used construct an entry JarBackSlash/dir/file.txt |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
51 |
private static String JARBACKSLASH = "JarBackSlash"; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
52 |
private static String DIR = "dir"; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
53 |
private static String FILENAME = "file.txt"; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
54 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
55 |
private static File createJarFile() throws IOException { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
56 |
File jarFile = File.createTempFile("JarBackSlashTest", ".jar"); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
57 |
jarFile.deleteOnExit(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
58 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
59 |
try (JarOutputStream output = new JarOutputStream(new FileOutputStream(jarFile))) { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
60 |
JarEntry entry = new JarEntry(JARBACKSLASH + "/" + DIR + "/" + FILENAME); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
61 |
output.putNextEntry(entry); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
62 |
} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
63 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
64 |
return jarFile; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
65 |
} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
66 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
67 |
private static void testJarList(String jarFile) throws IOException { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
68 |
List<String> argList = new ArrayList<String>(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
69 |
argList.add("-tvf"); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
70 |
argList.add(jarFile); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
71 |
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
72 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
73 |
String jarArgs[] = new String[argList.size()]; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
74 |
jarArgs = argList.toArray(jarArgs); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
75 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
76 |
PipedOutputStream pipedOutput = new PipedOutputStream(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
77 |
PipedInputStream pipedInput = new PipedInputStream(pipedOutput); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
78 |
PrintStream out = new PrintStream(pipedOutput); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
79 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
80 |
Main jarTool = new Main(out, System.err, "jar"); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
81 |
if (!jarTool.run(jarArgs)) { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
82 |
fail("Could not list jar file."); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
83 |
} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
84 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
85 |
out.flush(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
86 |
check(pipedInput.available() > 0); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
87 |
} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
88 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
89 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
90 |
private static void testJarExtract(String jarFile) throws IOException { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
91 |
List<String> argList = new ArrayList<String>(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
92 |
argList.add("-xvf"); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
93 |
argList.add(jarFile); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
94 |
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
95 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
96 |
String jarArgs[] = new String[argList.size()]; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
97 |
jarArgs = argList.toArray(jarArgs); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
98 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
99 |
PipedOutputStream pipedOutput = new PipedOutputStream(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
100 |
PipedInputStream pipedInput = new PipedInputStream(pipedOutput); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
101 |
PrintStream out = new PrintStream(pipedOutput); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
102 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
103 |
Main jarTool = new Main(out, System.err, "jar"); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
104 |
if (!jarTool.run(jarArgs)) { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
105 |
fail("Could not list jar file."); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
106 |
} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
107 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
108 |
out.flush(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
109 |
check(pipedInput.available() > 0); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
110 |
} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
111 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
112 |
public static void realMain(String[] args) throws Throwable { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
113 |
File tmpJarFile = createJarFile(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
114 |
String tmpJarFilePath = tmpJarFile.getAbsolutePath(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
115 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
116 |
testJarList(tmpJarFilePath); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
117 |
testJarExtract(tmpJarFilePath); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
118 |
} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
119 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
120 |
|
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
121 |
//--------------------- Infrastructure --------------------------- |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
122 |
static volatile int passed = 0, failed = 0; |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
123 |
static void pass() {passed++;} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
124 |
static void fail() {failed++; Thread.dumpStack();} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
125 |
static void fail(String msg) {System.out.println(msg); fail();} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
126 |
static void unexpected(Throwable t) {failed++; t.printStackTrace();} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
127 |
static void check(boolean cond) {if (cond) pass(); else fail();} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
128 |
static void equal(Object x, Object y) { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
129 |
if (x == null ? y == null : x.equals(y)) pass(); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
130 |
else fail(x + " not equal to " + y);} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
131 |
public static void main(String[] args) throws Throwable { |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
132 |
try {realMain(args);} catch (Throwable t) {unexpected(t);} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
133 |
System.out.println("\nPassed = " + passed + " failed = " + failed); |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
134 |
if (failed > 0) throw new AssertionError("Some tests failed");} |
aee973f6b53a
7201156: jar tool fails to convert file separation characters for list and extract
zhouyx
parents:
diff
changeset
|
135 |
} |