-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathPackage.java
More file actions
105 lines (101 loc) · 2.87 KB
/
Copy pathPackage.java
File metadata and controls
105 lines (101 loc) · 2.87 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
98
99
100
101
102
103
104
105
package javaforce.utils;
import java.io.*;
import java.util.*;
import javaforce.*;
import javaforce.linux.*;
/** Package everything for current OS (WIP).
*
* @author pquiring
*/
public class Package {
public static void main(String[] args) {
if (JF.isWindows()) {
doWindows();
} else {
doLinux();
}
}
private static void doWindows() {
type = "msi";
String[] projects = new File("projects").list();
for(String project : projects) {
if (!new File("projects/" + project + "/wix64.xml").exists()) continue;
if (!execute("projects/" + project)) return;
}
}
private static void doLinux() {
Linux.detectDistro();
String distro = null;
String version = null;
switch (Linux.distro) {
case Debian: type = "deb"; distro = "debian"; version = Linux.getVersionCodeName(); break;
case Fedora: type = "rpm"; distro = "fedora"; version = Linux.getVersion(); break;
case Arch: type = "pac"; distro = "arch"; version = "latest"; break;
}
//clean repo (clean.sh)
if (!clean_repo(distro, version)) {
JFLog.log("clean repo failed");
return;
}
//clean .class files (force rebuild)
JF.deletePathEx(".", ".*\\.class$");
//package javaforce
if (!execute(".")) return;
//package utils
if (!execute("utils")) return;
//package projects
String[] projects = new File("projects").list();
for(String project : projects) {
if (!execute("projects/" + project)) return;
}
package_libs();
}
private static boolean clean_repo(String distro, String version) {
//detect cpu
String cpu = System.getenv("HOSTTYPE");
if (cpu == null) return false;
if (distro.equals("debian")) {
//debian uses alt names for cpu
switch (cpu) {
case "x86_64": cpu = "amd64"; break;
case "aarch64": cpu = "arm64"; break;
}
}
ProcessBuilder pb = new ProcessBuilder();
pb = pb.directory(new File("repo/" + distro + "/" + version + "/" + cpu));
pb = pb.redirectOutput(new File("output.log"));
ArrayList<String> cmd = new ArrayList<String>();
cmd.add("/usr/bin/bash");
cmd.add("clean.sh");
pb = pb.command(cmd);
try {
Process p = pb.start();
return p.waitFor() == 0;
} catch (Exception e) {
return false;
}
}
private static String type;
private static boolean execute(String folder) {
ProcessBuilder pb = new ProcessBuilder();
pb = pb.directory(new File(folder));
pb = pb.redirectOutput(new File("output.log"));
ArrayList<String> cmd = new ArrayList<String>();
if (JF.isWindows()) {
cmd.add("ant.bat");
} else {
cmd.add("ant");
}
cmd.add(type);
pb = pb.command(cmd);
try {
Process p = pb.start();
return p.waitFor() == 0;
} catch (Exception e) {
return false;
}
}
private static void package_libs() {
//TODO
}
}