-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
595 lines (517 loc) · 14.3 KB
/
build.gradle
File metadata and controls
595 lines (517 loc) · 14.3 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
plugins {
id 'java'
id 'application'
id('com.diffplug.spotless') version '8.1.0'
id('com.palantir.java-format-spotless') version '2.83.0'
id('com.palantir.java-format') version '2.83.0'
}
group = 'epox'
version = '2.6.0'
description = 'WebAOM - Web Anime-O-Matic (AniDB file identification and organization)'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
// Get the Java toolchain's installation directory for use in Exec tasks
def javaToolchainService = project.extensions.getByType(JavaToolchainService)
def javaLauncher = javaToolchainService.launcherFor {
languageVersion = JavaLanguageVersion.of(21)
}
def toolchainJavaHome = javaLauncher.map { it.metadata.installationPath.asFile }
application {
mainClass = 'epox.webaom.WebAOM'
}
tasks.named('run', JavaExec) {
jvmArgs '-Dwebaom.dev=true'
}
repositories {
mavenCentral()
}
// Dependency configurations for different JAR variants
configurations {
sqliteOnly
allDrivers
}
dependencies {
implementation 'com.formdev:flatlaf:3.7'
// SQLite is always included (embedded database)
runtimeOnly 'org.xerial:sqlite-jdbc:3.51.0.0'
sqliteOnly 'org.xerial:sqlite-jdbc:3.51.0.0'
// External database drivers (PostgreSQL, MySQL)
runtimeOnly 'org.postgresql:postgresql:42.7.8'
runtimeOnly 'com.mysql:mysql-connector-j:9.5.0'
allDrivers 'org.xerial:sqlite-jdbc:3.51.0.0'
allDrivers 'org.postgresql:postgresql:42.7.8'
allDrivers 'com.mysql:mysql-connector-j:9.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testImplementation 'org.mockito:mockito-core:5.12.0'
}
tasks.named('test', Test) {
useJUnitPlatform {
excludeTags 'ui', 'benchmark'
}
systemProperty 'java.awt.headless', 'true'
}
tasks.register('testUi', Test) {
group = 'verification'
description = 'Runs UI-tagged tests.'
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
useJUnitPlatform {
includeTags 'ui'
}
systemProperty 'java.awt.headless', 'true'
}
tasks.register('benchmark', Test) {
group = 'verification'
description = 'Runs hash algorithm benchmarks.'
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
useJUnitPlatform {
includeTags 'benchmark'
}
maxHeapSize = '512m'
}
tasks.register('generateVersionProperties') {
// Capture values during configuration time to avoid deprecated API usage
def versionString = project.version.toString()
def buildDate = new Date().format('yyyy-MM-dd')
def generatedVersionResourcesDir = layout.buildDirectory.dir('generated/resources/version')
outputs.file(generatedVersionResourcesDir.map { it.file('webaom-version.properties') })
doLast {
def propsFile = generatedVersionResourcesDir.get().file('webaom-version.properties').asFile
propsFile.parentFile.mkdirs()
def props = new Properties()
props['webaom.version'] = versionString
props['webaom.buildDate'] = buildDate
propsFile.withWriter { props.store(it, null) }
}
}
tasks.register('installGitHooks', Exec) {
group = 'help'
description = 'Installs local Git hook shims that run repository hooks'
onlyIf {
def isCi = System.getenv('CI')?.toBoolean() ?: false
def isWindows = System.getProperty('os.name').toLowerCase().contains('win')
!isCi && !isWindows
}
commandLine 'bash', 'scripts/install-hooks.sh'
}
tasks.configureEach {
if (name != 'installGitHooks') {
dependsOn(tasks.named('installGitHooks'))
}
}
sourceSets {
main {
resources.srcDir(layout.buildDirectory.dir('generated/resources/version'))
}
}
processResources.dependsOn generateVersionProperties
jar {
manifest {
attributes(
'Main-Class': 'epox.webaom.WebAOM',
'Implementation-Title': 'WebAOM',
'Implementation-Version': version,
'Created-By': 'epoximator',
'Specification-Title': 'WebAOM',
'Specification-Version': version,
'Specification-Vendor': 'epoximator'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// Lite JAR with SQLite only (smaller, for most users)
tasks.register('jarLite', Jar) {
dependsOn classes, generateVersionProperties
group = 'build'
description = 'Creates a lite JAR with SQLite database only'
archiveClassifier = 'lite'
manifest {
attributes(
'Main-Class': 'epox.webaom.WebAOM',
'Implementation-Title': 'WebAOM',
'Implementation-Version': version,
'Created-By': 'epoximator',
'Specification-Title': 'WebAOM',
'Specification-Version': version,
'Specification-Vendor': 'epoximator'
)
}
from sourceSets.main.output
from("${layout.buildDirectory.get()}/resources/main")
from {
sourceSets.main.runtimeClasspath
.findAll { dep ->
!dep.name.contains('postgresql') && !dep.name.contains('mysql-connector-j')
}
.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// Full JAR with all database drivers
tasks.register('jarFull', Jar) {
dependsOn classes, generateVersionProperties
group = 'build'
description = 'Creates a full JAR with all database drivers (SQLite, PostgreSQL, MySQL)'
archiveClassifier = 'full'
manifest {
attributes(
'Main-Class': 'epox.webaom.WebAOM',
'Implementation-Title': 'WebAOM',
'Implementation-Version': version,
'Created-By': 'epoximator',
'Specification-Title': 'WebAOM',
'Specification-Version': version,
'Specification-Vendor': 'epoximator'
)
}
from sourceSets.main.output
from("${layout.buildDirectory.get()}/resources/main")
from {
sourceSets.main.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.named('build') {
dependsOn jarLite, jarFull
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs.addAll([
'-Xlint:unchecked',
'-Xlint:deprecation'
])
}
spotless {
java {
}
}
// Native app packaging with jpackage (requires Java 21+)
def jpackageOutputDir = layout.buildDirectory.dir('installer')
def jlinkOutputDir = layout.buildDirectory.dir('jlink')
def appName = 'WebAOM'
def appDescription = 'AniDB file identification and organization tool'
def appVendor = 'epoximator'
def appCopyright = 'Copyright 2005-2010 epoximator'
def jpackageAppVersion = version.toString().replaceFirst(/-.*/, '')
def packagingResourceRootDir = file('packaging/jpackage')
def packagingOsKey = { String osName ->
def os = osName.toLowerCase()
if (os.contains('mac')) {
return 'macos'
}
if (os.contains('win')) {
return 'windows'
}
if (os.contains('linux')) {
return 'linux'
}
return 'common'
}
def packagingResourceDir = { String osName ->
def dir = new File(packagingResourceRootDir, packagingOsKey(osName))
return dir.exists() ? dir : null
}
def packagedAppImageDir = { File outputDir, String osName ->
osName.toLowerCase().contains('mac') ? new File(outputDir, "${appName}.app") : new File(outputDir, appName)
}
def copyWindowsLauncherManifest = { File outputDir ->
def manifestFile = file('packaging/jpackage/windows/WebAOM.exe.manifest')
def appImageDir = new File(outputDir, appName)
if (!manifestFile.exists() || !appImageDir.exists()) {
return
}
copy {
from manifestFile
into appImageDir
}
}
// Modules required by the application (Swing + networking + database drivers)
def requiredModules = [
'java.base',
'java.desktop',
'java.logging',
'java.naming',
'java.net.http',
'java.prefs',
'java.security.jgss',
'java.sql',
'java.xml',
'jdk.crypto.ec',
'jdk.unsupported'
].join(',')
tasks.register('jlink', Exec) {
dependsOn build
group = 'distribution'
description = 'Creates a minimal custom JRE using jlink'
def outputDir = jlinkOutputDir.get().asFile
def jlinkExe = new File(toolchainJavaHome.get(), 'bin/jlink')
commandLine jlinkExe.absolutePath,
'--add-modules', requiredModules,
'--strip-debug',
'--no-man-pages',
'--no-header-files',
'--compress', 'zip-9',
'--output', outputDir.absolutePath
doFirst {
delete outputDir
println "Creating minimal JRE with jlink..."
}
doLast {
println "Custom JRE created in: ${outputDir.absolutePath}"
}
}
tasks.register('jpackage', Exec) {
dependsOn jpackageAppImage
group = 'distribution'
description = 'Creates native application package for the current platform'
def os = System.getProperty('os.name').toLowerCase()
def packageType = os.contains('mac') ? 'dmg' :
os.contains('win') ? 'msi' :
os.contains('linux') ? 'deb' : 'app-image'
def outputDir = jpackageOutputDir.get().asFile
def jpackageExe = new File(toolchainJavaHome.get(), 'bin/jpackage')
def appImageDir = packagedAppImageDir(outputDir, os)
def args = [
jpackageExe.absolutePath,
'--app-image',
appImageDir.absolutePath,
'--name',
appName,
'--app-version',
jpackageAppVersion,
'--description',
appDescription,
'--vendor',
appVendor,
'--copyright',
appCopyright,
'--type',
packageType,
'--dest',
outputDir.absolutePath
]
def resourceDir = packagingResourceDir(os)
if (resourceDir != null) {
args.addAll([
'--resource-dir',
resourceDir.absolutePath
])
}
// Platform-specific options
if (os.contains('mac')) {
args.addAll([
'--mac-package-name',
appName,
'--mac-package-identifier',
'epox.webaom'
])
def macIcon = file('src/main/resources/webaom.icns')
if (macIcon.exists()) {
args.addAll([
'--icon',
macIcon.absolutePath
])
}
} else if (os.contains('win')) {
args.addAll([
'--win-menu',
'--win-shortcut',
'--win-dir-chooser'
])
def winIcon = file('src/main/resources/webaom.ico')
if (winIcon.exists()) {
args.addAll([
'--icon',
winIcon.absolutePath
])
}
} else if (os.contains('linux')) {
args.addAll([
'--linux-shortcut',
'--linux-menu-group',
'Utility'
])
def linuxIcon = file('src/main/resources/webaom.png')
if (linuxIcon.exists()) {
args.addAll([
'--icon',
linuxIcon.absolutePath
])
}
}
commandLine args
doFirst {
// Unmount any existing WebAOM volumes to prevent hdiutil conflicts
if (System.getProperty('os.name').toLowerCase().contains('mac')) {
try {
[
'hdiutil',
'detach',
'/Volumes/WebAOM',
'-force',
'-quiet'
].execute().waitFor()
} catch (Exception ignored) {}
}
if (!appImageDir.exists()) {
throw new GradleException("jpackage app-image not found at ${appImageDir}")
}
outputDir.mkdirs()
println "Creating ${packageType} package with minimal runtime..."
}
doLast {
println "Package created in: ${outputDir.absolutePath}"
}
}
tasks.register('jpackageAppImage', Exec) {
dependsOn jarLite, jlink
group = 'distribution'
description = 'Creates a portable app-image (no installer) for the current platform'
def outputDir = jpackageOutputDir.get().asFile
def jpackageExe = new File(toolchainJavaHome.get(), 'bin/jpackage')
def os = System.getProperty('os.name').toLowerCase()
def appImageDir = packagedAppImageDir(outputDir, os)
def args = [
jpackageExe.absolutePath,
'--input',
"${layout.buildDirectory.get()}/libs",
'--main-jar',
"webaom-${version}-lite.jar",
'--name',
appName,
'--app-version',
jpackageAppVersion,
'--description',
appDescription,
'--vendor',
appVendor,
'--copyright',
appCopyright,
'--type',
'app-image',
'--runtime-image',
jlinkOutputDir.get().asFile.absolutePath,
'--dest',
outputDir.absolutePath
]
def resourceDir = packagingResourceDir(os)
if (resourceDir != null) {
args.addAll([
'--resource-dir',
resourceDir.absolutePath
])
}
if (os.contains('mac')) {
def macIcon = file('src/main/resources/webaom.icns')
if (macIcon.exists()) {
args.addAll([
'--icon',
macIcon.absolutePath
])
}
} else if (os.contains('win')) {
def winIcon = file('src/main/resources/webaom.ico')
if (winIcon.exists()) {
args.addAll([
'--icon',
winIcon.absolutePath
])
}
} else if (os.contains('linux')) {
def linuxIcon = file('src/main/resources/webaom.png')
if (linuxIcon.exists()) {
args.addAll([
'--icon',
linuxIcon.absolutePath
])
}
}
commandLine args
doFirst {
delete appImageDir
outputDir.mkdirs()
println "Creating app-image with minimal runtime..."
}
doLast {
if (os.contains('win')) {
copyWindowsLauncherManifest(outputDir)
}
println "App image created in: ${outputDir.absolutePath}"
}
}
// AppImage packaging for Linux (universal Linux format)
tasks.register('appimage') {
dependsOn jpackageAppImage
group = 'distribution'
description = 'Creates an AppImage for Linux distribution'
onlyIf { System.getProperty('os.name').toLowerCase().contains('linux') }
def outputDir = jpackageOutputDir.get().asFile
def appDir = new File(outputDir, "${appName}.AppDir")
def appImageName = "${appName}-${version}-x86_64.AppImage"
doFirst {
println "Creating AppImage..."
// Clean previous AppDir
if (appDir.exists()) {
delete(appDir)
}
appDir.mkdirs()
// Copy jpackage app-image to AppDir
def jpackageApp = new File(outputDir, appName)
if (!jpackageApp.exists()) {
throw new GradleException("jpackage app-image not found at ${jpackageApp}")
}
copy {
from jpackageApp
into appDir
}
// Copy AppRun launcher
copy {
from 'src/main/resources/AppRun'
into appDir
}
file("${appDir}/AppRun").setExecutable(true)
// Copy .desktop file
copy {
from 'src/main/resources/WebAOM.desktop'
into appDir
filter { line ->
if (line == 'Terminal=false') {
return "Terminal=false\nX-AppImage-Version=${version}"
}
line
}
}
// Copy icon and create .DirIcon symlink
copy {
from 'src/main/resources/webaom.png'
into appDir
}
// Create .DirIcon symlink (required by AppImage)
ant.symlink(link: "${appDir}/.DirIcon", resource: 'webaom.png', overwrite: true)
}
doLast {
// Run appimagetool with update information for Gear Lever
// The update URL format is: gh-releases-zsync|owner|repo|tag|filename.zsync
// Using 'latest' for tag to always fetch the newest release
def updateInfo = "gh-releases-zsync|alysson-souza|webaom|latest|WebAOM-*-x86_64.AppImage.zsync"
def result = exec {
workingDir outputDir
environment 'ARCH', 'x86_64'
commandLine 'appimagetool', '-u', updateInfo, appDir.name, appImageName
ignoreExitValue = true
}
if (result.exitValue != 0) {
throw new GradleException("appimagetool failed with exit code ${result.exitValue}")
}
// Clean up AppDir
delete(appDir)
println "AppImage created: ${new File(outputDir, appImageName).absolutePath}"
}
}