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