forked from angryip/ipscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
282 lines (249 loc) · 10.1 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
apply plugin: 'java'
version = '3.6.1'
sourceCompatibility = 1.8
targetCompatibility = 1.8
def osName = System.getProperty("os.name")
def is64 = System.getProperty("os.arch").contains("64")
def platform = osName.contains("Linux") ? 'linux' + (is64 ? '64' : '') :
osName.contains("Windows") ? 'win' + (is64 ? '64' : '32') :
osName.contains("OS X") ? 'mac' : 'unknown'
buildscript {
ext.proguard_version = '6.0.3'
dependencies {
classpath "net.sf.proguard:proguard-gradle:$proguard_version"
}
repositories {
jcenter()
}
}
sourceSets {
main {
java { srcDirs "src", "ext/rocksaw/src", "ext/vserv-tcpip/src/java" }
resources { srcDirs "config", "src", "resources" }
}
test {
java { srcDir "test" }
resources { srcDir "test" }
}
}
repositories {
jcenter()
}
dependencies {
compile 'com.google.dagger:dagger:2.19'
annotationProcessor 'com.google.dagger:dagger-compiler:2.19'
compileOnly files("lib/swt-${platform}.jar")
compileOnly files('lib/jna.jar')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.23.0'
}
configurations {
testImplementation.extendsFrom compileOnly
}
compileJava.options.annotationProcessorGeneratedSourcesDirectory = new File('build/generated')
def packageTask(def platform, def moreJars, def moreLibs, 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': '.',
'Title': 'Angry IP Scanner',
'Version': version,
'Build-Date': java.time.LocalDate.now().toString(),
'URL': 'https://angryip.org/'
}
baseName = project.name + '-' + platform
from {
(configurations.compile + files("lib/swt-${platform}.jar") + files(moreJars))
.collect { it.isDirectory() ? it : zipTree(it) } +
moreLibs
}
exclude(
'version.txt',
'images/**/*.svg',
'chrome.manifest',
'swt.js',
'swt.xpt',
// GTK stuff
'libswt-awt-gtk-*.so',
'libswt-glx-gtk-*.so',
'libswt-mozilla-*.so',
'libswt-gnome-*.so',
'libswt-xpcominit-gtk-*.so',
'libswt-xulrunner-*.so',
'libswt-webkit-gtk-*.so',
// Win32 stuff
'swt-awt-*.dll',
'swt-wgl-*.dll',
'swt-gdip-*.dll',
'swt-xpcominit-*.dll',
'swt-xulrunner-*.dll',
'swt-webkit-*.dll',
// Mac stuff
'libswt-awt-*.jnilib',
'libswt-xulrunner-*.jnilib'
)
with jar
def rtJar = new File(System.getProperty('java.home') + "/jre/lib/rt.jar")
if (!rtJar.exists()) rtJar = new File('/usr/lib/jvm/java-10-openjdk-amd64/jmods/java.base.jmod') // try Ubuntu version of Java 10
if (!rtJar.exists()) rtJar = new File('/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar') // try Ubuntu version of Java 8 if current Java doesn't have rt.jar
if (!rtJar.exists()) rtJar = new File('/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/rt.jar') // try Ubuntu version of OpenJDK 8
if (rtJar.exists()) {
print "Using $rtJar for proguard minimization"
finalizedBy minimizeTask(rtJar, platform, doMore)
}
else {
println "WARNING: not minimizing, Java 8 is currently required for that"
doLast(doMore)
}
}
}
def minimizeTask(File rtJar, String platform, Closure doMore) {
return tasks.create("${platform}.min", proguard.gradle.ProGuardTask) {
injars "build/libs/ipscan-${platform}-${version}.jar"
outjars "build/libs/ipscan-${platform}-${version}.min.jar"
libraryjars rtJar.absolutePath
libraryjars 'lib/jna.jar'
dontobfuscate
dontoptimize
dontnote '**'
configuration 'lib/swt.pro'
configuration 'lib/jna.pro'
def keepClasses = [
'net.azib.ipscan.**',
'org.savarese.rocksaw.**',
]
for (keepClass in keepClasses) {
keep access: 'public', name: keepClass, {
method access: 'public'
}
}
doLast {
ant.move(file: "build/libs/ipscan-${platform}-${version}.min.jar", tofile: "build/libs/ipscan-${platform}-${version}.jar")
doMore()
}
}
}
def launch4j(def platform) {
ant.taskdef(name: 'launch4j', classname: 'net.sf.launch4j.ant.Launch4jTask', classpath: 'ext/launch4j/launch4j.jar:ext/launch4j/xstream.jar')
def configFile = "build/libs/launch4j-${platform}.xml"
ant.copy(file: "ext/launch4j/ipscan.xml", tofile: configFile)
ant.replace(file: configFile) {
ant.replacefilter(token: "BASENAME", value: "${project.name}-${platform}-${version}")
ant.replacefilter(token: "VERSION", value: version)
}
ant.launch4j(configFile: configFile)
ant.delete(file: configFile)
ant.delete(file: "${project.name}-${platform}-${version}.jar")
}
def deb(def platform, def arch) {
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.exec(executable: "chmod", dir: dist, failonerror: true) {
ant.arg(line: "a+x usr/bin/ipscan usr/lib/ipscan/${project.name}-${platform}-${version}.jar")
}
ant.exec(executable: 'fakeroot', dir: dist + '/..', failonerror: true) {
ant.arg(line: "dpkg-deb -b deb ${project.name}_${version}_${arch}.deb")
}
ant.delete(dir: dist)
}
def rpm(def platform, def arch) {
def dist = buildDir.path + '/libs/rpm'
ant.mkdir(dir: dist)
ant.copy(todir: dist) {
ant.fileset(dir: "ext/rpmbuild")
}
ant.replace(file: "${dist}/SPECS/ipscan.spec") {
ant.replacefilter(token: "VERSION", value: version)
}
ant.exec(executable: "rpmbuild", dir: dist, failonerror: true) {
ant.arg(line: "--target ${arch} --define \"_topdir ${new File(dist).absolutePath}\" --define \"platform ${platform}\" -bb SPECS/ipscan.spec")
}
ant.move(file: "${dist}/RPMS/${arch}/ipscan-${version}-1.${arch}.rpm", todir:'build/libs')
ant.delete(dir: dist)
}
packageTask('linux', [], 'ext/rocksaw/lib/linux/librocksaw.so') {
deb('linux', 'i386')
rpm('linux', 'i386')
}
packageTask('linux64', [], 'ext/rocksaw/lib/linux64/librocksaw.so') {
deb('linux64', 'amd64')
rpm('linux64', 'x86_64')
}
packageTask('win32', 'lib/jna-win32.jar', 'ext/rocksaw/lib/rocksaw.dll') {
launch4j('win32')
}
packageTask('win64', 'lib/jna-win64.jar', []) {
launch4j('win64')
}
packageTask('mac', [], []) {
def dist = buildDir.path + '/libs'
def name = 'Angry IP Scanner'
ant.copy(todir: dist) {
ant.fileset(dir: "ext/mac-bundle")
}
ant.copy(file: "${dist}/${project.name}-mac-${version}.jar", todir: "${dist}/${name}.app/Contents/MacOS")
ant.replace(file: "${dist}/${name}.app/Contents/Info.plist") {
ant.replacefilter(token: "APPNAME", value: name)
ant.replacefilter(token: "VERSION", value: version)
}
ant.zip(destfile: "${dist}/${project.name}-mac-${version}.zip") {
ant.zipfileset(dir: "${dist}/${name}.app", excludes: "Contents/MacOS/ipscan", prefix: "${name}.app")
// this one should be executable
ant.zipfileset(dir: "${dist}/${name}.app", includes: "Contents/MacOS/ipscan", prefix: "${name}.app", filemode: "755")
}
ant.delete(dir: "${dist}/${name}.app")
ant.delete(file: "${dist}/${project.name}-mac-${version}.jar")
}
task 'win-installer'(dependsOn: ['win32', 'win64']) {
doLast {
def installerDir = 'ext/win-installer'
ant.replace(file: "${installerDir}/InstallerConfig.nsh") {
ant.replacefilter(token: "VERSION_MINOR", value: "5")
ant.replacefilter(token: "VERSION", value: version)
}
ant.copy(file: "build/libs/${project.name}-win32-${version}.exe", tofile:"${installerDir}/AppFiles32/ipscan.exe")
ant.copy(file: "build/libs/${project.name}-win64-${version}.exe", tofile:"${installerDir}/AppFiles64/ipscan.exe")
if (platform.startsWith('linux')) {
ant.exec(dir: installerDir, executable: "wine", failOnError: true) {
ant.arg(value: "NSISPortable/App/NSIS/makensis.exe")
ant.arg(value: "Installer/Installer.nsi")
}
}
else {
ant.exec(dir: installerDir, executable: "NSISPortable/App/NSIS/makensis.exe", vmlauncher: false, failOnError: true) {
ant.arg(value: "Installer/Installer.nsi")
}
}
ant.move(file: "${installerDir}/ipscan-${version}-setup.exe", todir:"build/libs")
ant.exec(command: "git checkout ${installerDir}/InstallerConfig.nsh")
}
}
task all(dependsOn: ['clean', 'linux', 'linux64', 'mac', 'win-installer'])
task current(dependsOn: ['clean', platform])
task info {
doLast {
println "This script will build ${project.name} ${version}"
println "Targets (some may work only on Linux):"
println " all - runs tests and builds binaries for all OSs"
println " current - build for current platform ($platform)"
println " linux - builds only Linux 32-bit binary"
println " linux64 - builds only Linux 64-bit binary"
println " mac - builds only Mac binary"
println " win32 - builds only Windows binary"
println " win64 - builds only Windows 64-bit binary"
println " win-installer - packages a Windows installer (including both 32 and 64-bit binaries)"
}
}
defaultTasks 'info'