-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
247 lines (216 loc) · 7.42 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
import org.gradle.internal.os.OperatingSystem;
allprojects {
version = '2.2.2'
group = 'org.corewall'
}
defaultTasks 'clean', 'build'
tasks.register('clean') {
doLast {
ant.delete(dir: file('dist'), failonerror: false)
ant.delete(dir: file('bin'), failonerror: false)
}
}
/* Names of directories containing Java 11 runtimes for use in packaging.
These directories should be located in the packages/java_runtime dir. */
def windows_javaRuntime = null
def macOS_javaRuntime = null
/**
* Packaging tasks. It may be good to just extend the gradle dist task instead of having a custom task.
*/
tasks.register('packageCheck') {
dependsOn ':app:build'
doLast {
def required = file("scenegraph/dist/scenegraph-${version}.jar")
if (!required.exists()) {
logger.error("!! Missing required scenegraph library or version mismatch. Expected: scenegraph/dist/scenegraph-${version}.jar")
logger.error("!! The library must be generated (or re-generated for this version), see scenegraph/README.md for instructions.")
throw new Error("Missing required scenegraph library or version mismatch. Expected: scenegraph/dist/scenegraph-${version}.jar")
}
if (!OperatingSystem.current().isLinux()) {
def javaRuntimeDir = file("packages/java_runtime")
if (!javaRuntimeDir.exists()) {
throw new Error("Error: Missing packages/java_runtime directory")
}
}
}
}
tasks.register('javaRuntimeCheckMac') {
dependsOn tasks.packageCheck
def javaRuntimeDir = file("packages/java_runtime")
if (macOS_javaRuntime == null) {
throw new Error("Error: macOS_javaRuntime var is null.\nTo resolve, update macOS_javaRuntime var with your macOS Java 11 runtime in build.gradle.")
}
if (javaRuntimeDir.listFiles().find { it.name.equals(macOS_javaRuntime) } == null) {
throw new Error("Error: Missing macOS Java 11 runtime '${macOS_javaRuntime}' dir in packages/java_runtime")
}
}
tasks.register('javaRuntimeCheckWin') {
dependsOn tasks.packageCheck
def javaRuntimeDir = file("packages/java_runtime")
if (windows_javaRuntime == null) {
throw new Error("Error: windows_javaRuntime var is null.\nTo resolve, update windows_javaRuntime var with your Windows Java 11 runtime in build.gradle.")
}
if (javaRuntimeDir.listFiles().find { it.name.equals(windows_javaRuntime) } == null) {
throw new Error("Error: Missing Windows Java 11 runtime '${windows_javaRuntime}' dir in packages/java_runtime")
}
}
tasks.register('createWorkingDir') {
def wrk_dir = file('working_dir')
if (!wrk_dir.exists()) {
mkdir(wrk_dir)
}
copy {
into wrk_dir
from 'packages/base'
}
}
// 'package' is a misnomer, this task just builds components and creates
// working_dir for command-line launch of Corelyzer.
tasks.register('packageLinux') {
dependsOn tasks.packageCheck
dependsOn tasks.createWorkingDir
}
// Package things up as a macOS/OSX .app bundle
tasks.register('packageMac') {
dependsOn tasks.javaRuntimeCheckMac
doLast {
def app = file('dist/mac/Corelyzer.app')
if (app.exists()) {
println "Found dist/mac/Corelyzer.app package, copying in latest app/dist, app/deps/mac, scenegraph/dist..."
// copy the jars and native libraries
copy {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
into 'dist/mac/Corelyzer.app/Contents/Resources/Java'
from 'app/dist'
from 'app/deps/mac'
from file('scenegraph/dist').listFiles().findAll { it.name.endsWith('.jar') || it.name.endsWith('.jnilib') }
}
} else {
println "No dist/mac/Corelyzer.app found, building from scratch..."
mkdir(app)
// copy the skeleton
copy {
into app
from 'packages/mac'
}
// copy the base resources and help files
copy {
into 'dist/mac/Corelyzer.app/Contents/Resources'
from 'packages/base/resources'
}
copy {
into 'dist/mac/Corelyzer.app/Contents/help'
from 'packages/base/help'
}
copy {
into 'dist/mac/Corelyzer.app/Contents/plugins'
from 'packages/base/plugins'
}
// copy the jars and native libraries
copy {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
into 'dist/mac/Corelyzer.app/Contents/Resources/Java'
from 'app/dist'
from 'app/deps/mac'
from file('scenegraph/dist').listFiles().findAll { it.name.endsWith('.jar') || it.name.endsWith('.jnilib') }
}
// copy Java runtime into bundle
copy {
from 'packages/java_runtime'
into 'dist/mac/Corelyzer.app/Contents/Frameworks'
include "${macOS_javaRuntime}/**"
}
// update our Info.plist
def classpath = file('dist/mac/Corelyzer.app/Contents/Resources/Java').listFiles().findAll { it.name.endsWith('.jar') }.collect { file ->
'\t\t\t<string>\\$JAVAROOT/' + file.name + '</string>'
}
def plist = file('dist/mac/Corelyzer.app/Contents/Info.plist')
def text = plist.text.toString()
text = text.replaceAll(':version', version) // add our version
text = text.replaceAll(':classpath', classpath.join('\n'))
text = text.replaceAll(':java_runtime', macOS_javaRuntime)
plist.write(text)
// make our app executable
ant.chmod(file:"dist/mac/Corelyzer.app/Contents/MacOS/Corelyzer", perm:"ugo+rx")
// codesign the app so Mac users are only pestered by the "Do you want Corelyzer
// to allow incoming network connections" dialog once...otherwise it appears
// at every launch.
exec {
println "Code signing app package"
workingDir 'dist/mac'
commandLine 'codesign', '--force', '--deep', '--sign', '-', 'Corelyzer.app'
standardOutput = new ByteArrayOutputStream()
println standardOutput.toString()
}
// tar and zip up app bundle
def tarfile = "Corelyzer-${version}.tar.gz"
println "Creating tarball ${tarfile}"
ant.exec(executable: 'tar', dir: 'dist/mac') {
arg(value: 'czvf')
arg(value: tarfile)
arg(value: 'Corelyzer.app')
}
}
}
}
// Windows packaging
def winDist = file("dist/win/Corelyzer")
def winLibs = file('dist/win/Corelyzer/lib')
tasks.register('packageWin') {
dependsOn tasks.javaRuntimeCheckWin
dependsOn tasks.createWinDist
doLast {
// copy the jars to Corelyzer/lib
copy {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
into winLibs
from 'app/dist'
from file('app/deps/win').listFiles().findAll { it.name.endsWith('.jar') }
from file('scenegraph/dist').listFiles().findAll { it.name.endsWith('.jar') }
}
// copy dlls to Corelyzer since I couldn't find a way to make Windows find them in lib
copy {
into winDist
from file('app/deps/win').listFiles().findAll { it.name.endsWith('.dll') }
from file('scenegraph/dist').listFiles().findAll { it.name.endsWith('.dll') }
}
// copy help and resources
copy {
into 'dist/win/Corelyzer/help'
from file('packages/base/help')
}
copy {
into 'dist/win/Corelyzer/resources'
from file('packages/base/resources')
}
// copy plugins
copy {
into 'dist/win/Corelyzer/plugins'
from file('plugins').listFiles().findAll { it.name.endsWith('.jar') }
}
// copy Java runtime into bundle
copy {
from "packages/java_runtime/${windows_javaRuntime}"
into 'dist/win/Corelyzer/jre'
}
// create our zip file
ant.zip(basedir: file("dist/win"), destfile: file("dist/win/Corelyzer-${version}.zip"), includes: "Corelyzer/**")
}
}
tasks.register('createWinDist') {
doLast {
if (!winDist.exists()) {
mkdir(winDist)
mkdir(winLibs)
// copy the skeleton
copy {
into winDist
from file('packages/win').listFiles().find { it.name.equals('Corelyzer.exe') }
}
}
}
}
tasks.register('package') {
dependsOn tasks.packageMac
dependsOn tasks.packageWin
}