-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathCompileSubmodule.java
40 lines (35 loc) · 1.44 KB
/
CompileSubmodule.java
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
import java.io.*;
import java.net.*;
import java.nio.file.*;
import java.util.*;
import java.util.zip.*;
/** Compile submodule into Jar and JS
*/
public class CompileSubmodule {
public static void main(String[] a) throws Exception {
String dir = a[0];
if (isWindows()) {
runCommand(dir, "cmd", "/c", "ant", "dist");
runCommand(dir, "cmd", "/c", "ant", "gwtc");
} else {
runCommand(dir, "ant", "dist");
runCommand(dir, "ant", "gwtc");
}
replaceUserAgentCheck(dir);
}
public static void replaceUserAgentCheck(String dir) throws Exception {
Path peergosLib = Paths.get(dir + "/war/peergoslib/peergoslib.nocache.js");
String updated = Files.readString(peergosLib).replaceAll("var ua = navigator.userAgent.toLowerCase\\(\\);", "var ua = \"webkit\";");
Files.writeString(peergosLib, updated, StandardOpenOption.TRUNCATE_EXISTING);
}
public static int runCommand(String dir, String... command) throws Exception {
System.out.println(Arrays.asList(command));
ProcessBuilder pb = new ProcessBuilder(command).directory(new File(dir));
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
return pb.start().waitFor();
}
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().startsWith("windows");
}
}