Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ConnectorsJarBuilder.java
40948 views
1
/*
2
* Copyright (c) 2018, 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
package nsk.jdi;
25
26
import jdk.test.lib.JDKToolLauncher;
27
import jdk.test.lib.Utils;
28
import jdk.test.lib.process.ProcessTools;
29
30
import java.io.IOException;
31
import java.nio.file.Files;
32
import java.nio.file.Path;
33
import java.nio.file.Paths;
34
import java.util.Arrays;
35
import java.util.stream.Stream;
36
37
public class ConnectorsJarBuilder {
38
public static void main(String[] args) {
39
Path src = Paths.get(Utils.TEST_SRC)
40
.resolve("connectors")
41
.toAbsolutePath();
42
if (Files.notExists(src)) {
43
throw new Error("connectors dir [" + src + "] doesn't exist");
44
}
45
Path classes = Paths.get("connectors","classes")
46
.toAbsolutePath();
47
try {
48
Files.createDirectories(classes);
49
} catch (IOException e) {
50
throw new Error("can't create dir " + classes, e);
51
}
52
compile(src, classes);
53
Path target = Paths.get("jars", "connectors.jar")
54
.toAbsolutePath();
55
buildJar(classes, target);
56
addMetaInf(src, target);
57
}
58
59
private static void compile(Path src, Path classes) {
60
JDKToolLauncher javac = JDKToolLauncher.create("javac")
61
.addToolArg("-d")
62
.addToolArg(classes.toString())
63
.addToolArg("-cp")
64
.addToolArg(Utils.TEST_CLASS_PATH);
65
try (Stream<Path> stream = Files.walk(src)) {
66
stream.map(Path::toAbsolutePath)
67
.map(Path::toString)
68
.filter(s -> s.endsWith(".java"))
69
.forEach(javac::addToolArg);
70
} catch (IOException e) {
71
throw new Error("traverse dir " + src, e);
72
}
73
74
executeTool(javac);
75
}
76
77
private static void buildJar(Path classes, Path target) {
78
try {
79
Files.createDirectories(target.getParent());
80
} catch (IOException e) {
81
throw new Error("can't create dir " + target.getParent(), e);
82
}
83
JDKToolLauncher jar = JDKToolLauncher.create("jar")
84
.addToolArg("cf")
85
.addToolArg(target.toString())
86
.addToolArg("-C")
87
.addToolArg(classes.toString())
88
.addToolArg(".");
89
executeTool(jar);
90
}
91
92
private static void addMetaInf(Path src, Path jarFile) {
93
Path metaInf = src.resolve("META-INF");
94
if (Files.exists(metaInf)) {
95
JDKToolLauncher jar = JDKToolLauncher.create("jar")
96
.addToolArg("uf")
97
.addToolArg(jarFile.toString())
98
.addToolArg("-C")
99
.addToolArg(src.toString())
100
.addToolArg("META-INF");
101
executeTool(jar);
102
}
103
}
104
105
private static void executeTool(JDKToolLauncher tool) {
106
String[] command = tool.getCommand();
107
try {
108
ProcessTools.executeCommand(command)
109
.shouldHaveExitValue(0);
110
} catch (Error | RuntimeException e) {
111
throw e;
112
} catch (Throwable e) {
113
throw new Error("execution of " + Arrays.toString(command) + " failed", e);
114
}
115
}
116
}
117
118