-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathValhalla2Jakarta.java
More file actions
97 lines (83 loc) · 3.26 KB
/
Valhalla2Jakarta.java
File metadata and controls
97 lines (83 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.io.*;
import java.nio.file.*;
import java.util.stream.*;
public class Valhalla2Jakarta {
public static void main(String[] args) {
try {
updateValueClassInJavaFiles();
renameJvmConfig();
updatePomFiles();
updateInjectProcessorTest();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void updateValueClassInJavaFiles() throws IOException {
Path currentDir = Paths.get(".").toAbsolutePath().normalize();
try (Stream<Path> paths = Files.walk(currentDir)) {
paths
.filter(Files::isRegularFile)
.filter(p -> p.toString().endsWith(".java"))
.filter(p -> !p.getFileName().toString().equals("Valhalla2Jakarta.java"))
.forEach(
path -> {
try {
String content = new String(Files.readAllBytes(path), "UTF-8");
String updated = content.replace(" value class ", " /*value*/ class ");
if (!content.equals(updated)) {
Files.write(path, updated.getBytes("UTF-8"));
}
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
private static void renameJvmConfig() throws IOException {
Path jvmConfig = Paths.get(".mvn/jvm.config");
Path jvmConfigDisabled = Paths.get(".mvn/jvm.config.disabled");
if (Files.exists(jvmConfig)) {
Files.move(jvmConfig, jvmConfigDisabled, StandardCopyOption.REPLACE_EXISTING);
}
}
private static void updatePomFiles() throws IOException {
Path currentDir = Paths.get(".").toAbsolutePath().normalize();
try (Stream<Path> paths = Files.walk(currentDir)) {
paths
.filter(Files::isRegularFile)
.filter(p -> p.getFileName().toString().equals("pom.xml"))
.forEach(
path -> {
try {
String content = new String(Files.readAllBytes(path), "UTF-8");
String original = content;
content = content.replace("--enable-preview -Dnet.bytebuddy", "-Dnet.bytebuddy");
content = content.replace("<!-- VALHALLA-START -->", "<!-- VALHALLA-START ___");
content = content.replace("<!-- VALHALLA-END -->", "____ VALHALLA-END -->");
content =
content.replace(
"<additionalOptions>--enable-preview</additionalOptions> <!-- Valhalla -->",
"<!-- Javadoc-No-Preview -->");
if (!original.equals(content)) {
Files.write(path, content.getBytes("UTF-8"));
}
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
private static void updateInjectProcessorTest() throws IOException {
Path testFile =
Paths.get(
"./inject-generator/src/test/java/io/avaje/inject/generator/InjectProcessorTest.java");
if (!Files.exists(testFile)) {
return;
}
String content = new String(Files.readAllBytes(testFile), "UTF-8");
String updated = content.replace("@Disabled", "//@Disabled");
if (!content.equals(updated)) {
Files.write(testFile, updated.getBytes("UTF-8"));
}
}
}