Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/gc/GenClassesBuilder.java
41161 views
1
/*
2
* Copyright (c) 2017, 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.share.gc;
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
/**
38
* Uses {@link nsk.share.gc.Generator} to genearate {@code nsk.share.gc.newclass}
39
* classes and compile them to 'classes' directory.
40
*/
41
public class GenClassesBuilder {
42
public static void main(String[] args) {
43
Path srcDst = Paths.get(
44
"genSrc",
45
"nsk",
46
"share",
47
"gc",
48
"newclass").toAbsolutePath();
49
Path classesDir = Paths.get("classes").toAbsolutePath();
50
generateSource(srcDst);
51
compileSource(srcDst, classesDir);
52
}
53
54
private static void compileSource(Path srcDst, Path classesDir) {
55
JDKToolLauncher javac = JDKToolLauncher.create("javac")
56
.addToolArg("-d")
57
.addToolArg(classesDir.toString())
58
.addToolArg("-cp")
59
.addToolArg(Utils.TEST_CLASS_PATH);
60
try (Stream<Path> stream = Files.walk(srcDst)) {
61
stream.map(Path::toAbsolutePath)
62
.map(Path::toString)
63
.filter(s -> s.endsWith(".java"))
64
.forEach(javac::addToolArg);
65
} catch (IOException e) {
66
throw new Error("traverse source dir " + srcDst, e);
67
}
68
String[] command = javac.getCommand();
69
try {
70
ProcessTools.executeCommand(command)
71
.shouldHaveExitValue(0);
72
} catch (Error | RuntimeException e) {
73
throw e;
74
} catch (Throwable e) {
75
throw new Error("execution of javac(" + Arrays.toString(command) + ") failed", e);
76
}
77
}
78
79
private static void generateSource(Path dir) {
80
try {
81
Files.createDirectories(dir);
82
} catch (IOException e) {
83
throw new Error("can't create dirs for" + dir, e);
84
}
85
try {
86
Generator.main(new String[]{dir.toString()});
87
} catch (Exception e) {
88
throw new Error("can't generate classes", e);
89
}
90
}
91
}
92
93