forked from tfg13/LanXchange
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
294 lines (241 loc) · 7.68 KB
/
build.gradle
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// define what is required to build the desktop release (swing)
def desktopProjects() {
[project('core'), project('cli'), project('swing')]
}
// common settings for desktop (swing) projects
configure(desktopProjects()) {
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
compileJava.options.encoding = "UTF-8"
}
configure([project('swing')]) {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
configure([project('cli')]) {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
// configure paths
def signPath = "/mnt/veracrypt1"
def buildPath = "/tmp/lxcbuild"
def jnaPath = "lib/swing/jna-4.2.1-win-stripped.jar"
///////////////////////////////////
//
// main tasks
//
///////////////////////////////////
// Builds the desktop (swing) release
task releaseDesktop() {
description "Builds the desktop release with the swing gui."
dependsOn "cleanBuildEnv"
dependsOn desktopProjects().build
dependsOn "prepareJar"
dependsOn "prepareJar2"
dependsOn "prepareJar3"
dependsOn "desktopJar"
dependsOn "packDesktop"
doLast {
copy {
from (buildPath + "/lxc.zip")
into ("releases/stable")
}
println "Done. Results in releases/stable. Unpack anywhere to install."
}
}
// Builds the desktop release and packs all files for the automatic update
task packUpdate(dependsOn: desktopProjects().build) {
description "Builds the desktop release and packs it as automatic update."
// Check versions, signing environment
dependsOn "prepareUpdate"
// interactive setup & checks complete, normal build
dependsOn "cleanBuildEnv"
dependsOn desktopProjects().build
dependsOn "prepareJar"
dependsOn "prepareJar2"
dependsOn "prepareJar3"
dependsOn "desktopJar"
dependsOn "packDesktop2"
dependsOn "signUpdate"
dependsOn "packSignedFiles"
// order
desktopProjects().build.each {
it.mustRunAfter ":prepareUpdate"
}
doLast {
// copy update master file
copy {
from signPath + "/update_master.zip"
into "update"
}
// done!
println("Done. Commit and push directory \"update\" to apply (do not forget aws!)")
}
}
///////////////////////////////////
//
// internal tasks
//
///////////////////////////////////
task cleanBuildEnv() {
deleteRecursive(buildPath)
}
task prepareJar(type: Copy) {
mustRunAfter desktopProjects().build
mustRunAfter "cleanBuildEnv"
def jna_file = file(jnaPath)
def outputDir = file("${buildDir}/unpacked/dist")
from zipTree(jna_file)
into buildPath + "/jar"
exclude "META-INF/*"
}
task prepareJar2(type: Copy) {
mustRunAfter "prepareJar"
from "lib/swing/lxcwin64.dll"
into buildPath + "/jar/win32-x86-64"
rename("lxcwin64.dll", "lxcwin.dll")
}
task prepareJar3(type: Copy) {
mustRunAfter "prepareJar2"
from "lib/swing/lxcwin32.dll"
into buildPath + "/jar/win32-x86"
rename("lxcwin32.dll", "lxcwin.dll")
}
// create main jar
task desktopJar(type: Zip) {
mustRunAfter "prepareJar3"
archiveName "lanxchange.jar"
destinationDir file(buildPath)
// create manifest on the fly
def manifest = project('swing').jar.manifest
manifest.attributes("Main-Class": "de.tobifleig.lxc.plaf.swing.Main")
manifest.writeTo(buildPath + "/jar/META-INF/MANIFEST.MF")
from buildPath + "/jar"
from "Ubuntu-R.ttf"
from "lxc_updates.pub"
from desktopProjects().sourceSets.main.output.classesDir
}
// pack desktop release
task packDesktop(type: Zip) {
mustRunAfter "desktopJar"
archiveName "lxc.zip"
destinationDir file(buildPath)
from (".")
include ("img/*.png")
include ("COPYING")
include ("3rd_party_licenses/font_license.txt")
include ("lxc")
include ("lxc.exe")
from (buildPath + "/lanxchange.jar")
include ("lanxchange.jar")
}
// pack desktop release
// alternative version that includes the version number file, required for updates
task packDesktop2(type: Zip) {
mustRunAfter "desktopJar"
archiveName "lxc.zip"
destinationDir file(buildPath)
from (".")
include ("img/*.png")
include ("COPYING")
include ("3rd_party_licenses/font_license.txt")
include ("lxc")
include ("lxc.exe")
from (buildPath + "/lanxchange.jar")
include ("lanxchange.jar")
from ("update/v")
include ("v")
}
// sign update
task signUpdate(type: JavaExec) {
mustRunAfter "packDesktop"
doFirst {
// prepare signing environment
deleteIfExists(signPath + "/lxc.zip")
deleteIfExists(signPath + "/update_master.zip")
deleteIfExists(signPath + "/lxc.sign")
// copy update into signing environment
copy {
from (buildPath + "/lxc.zip")
into (signPath)
}
}
// sign
main = "de.tobifleig.lxc.Signer"
workingDir = signPath
}
// zip signed update
task packSignedFiles(type: Zip) {
mustRunAfter "signUpdate"
archiveName "update_master.zip"
destinationDir file(signPath)
from signPath
include "lxc.zip"
include "lxc.sign"
}
// querys for version info and checks signing environment
task prepareUpdate() << {
// Cannot pack without signing environment!
def signDir = new File(signPath)
if (!signDir.isDirectory()) {
throw new InvalidUserDataException("Missing signing environment (" + signPath + ")")
}
// interactive mode required for this
if (System.console() == null) {
throw new InvalidUserDataException("This task requires an interactive console (run from terminal)")
}
// read update system metadata
def mainClassFile = new File("modules/core/src/main/java/de/tobifleig/lxc/LXC.java")
ext.newversion = -1
mainClassFile.eachLine { line ->
def matcher = line =~ "\\s*public static final int versionId = ([0-9]+);"
if (matcher) {
ext.newversion = matcher.group(1)
}
}
if (ext.newversion == -1) {
throw new InvalidUserDataException("Cannot read version number from modules/core/src/main/java/de/tobifleig/lxc/LXC.java")
}
def oldversion = -1
def oldversionstring = ""
new File("update/v").withReader { oldversion = it.readLine(); oldversionstring = it.readLine()}
if (oldversionstring == null || oldversion == -1 || oldversionstring.isEmpty()) {
throw new InvalidUserDataException("Cannot read old version information from update/v")
}
// check if version number was incremented
if (ext.newversion <= oldversion) {
throw new InvalidUserDataException("Version number (" + ext.newversion + ") must be greater than the current version (" + oldversion + ")!")
}
// prompt for new version text
println("Old description for version " + oldversion + " is: " + oldversionstring)
ext.newversionstring = System.console().readLine("Enter new description: ")
if (ext.newversionstring == null || ext.newversionstring.isEmpty()) {
throw new InvalidUserDataException("Description cannot be empty")
}
// write new version file
new File("update/v").withWriter { out ->
out.println(ext.newversion)
out.println(ext.newversionstring)
}
}
///////////////////////////////////
//
// helpers
//
///////////////////////////////////
void deleteIfExists(String path) {
def file = new File(path)
if (file.exists()) {
file.delete()
}
}
void deleteRecursive(String path) {
def file = file(path)
if (file.isDirectory()) {
file.list().each{ f ->
deleteRecursive(path + "/" + f)
}
}
assert !file.exists() || file.delete()
}