Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jps/LingeredAppForJps.java
41149 views
1
/*
2
* Copyright (c) 2016, 2020, 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
import java.io.BufferedWriter;
25
import java.io.File;
26
import java.io.FileWriter;
27
import java.io.IOException;
28
import java.util.ArrayList;
29
import java.util.List;
30
import jdk.test.lib.apps.LingeredApp;
31
32
public class LingeredAppForJps extends LingeredApp {
33
34
// if set, the app is run from jar file
35
private File jarFile;
36
37
@Override
38
protected void runAddAppName(List<String> cmd) {
39
if (jarFile != null) {
40
cmd.add("-Xdiag");
41
cmd.add("-jar");
42
cmd.add(jarFile.getAbsolutePath());
43
} else {
44
super.runAddAppName(cmd);
45
}
46
}
47
48
/**
49
* The jps output should contain processes' names
50
* (except when jps is started in quite mode).
51
* The expected name of the test process is prepared here.
52
*/
53
public String getProcessName() {
54
return jarFile == null
55
? getClass().getSimpleName()
56
: jarFile.getName();
57
}
58
59
// full package name for the application's main class or the full path
60
// name to the application's JAR file:
61
public String getFullProcessName() {
62
return jarFile == null
63
? getClass().getCanonicalName()
64
: jarFile.getAbsolutePath();
65
}
66
67
public void buildJar() throws IOException {
68
String className = LingeredAppForJps.class.getName();
69
File jar = new File(className + ".jar");
70
String testClassPath = System.getProperty("test.class.path", "?");
71
72
// Classpath contains test class dir, libraries class dir(s), and
73
// may contains some additional dirs.
74
// We need to add to jar only classes from the test class directory.
75
// Main class (this class) should only be found in one directory
76
// from the classpath (test class dir), therefore only added once.
77
// Libraries class dir(s) and any additional classpath directories
78
// are written the jar manifest.
79
80
File manifestFile = new File(className + ".mf");
81
String nl = System.getProperty("line.separator");
82
String manifestClasspath = "";
83
84
List<String> jarArgs = new ArrayList<>();
85
jarArgs.add("-cfm");
86
jarArgs.add(jar.getAbsolutePath());
87
jarArgs.add(manifestFile.getAbsolutePath());
88
for (String path : testClassPath.split(File.pathSeparator)) {
89
String classFullName = path + File.separator + className + ".class";
90
File f = new File(classFullName);
91
if (f.exists()) {
92
jarArgs.add("-C");
93
jarArgs.add(path);
94
jarArgs.add(".");
95
System.out.println("INFO: scheduled to jar " + path);
96
} else {
97
manifestClasspath += " " + new File(path).toURI();
98
}
99
}
100
try (BufferedWriter output = new BufferedWriter(new FileWriter(manifestFile))) {
101
output.write("Main-Class: " + className + nl);
102
if (!manifestClasspath.isEmpty()) {
103
output.write("Class-Path: " + manifestClasspath + nl);
104
}
105
}
106
107
System.out.println("Running jar " + jarArgs.toString());
108
sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
109
if (!jarTool.run(jarArgs.toArray(new String[jarArgs.size()]))) {
110
throw new IOException("jar failed: args=" + jarArgs.toString());
111
}
112
113
manifestFile.delete();
114
jar.deleteOnExit();
115
116
// Print content of jar file
117
System.out.println("Content of jar file" + jar.getAbsolutePath());
118
119
jarArgs = new ArrayList<>();
120
jarArgs.add("-tvf");
121
jarArgs.add(jar.getAbsolutePath());
122
123
jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
124
if (!jarTool.run(jarArgs.toArray(new String[jarArgs.size()]))) {
125
throw new IOException("jar failed: args=" + jarArgs.toString());
126
}
127
128
jarFile = jar;
129
}
130
131
public static void main(String args[]) {
132
LingeredApp.main(args);
133
}
134
}
135
136