-
Notifications
You must be signed in to change notification settings - Fork 733
/
build.gradle
332 lines (291 loc) · 12.2 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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.guardsquare:proguard-gradle:7.3.0"
}
}
plugins {
id "java"
}
def osName = System.getProperty("os.name")
def is64 = System.getProperty("os.arch").contains("64")
def isArm = System.getProperty("os.arch").equals("aarch64")
def platform = osName.contains("Linux") ? 'linux' + (is64 ? '64' : '32') :
osName.contains("Windows") ? 'win' + (is64 ? '64' : '32') :
osName.contains("OS X") ? 'mac' + (isArm ? "Arm64" : "X86") : 'unknown'
String exec(def line, String dir = ".", boolean failOnError = true) {
def proc = Runtime.getRuntime().exec(line, null, project.file(dir))
if (proc.waitFor() == 0) return new String(proc.inputStream.readAllBytes()).trim()
else {
if (failOnError) throw new Exception(line + "\n" + new String(proc.errorStream.readAllBytes()))
else return null
}
}
version = exec("git describe --tags", ".", false) ?: "unknown"
sourceCompatibility = targetCompatibility = 11
def javaModules = ["java.base", "java.prefs", "java.logging", "jdk.crypto.ec"]
project.ext.set("javaModules", javaModules)
sourceSets {
main {
java { srcDirs "src" }
resources { srcDirs "config", "src", "resources" }
}
test {
java { srcDir "test" }
resources { srcDir "test" }
}
}
repositories {
mavenCentral()
}
configurations {
jna
any
linux64
win64.extendsFrom(jna)
macX86
macArm64
// compile and test with current platform's SWT and JNA
compileOnly.extendsFrom(getAt(platform), jna)
testImplementation.extendsFrom(compileOnly)
runtimeClasspath.extendsFrom(compileOnly)
all*.exclude module: 'org.eclipse.swt' // transitive dependency in Maven that fails
}
dependencies {
def swtVersion = '3.123.0'
linux64 "org.eclipse.platform:org.eclipse.swt.gtk.linux.x86_64:${swtVersion}"
win64 "org.eclipse.platform:org.eclipse.swt.win32.win32.x86_64:${swtVersion}"
macX86 "org.eclipse.platform:org.eclipse.swt.cocoa.macosx.x86_64:${swtVersion}"
macArm64 "org.eclipse.platform:org.eclipse.swt.cocoa.macosx.aarch64:${swtVersion}"
jna 'net.java.dev.jna:jna:5.9.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:2.23.0'
}
test {
if (platform.startsWith("mac")) {
// jvmArgs "-XstartOnFirstThread"
println("WARNING: tests that touch GUI will fail on Mac due to Cocoa restrictions and Gradle unable to run tests on main thread")
filter {
includeTestsMatching "net.azib.ipscan.core.net.*"
}
}
}
def packageTask(String platform, Closure doMore) {
return tasks.create(platform, Jar) {
dependsOn = ['classes']
manifest {
attributes 'Implementation-Title': 'Angry IP Scanner',
'Implementation-Version': version,
'Main-Class': 'net.azib.ipscan.Main',
'Class-Path': platform == "any" ? "/usr/share/java/swt4.jar /usr/lib/eclipse/swt.jar ./" : "./",
'Title': 'Angry IP Scanner',
'Version': version,
'Build-Date': java.time.LocalDate.now().toString(),
'URL': 'https://angryip.org/'
}
archiveBaseName.set(project.name + '-' + platform)
from {
configurations[platform].collect {
it.isDirectory() ? it : zipTree(it)
}
}
exclude(
'images/**/*.svg',
'META-INF/ECLIPSE*',
'about_files/*',
'version.txt',
'.api_description',
'about.html',
'fragment.properties',
'chrome.manifest',
// Linux/GTK
'libswt-awt-gtk-*.so',
'libswt-glx-gtk-*.so',
'libswt-webkit-gtk-*.so',
'webkitextensions*/*',
// Win32
'swt-awt-*.dll',
'swt-wgl-*.dll',
'swt-gdip-*.dll',
'swt-webkit-*.dll',
// Mac
'libswt-awt-*.jnilib',
// JNA
'com/sun/jna/*/*.a',
'com/sun/jna/*/*.so',
'com/sun/jna/*/*.jnilib',
"com/sun/jna/win32-${platform == 'win32' ? 'x86-64' : platform == 'win64' ? 'x86' : '*'}/*.dll",
// Win-specific stuff
!platform.startsWith('win') ? 'net/azib/ipscan/core/net/Win*' : '',
!platform.startsWith('win') ? 'net/azib/ipscan/fetchers/Win*' : ''
)
with jar
if (platform != "any")
finalizedBy minimizeTask(platform, doMore)
else
doLast(doMore)
}
}
def minimizeTask(String platform, Closure doMore) {
return tasks.create("${platform}.min", proguard.gradle.ProGuardTask) {
injars "build/libs/${project.name}-${platform}-${version}.jar"
outjars "build/libs/${project.name}-${platform}-${version}.min.jar"
(project.ext.javaModules + "java.desktop").each {
libraryjars System.getProperty('java.home') + "/jmods/${it}.jmod"
}
dontobfuscate
dontoptimize
dontnote '**'
configuration 'ext/swt.pro'
configuration 'ext/jna.pro'
def keepClasses = [
'net.azib.ipscan.**',
]
for (keepClass in keepClasses) {
keep access: 'public', name: keepClass, {
method access: 'public'
}
}
doLast {
ant.move(file: "build/libs/${project.name}-${platform}-${version}.min.jar", tofile: "build/libs/${project.name}-${platform}-${version}.jar")
doMore()
}
}
}
def winLauncher(def platform) {
ant.concat(destfile: "build/libs/${project.name}-${platform}-${version}.exe", binary: true) {
ant.fileset(file: "ext/win-launcher/launcher.exe")
ant.fileset(file: "build/libs/${project.name}-${platform}-${version}.jar")
}
ant.delete(file: "build/libs/${project.name}-${platform}-${version}.jar")
}
def deb(def platform, def arch, def moreDeps = '') {
def dist = buildDir.path + "/libs/deb"
ant.mkdir(dir: dist)
ant.copy(todir: dist) {
ant.fileset(dir: "ext/deb-bundle")
}
ant.copy(file: "build/libs/${project.name}-${platform}-${version}.jar", todir: "${dist}/usr/lib/ipscan")
ant.copy(file: "resources/images/icon128.png", tofile: "${dist}/usr/share/pixmaps/ipscan.png")
ant.replace(file: "${dist}/DEBIAN/control") {
ant.replacefilter(token: "VERSION", value: version)
ant.replacefilter(token: "ARCH", value: arch)
ant.replacefilter(token: "DEPENDS ", value: moreDeps)
}
exec("chmod +x usr/bin/ipscan usr/lib/ipscan/${project.name}-${platform}-${version}.jar", dist)
exec("fakeroot dpkg-deb -Zxz -b deb ${project.name}_${version}_${arch}.deb", "$dist/..")
ant.delete(dir: dist)
}
def rpm(def platform, def arch) {
def dist = buildDir.path + '/libs/rpm'
def rpmVersion = version.replace('-', '.')
ant.mkdir(dir: dist)
ant.copy(todir: dist) {
ant.fileset(dir: "ext/rpmbuild")
}
ant.replace(file: "${dist}/SPECS/ipscan.spec") {
ant.replacefilter(token: "RPM_VERSION", value: rpmVersion)
ant.replacefilter(token: "VERSION", value: version)
}
exec(new String[] {"sh", "-c", "rpmbuild --target ${arch} --define \"_topdir ${new File(dist).absolutePath}\" --define \"platform ${platform}\" -bb SPECS/ipscan.spec"}, dist)
ant.move(file: "${dist}/RPMS/${arch}/ipscan-${rpmVersion}-1.${arch}.rpm", todir:'build/libs')
ant.delete(dir: dist)
}
def macLauncher(def platform) {
def dist = buildDir.path + '/libs'
def name = 'Angry IP Scanner'
exec("cp -rp ext/mac-bundle/. $dist")
ant.copy(todir: dist) {
ant.fileset(dir: "ext/mac-bundle")
}
def target = "${dist}/${name}.app/Contents/MacOS"
ant.move(file: "${dist}/${project.name}-${platform}-${version}.jar", todir: target)
jlink(target, "jre")
ant.replace(file: "${dist}/${name}.app/Contents/Info.plist") {
ant.replacefilter(token: "APPNAME", value: name)
ant.replacefilter(token: "VERSION_NUM", value: version.replaceFirst('-.*', ''))
ant.replacefilter(token: "VERSION", value: version)
}
ant.delete(file: "${dist}/${name}.app/Contents/MacOS/jre/bin/keytool")
def zipName = "${dist}/${project.name}-${platform}-${version}.zip"
exec("zip -R $zipName * -x*.zip", dist)
if (System.getenv("APPLE_USER")) {
// TODO: codesign --sign Example --options runtime --entitlements test/test.entitlements --force build/Release/test.app
// TODO: https://developer.apple.com/documentation/xcode/notarizing_macos_software_before_distribution/customizing_the_notarization_workflow
println("Sending zip file to Apple for notarization")
exec("xcrun altool --list-providers --username ${System.getenv("APPLE_USER")} --password ${System.getenv("APPLE_PASSWORD")}", ".", false)
exec("xcrun altool --notarize-app --primary-bundle-id net.azib.ipscan.zip --username ${System.getenv("APPLE_USER")} --password ${System.getenv("APPLE_PASSWORD")} --file ${zipName}", ".", false)
}
ant.delete(dir: "${dist}/${name}.app")
}
packageTask('linux64') {
deb('linux64', 'amd64')
rpm('linux64', 'x86_64')
}
packageTask('any') {
deb('any', 'all', 'libswt-gtk-4-java, libswt-cairo-gtk-4-jni,')
}
packageTask('win64') {
winLauncher('win64')
}
packageTask('macX86') {
macLauncher("macX86")
}
packageTask('macArm64') {
macLauncher("macArm64")
}
def jlink(String target, String jrePath, String extraOpts = System.getenv("JLINK_OPTS") ?: "") {
def jreDir = new File(target, jrePath)
if (!jreDir.exists()) {
jreDir.getParentFile().mkdirs()
exec("jlink --output $jrePath $extraOpts --vm=client --compress=2 --no-header-files --no-man-pages --strip-debug --add-modules " + javaModules.join(","), target)
ant.delete(dir: new File(jreDir, "legal"))
}
}
task 'win-installer'(dependsOn: 'win64') {
doLast {
def nsisVersion = "3.08"
def nsis = "nsis-$nsisVersion"
def installerDir = 'ext/win-installer'
ant.get(src: "https://sourceforge.net/projects/nsis/files/NSIS%203/${nsisVersion}/${nsis}.zip/download", dest: "$installerDir/${nsis}.zip", skipexisting: 'true')
ant.unzip(src: "${installerDir}/${nsis}.zip", dest: installerDir)
ant.replace(file: "${installerDir}/InstallerConfig.nsh") {
ant.replacefilter(token: "VERSION_MINOR", value: "8")
ant.replacefilter(token: "VERSION", value: version)
}
jlink(installerDir, "AppFiles/jre")
ant.copy(file: "resources/images/icon.ico", todir: "${installerDir}/AppFiles")
ant.copy(file: "LICENSE", tofile: "${installerDir}/AppFiles/license.txt")
ant.copy(file: "build/libs/${project.name}-win64-${version}.exe", tofile:"${installerDir}/AppFiles/ipscan.exe")
if (platform.startsWith('win')) {
exec("cmd /c $nsis\\makensis.exe Installer\\Installer.nsi", installerDir)
}
else {
println("Building of Windows Installer is not supported on other platforms")
exec("wine $nsis/makensis.exe Installer/Installer.nsi", installerDir)
}
ant.move(file: "${installerDir}/ipscan-$version-setup.exe", todir: "build/libs")
exec("git checkout ${installerDir}/InstallerConfig.nsh")
}
}
task mac(dependsOn: ['macX86', 'macArm64'])
task linux(dependsOn: ['any', 'linux64'])
task current(dependsOn: [platform])
task info {
doLast {
println "This script will build ${project.name} ${version}"
println "Targets:"
println " current - build for current platform ($platform)"
println " linux - builds all Linux binaries"
println " linux64 - builds only Linux 64-bit binary"
println " any - doesn't bundle SWT, making it possible to run on ARM/Raspbian with libswt provided by OS (Experimental)"
println " mac - builds all Mac binaries"
println " macX86 - builds only MacX86 binary"
println " macArm64 - builds only MacArm64 binary"
println " win64 - builds only Windows 64-bit binary"
println " win-installer - packages a Windows installer (with included JRE)"
}
}
defaultTasks 'info'