Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/IndifiedClassesBuilder.java
41155 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 vm.mlvm.share;
25
26
import jdk.test.lib.Utils;
27
28
import java.io.File;
29
import java.io.IOException;
30
import java.nio.file.FileVisitResult;
31
import java.nio.file.Files;
32
import java.nio.file.Path;
33
import java.nio.file.Paths;
34
import java.nio.file.SimpleFileVisitor;
35
import java.nio.file.StandardCopyOption;
36
import java.nio.file.attribute.BasicFileAttributes;
37
import java.util.Arrays;
38
import java.util.stream.Stream;
39
40
public class IndifiedClassesBuilder {
41
public static void main(String... args) {
42
Path[] targets;
43
if (args.length != 0) {
44
targets = Arrays.stream(args)
45
.map(Paths::get)
46
.toArray(Path[]::new);
47
for (Path path : targets) {
48
if (Files.notExists(path)) {
49
throw new Error(path + " doesn't exist");
50
}
51
if (!Files.isDirectory(path)) {
52
throw new Error(path + " isn't a directory");
53
}
54
}
55
} else {
56
targets = Arrays.stream(Utils.TEST_CLASS_PATH.split(File.pathSeparator))
57
.map(Paths::get)
58
.toArray(Path[]::new);
59
}
60
for (Path path : targets) {
61
if (!Files.isDirectory(path)) {
62
continue;
63
}
64
try (Stream<Path> files = Files.walk(path)) {
65
files.filter(
66
p -> {
67
String s = p.getFileName().toString();
68
return s.startsWith("INDIFY_") && s.endsWith(".class");
69
})
70
.forEach( p -> IndifiedClassesBuilder.indify(p, path));
71
} catch (IOException e) {
72
throw new Error("can't traverse path " + path);
73
}
74
}
75
}
76
77
private static void indify(Path file, Path path) {
78
Path tmp = Paths.get("indify.tmp");
79
try {
80
Files.createDirectories(tmp);
81
} catch (IOException e) {
82
throw new Error("can't create dir " + tmp, e);
83
}
84
try {
85
vm.mlvm.tools.Indify.main(
86
"--all",
87
"--overwrite",
88
"--transitionalJSR292=no",
89
"--dest", tmp.toAbsolutePath().toString(),
90
file.toAbsolutePath().toString());
91
92
// workaround for "nested" classpaths
93
if (Files.exists(tmp.resolve(path.relativize(file)))) {
94
Files.copy(tmp.resolve(path.relativize(file)), file, StandardCopyOption.REPLACE_EXISTING);
95
}
96
97
delete(tmp);
98
} catch (IOException e) {
99
throw new Error("can't indify " + file, e);
100
}
101
}
102
103
private static void delete(Path dir) throws IOException {
104
Files.walkFileTree(dir, new SimpleFileVisitor<>() {
105
@Override
106
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
107
FileVisitResult result = super.visitFile(file, attrs);
108
Files.delete(file);
109
return result;
110
}
111
112
@Override
113
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
114
FileVisitResult result = super.postVisitDirectory(dir, exc);
115
Files.delete(dir);
116
return result;
117
}
118
});
119
}
120
}
121
122