Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/shared/BuildJar.java
41161 views
1
/*
2
* Copyright (c) 2017, 2019, 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 vm.runtime.defmeth.shared;
25
26
import jdk.test.lib.JDKToolLauncher;
27
import jdk.test.lib.Utils;
28
import jdk.test.lib.process.ProcessTools;
29
import jdk.test.lib.util.JarUtils;
30
31
import java.io.File;
32
import java.nio.file.Files;
33
import java.nio.file.Path;
34
import java.nio.file.Paths;
35
import java.util.Arrays;
36
37
/**
38
* Build {@code retransform.jar} in current directory using
39
* {@code vm/runtime/defmeth/shared/retransform.mf} and classes from
40
* {@code vm.runtime.defmeth.shared} package.
41
*/
42
public class BuildJar {
43
public static void main(String[] args) {
44
Path manifest = Paths.get(Utils.TEST_ROOT)
45
.resolve("vmTestbase")
46
.resolve("vm")
47
.resolve("runtime")
48
.resolve("defmeth")
49
.resolve("shared")
50
.resolve("retransform.mf")
51
.toAbsolutePath();
52
if (Files.notExists(manifest)) {
53
throw new Error("can't find manifest file: " + manifest);
54
}
55
56
Path file = foundInClassPath(Util.Transformer.class).toAbsolutePath();
57
// Util$Transformer.class is in vm/runtime/defmeth/shared
58
Path dir = file.getParent()
59
.getParent()
60
.getParent()
61
.getParent()
62
.getParent()
63
.toAbsolutePath();
64
65
JDKToolLauncher jar = JDKToolLauncher.create("jar")
66
.addToolArg("cmf")
67
.addToolArg(manifest.toString())
68
.addToolArg("retransform.jar")
69
.addToolArg("-C")
70
.addToolArg(dir.toString())
71
.addToolArg(dir.relativize(file).toString());
72
String[] command = jar.getCommand();
73
try {
74
ProcessTools.executeCommand(command)
75
.shouldHaveExitValue(0);
76
} catch (Error | RuntimeException e) {
77
throw e;
78
} catch (Throwable e) {
79
throw new Error("execution of jar [" + Arrays.toString(command) + "] failed", e);
80
}
81
}
82
83
private static Path foundInClassPath(Class<?> aClass) {
84
Path file = Paths.get(aClass.getName()
85
.replace(".", File.separator) + ".class");
86
for (String dir : Utils.TEST_CLASS_PATH.split(File.pathSeparator)) {
87
Path result = Paths.get(dir).resolve(file);
88
if (Files.exists(result)) {
89
return result;
90
}
91
}
92
throw new Error("can't find " + file + " in " + Utils.TEST_CLASS_PATH);
93
}
94
}
95
96
97