-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathGenMSI.java
More file actions
172 lines (157 loc) · 6.59 KB
/
Copy pathGenMSI.java
File metadata and controls
172 lines (157 loc) · 6.59 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package javaforce.utils;
import java.io.*;
import javaforce.*;
/** GenMSI : Generates Windows MSI file (wixtoolset)
*
* @author pquiring
*/
public class GenMSI {
private BuildTools tools;
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage:GenMSI build.xml");
System.exit(1);
}
try {
new GenMSI().run(args[0]);
} catch (Exception e) {
JFLog.log(e);
}
}
public void run(String buildfile) throws Exception {
tools = new BuildTools();
if (!tools.loadXML(buildfile)) throw new Exception("error loading " + buildfile);
String home = tools.getProperty("home");
String app = tools.getProperty("app");
String apptype = tools.getProperty("apptype");
String version = tools.getProperty("version");
String jre = tools.getProperty("jre");
if (jre.length() == 0) {
JFLog.log("Error:JRE property not set");
System.exit(1);
}
jre = jre.replaceAll("\\$\\{home\\}", home);
String msi = tools.getProperty("msi");
if (msi.length() == 0) msi = app;
String heat_home = tools.getProperty("heat_home");
if (heat_home.length() == 0) heat_home = "jre";
String candle_extra = tools.getProperty("candle_extra");
String light_extra = tools.getProperty("light_extra");
String ffmpeg_version = tools.getVersion("ffmpeg-version");
String ffmpeg_folder = home + "/ffmpeg-bin/" + ffmpeg_version;
String[] wixheats = tools.getProperty("wixheat").split(",");
String out = msi + "-" + version + "-win64.msi";
String pdb = msi + "-" + version + "-win64.wixpdb";
try {
{
//create wix object
String[] cmd = new String[] {"wix","build","-arch","x64","-ext","WixToolset.UI.wixext","-ext","WixToolset.Firewall.wixext","-ext","WixToolset.Util.wixext","-o","app.wixlib","wix64.xml"};
if (candle_extra.length() > 0) {
String[] extra = candle_extra.split(" ");
for(String x : extra) {
cmd = JF.copyOfInsert(cmd, cmd.length, x);
}
}
ShellProcess.Output output = ShellProcess.exec(cmd, true);
if (output == null) throw new Exception("error");
System.out.println(output.stdout);
if (output.errorLevel > 0) throw new Exception("error");
}
{
//create jre object
WixHeat.main(new String[] {jre, "jre.xml", "JRE", heat_home});
ShellProcess.Output output = ShellProcess.exec(new String[] {"wix","build","-arch","x64","-o","jre.wixlib","jre.xml"}, true);
if (output == null) throw new Exception("error");
System.out.println(output.stdout);
if (output.errorLevel > 0) throw new Exception("error");
}
{
//create ffmpeg object
WixHeat.main(new String[] {ffmpeg_folder, "ffmpeg.xml", "FFMPEG", "."});
ShellProcess.Output output = ShellProcess.exec(new String[] {"wix","build","-arch","x64","-o","ffmpeg.wixlib","ffmpeg.xml"}, true);
if (output == null) throw new Exception("error");
System.out.println(output.stdout);
if (output.errorLevel > 0) throw new Exception("error");
}
{
//create msvcrt object
WixHeat.main(new String[] {home + "/jre_base/bin", "msvcrt.xml", "MSVCRT", ".", "**/api*.dll", "**/msvc*.dll", "**/ucrtbase.dll", "**/vcruntime*.dll"});
ShellProcess.Output output = ShellProcess.exec(new String[] {"wix","build","-arch","x64","-o","msvcrt.wixlib","msvcrt.xml"}, true);
if (output == null) throw new Exception("error");
System.out.println(output.stdout);
if (output.errorLevel > 0) throw new Exception("error");
}
for(String wixheat : wixheats) {
//create custom object
if (wixheat.trim().length() == 0) continue;
WixHeat.main(new String[] {wixheat, wixheat + ".xml", wixheat, "."});
ShellProcess.Output output = ShellProcess.exec(new String[] {"wix","build","-arch","x64","-o",wixheat + ".wixlib",wixheat + ".xml"}, true);
if (output == null) throw new Exception("error");
System.out.println(output.stdout);
if (output.errorLevel > 0) throw new Exception("error");
}
{
//create msi file
//see https://wixtoolset.org/docs/fourthree/faqs/
//see https://wixtoolset.org/docs/tools/wixexe/
String[] cmd = new String[] {"wix","build","-arch","x64","-ext","WixToolset.UI.wixext","-ext","WixToolset.Firewall.wixext","-ext","WixToolset.Util.wixext","-culture","en-us"
,"-b",home,"-b",jre,"-b",jre + "/bin","-b",ffmpeg_folder,"-bv", "WixUILicenseRtf=" + home + "/license.rtf"
,"-o",out,"app.wixlib","jre.wixlib","ffmpeg.wixlib","msvcrt.wixlib"};
if (light_extra.length() > 0) {
String[] extra = light_extra.split(" ");
for(String x : extra) {
cmd = JF.copyOfInsert(cmd, cmd.length, x);
}
}
for(String wixheat : wixheats) {
if (wixheat.trim().length() == 0) continue;
cmd = JF.copyOfInsert(cmd, cmd.length, wixheat + ".wixlib");
cmd = JF.copyOfInsert(cmd, cmd.length, "-b");
cmd = JF.copyOfInsert(cmd, cmd.length, wixheat);
}
ShellProcess.Output output = ShellProcess.exec(cmd, true);
if (output == null) throw new Exception("error");
System.out.println(output.stdout);
if (output.errorLevel > 0) throw new Exception("error");
}
{
//cleanup
new File("app.wixlib").delete();
new File("jre.wixlib").delete();
new File("jre.xml").delete();
new File("ffmpeg.wixlib").delete();
new File("ffmpeg.xml").delete();
new File("msvcrt.wixlib").delete();
new File("msvcrt.xml").delete();
new File(pdb).delete();
if (new File(home + "/repo/windows/amd64/readme.txt").exists()) {
JF.sleep(500); //wix sometimes holds file causing move error during ant processing
if (!JF.moveFile(out, home + "/repo/windows/amd64/" + out)) throw new Exception("move failed");
}
}
System.out.println(out + " created!");
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public static String getArch() {
String arch = System.getenv("HOSTTYPE");
if (arch == null) {
arch = System.getProperty("os.arch");
if (arch == null) {
JFLog.log("Error:Unable to detect CPU from env:HOSTTYPE or property:os.arch");
}
}
//debian uses custom names
switch (arch) {
case "x86_64": return "amd64";
case "aarch64": return "arm64";
}
return arch;
}
public static String getArchExt() {
return getArch();
}
}