50018
|
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.share;
|
|
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 ExtraClassesBuilder {
|
|
38 |
public static void main(String[] args) {
|
|
39 |
String[] javacOpts = Arrays.stream(args)
|
|
40 |
.takeWhile(s -> s.startsWith("-"))
|
|
41 |
.toArray(String[]::new);
|
|
42 |
|
|
43 |
Arrays.stream(args)
|
|
44 |
.dropWhile(s -> s.startsWith("-"))
|
|
45 |
.forEach(s -> ExtraClassesBuilder.compile(s, javacOpts));
|
|
46 |
}
|
|
47 |
|
|
48 |
private static void compile(String name, String[] args) {
|
|
49 |
Path src = Paths.get(Utils.TEST_SRC)
|
|
50 |
.resolve(name)
|
|
51 |
.toAbsolutePath();
|
|
52 |
if (Files.notExists(src)) {
|
|
53 |
throw new Error(src + " doesn't exist");
|
|
54 |
}
|
|
55 |
Path dst = Paths.get("bin")
|
|
56 |
.resolve(Paths.get(name).getFileName())
|
|
57 |
.toAbsolutePath();
|
|
58 |
try {
|
|
59 |
Files.createDirectories(dst);
|
|
60 |
} catch (IOException e) {
|
|
61 |
throw new Error("can't create dir " + dst, e);
|
|
62 |
}
|
|
63 |
JDKToolLauncher javac = JDKToolLauncher.create("javac")
|
|
64 |
.addToolArg("-d")
|
|
65 |
.addToolArg(dst.toString())
|
|
66 |
.addToolArg("-cp")
|
|
67 |
.addToolArg(Utils.TEST_CLASS_PATH);
|
|
68 |
|
|
69 |
for (String arg : args) {
|
|
70 |
javac.addToolArg(arg);
|
|
71 |
}
|
|
72 |
|
|
73 |
try (Stream<Path> stream = Files.walk(src)) {
|
|
74 |
stream.map(Path::toAbsolutePath)
|
|
75 |
.map(Path::toString)
|
|
76 |
.filter(s -> s.endsWith(".java"))
|
|
77 |
.forEach(javac::addToolArg);
|
|
78 |
} catch (IOException e) {
|
|
79 |
throw new Error("traverse dir " + src, e);
|
|
80 |
}
|
|
81 |
|
|
82 |
executeTool(javac);
|
|
83 |
}
|
|
84 |
|
|
85 |
private static void executeTool(JDKToolLauncher tool) {
|
|
86 |
String[] command = tool.getCommand();
|
|
87 |
try {
|
|
88 |
ProcessTools.executeCommand(command)
|
|
89 |
.shouldHaveExitValue(0);
|
|
90 |
} catch (Error | RuntimeException e) {
|
|
91 |
throw e;
|
|
92 |
} catch (Throwable e) {
|
|
93 |
throw new Error("execution of " + Arrays.toString(command) + " failed", e);
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|