Skip to content

Commit 9f3a07d

Browse files
committed
Move output files
1 parent eef4f08 commit 9f3a07d

File tree

3 files changed

+109
-66
lines changed

3 files changed

+109
-66
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ bin/
2424

2525
fuzzed/
2626
compiled/
27-
decompiled/
27+
decompiled/
28+
output/

Diff for: src/main/java/org/quiltmc/javacodegen/CompilingCreator.java

+107-63
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,116 @@
44
import org.quiltmc.javacodegen.vars.VarsEntry;
55

66
import java.io.BufferedReader;
7-
import java.io.File;
7+
import java.io.IOException;
88
import java.io.InputStreamReader;
99
import java.nio.file.Files;
10+
import java.nio.file.Path;
1011
import java.nio.file.Paths;
1112

1213
public final class CompilingCreator {
13-
private static final String QF_JAR = System.getProperty("QF_JAR", null);
14-
public static void main(String[] args) throws Exception {
15-
int count = 500;
16-
17-
for (int i = 0; i < count; i++) {
18-
VarsEntry.resetId();
19-
20-
Statement statement = (new Creator()).createScope(
21-
false,
22-
true,
23-
new Context(),
24-
new Creator.Params(8),
25-
new VarsEntry()
26-
);
27-
28-
Paths.get(".", "fuzzed").toFile().mkdirs();
29-
Paths.get(".", "compiled", "recompiled").toFile().mkdirs();
30-
Paths.get(".", "decompiled").toFile().mkdirs();
31-
32-
StringBuilder stringBuilder = new StringBuilder();
33-
stringBuilder.append("import java.util.Random;\n");
34-
35-
stringBuilder.append("class FuzzedClass_").append(i).append(" {\n");
36-
stringBuilder.append("public void test()").append(" {\n");
37-
statement.javaLike(stringBuilder, "");
38-
stringBuilder.append("}\n");
39-
stringBuilder.append("}\n");
40-
41-
Files.write(Paths.get(".", "fuzzed", "FuzzedClass_" + i + ".java"), stringBuilder.toString().getBytes());
42-
}
43-
44-
Process exec = Runtime.getRuntime().exec("javac -g " + Paths.get(".", "fuzzed").toAbsolutePath() + "\\*.java -d " + Paths.get(".", "compiled").toAbsolutePath());
45-
46-
BufferedReader serr = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
47-
48-
String s;
49-
50-
while ((s = serr.readLine()) != null) {
51-
System.out.println(s);
52-
}
53-
54-
if (QF_JAR != null) {
55-
56-
exec = Runtime.getRuntime()
57-
.exec("java -jar " + QF_JAR + " " + Paths.get(".", "compiled").toAbsolutePath() + " " + Paths.get(".", "decompiled").toAbsolutePath());
58-
59-
serr = new BufferedReader(new InputStreamReader(exec.getInputStream()));
60-
61-
while ((s = serr.readLine()) != null) {
62-
System.out.println(s);
63-
}
64-
65-
exec = Runtime.getRuntime()
66-
.exec("javac -g " + Paths.get(".", "decompiled").toAbsolutePath() + "\\*.java -d " + Paths.get(".", "compiled", "recompiled").toAbsolutePath());
67-
68-
serr = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
69-
70-
while ((s = serr.readLine()) != null) {
71-
System.out.println(s);
72-
}
73-
}
74-
}
14+
private static final String QF_JAR = System.getProperty("QF_JAR", null);
15+
16+
public static void main(String[] args) throws Exception {
17+
int count = 300;
18+
19+
Path path = deleteDirs();
20+
21+
final Path fuzzed = path.resolve("fuzzed");
22+
final Path compiled = path.resolve("compiled");
23+
final Path decompiled = path.resolve("decompiled");
24+
final Path recompiled = path.resolve("recompiled");
25+
26+
Files.createDirectories(fuzzed);
27+
Files.createDirectories(compiled);
28+
Files.createDirectories(decompiled);
29+
Files.createDirectories(recompiled);
30+
31+
for (int i = 0; i < count; i++) {
32+
VarsEntry.resetId();
33+
34+
Statement statement = (new Creator()).createScope(
35+
false,
36+
true,
37+
new Context(),
38+
new Creator.Params(10),
39+
new VarsEntry()
40+
);
41+
42+
StringBuilder stringBuilder = new StringBuilder();
43+
stringBuilder.append("import java.util.Random;\n");
44+
45+
stringBuilder.append("class FuzzedClass_").append(i).append(" {\n");
46+
stringBuilder.append("public void test()").append(" {\n");
47+
statement.javaLike(stringBuilder, "");
48+
stringBuilder.append("}\n");
49+
stringBuilder.append("}\n");
50+
51+
Files.write(fuzzed.resolve("FuzzedClass_" + i + ".java"), stringBuilder.toString().getBytes());
52+
}
53+
54+
Process exec = Runtime.getRuntime().exec(
55+
"javac -encoding utf-8 -g " + fuzzed.toAbsolutePath() + "\\*.java -d " + compiled.toAbsolutePath());
56+
57+
BufferedReader serr = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
58+
59+
String s;
60+
61+
while ((s = serr.readLine()) != null) {
62+
System.out.println(s);
63+
}
64+
65+
if (QF_JAR != null) {
66+
67+
exec = Runtime.getRuntime()
68+
.exec("java -jar " + QF_JAR + " " + compiled.toAbsolutePath() + " " + decompiled.toAbsolutePath());
69+
70+
serr = new BufferedReader(new InputStreamReader(exec.getInputStream()));
71+
72+
while ((s = serr.readLine()) != null) {
73+
if (s.startsWith("INFO:")) {
74+
System.out.println(s);
75+
} else {
76+
System.err.println(s);
77+
}
78+
}
79+
80+
exec = Runtime.getRuntime()
81+
.exec("javac -encoding utf-8 -g " + decompiled.toAbsolutePath() + "\\*.java -d " + recompiled.toAbsolutePath());
82+
83+
serr = new BufferedReader(new InputStreamReader(exec.getErrorStream()));
84+
85+
86+
while ((s = serr.readLine()) != null) {
87+
System.out.println(s);
88+
}
89+
}
90+
}
91+
92+
private static Path deleteDirs() throws IOException {
93+
final Path path = Paths.get(".").resolve("output");
94+
Files.createDirectories(path);
95+
removeSubFolder(path, "fuzzed");
96+
removeSubFolder(path, "compiled");
97+
removeSubFolder(path, "decompiled");
98+
removeSubFolder(path, "recompiled");
99+
return path;
100+
}
101+
102+
private static void removeSubFolder(Path path, String fuzzed) throws IOException {
103+
final Path subFolder = path.resolve(fuzzed);
104+
if(!Files.exists(subFolder)){
105+
return;
106+
}
107+
if(!Files.isDirectory(subFolder)){
108+
Files.delete(subFolder);
109+
return;
110+
}
111+
Files.list(subFolder).filter(Files::isRegularFile).forEach(path1 -> {
112+
try {
113+
Files.delete(path1);
114+
} catch (IOException e) {
115+
throw new RuntimeException(e);
116+
}
117+
});
118+
}
75119
}

Diff for: src/main/java/org/quiltmc/javacodegen/vars/VarsEntry.java

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.quiltmc.javacodegen.vars;
22

3-
import java.util.ArrayList;
43
import java.util.HashMap;
5-
import java.util.List;
64
import java.util.Map;
75

86
public final class VarsEntry {

0 commit comments

Comments
 (0)