-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.gradle
746 lines (658 loc) · 28 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
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
import com.bmuschko.gradle.docker.tasks.container.*
import com.bmuschko.gradle.docker.tasks.image.*
plugins {
// https://github.com/bmuschko/gradle-docker-plugin
id "com.bmuschko.docker-remote-api" version "9.4.0"
id "com.github.node-gradle.node" version "7.1.0"
id "com.diffplug.spotless" version "6.25.0"
id "com.graphql-java-generator.graphql-gradle-plugin3" version "2.8"
id "org.beryx.runtime" version "1.13.1"
id "com.netflix.nebula.rpm" version "11.10.1"
id "org.springframework.boot" version "3.4.0" apply false
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply plugin: 'project-report' // adds dependencyReport and htmlDependencyReport tasks
apply plugin: 'io.spring.dependency-management'
java {
sourceCompatibility = 17
targetCompatibility = 17
}
boolean isTestEnv = project.hasProperty("testEnv")
String jdbi3Version = "3.47.0"
String jupiterVersion = "5.11.4"
String keycloakVersion = "26.0.7"
String poiVersion = "5.3.0"
String powermockVersion = "2.0.9"
String simplejavamailVersion = "8.12.4"
String springShellVersion = "3.4.0"
String psqlPushDataPath = "/var/tmp"
String keycloakContainerPath = "/opt/keycloak"
String keycloakPushDataPath = "${keycloakContainerPath}/data"
String hostKeycloakPath = "${rootProject.projectDir}/keycloak"
// If defined, load alternatives for variables
if (!isTestEnv && file('localSettings.gradle').exists()) {
apply from: 'localSettings.gradle'
} else if (isTestEnv && file('localTestSettings.gradle').exists()) {
apply from: 'localTestSettings.gradle'
}
// Defaults for development variables
String DEV_DB = "devAnet"
String TEST_DB = "testAnet"
run.environment("DB_DRIVER", run.environment["DB_DRIVER"] ?: "postgresql")
run.environment("DB_VERSION", run.environment["DB_VERSION"] ?: "latest")
run.environment("ANET_DB_SERVER", run.environment["ANET_DB_SERVER"] ?: "localhost")
run.environment("ANET_DB_NAME", run.environment["ANET_DB_NAME"] ?: isTestEnv ? TEST_DB : DEV_DB)
run.environment("ANET_DB_USERNAME", run.environment["ANET_DB_USERNAME"] ?: isTestEnv ? "anetTestUser" : "anetDevUser")
run.environment("ANET_DB_PASSWORD", run.environment["ANET_DB_PASSWORD"] ?: isTestEnv ? "Test-P@ssw0rd" : "Dev-P@ssw0rd")
run.environment("ANET_DB_PORT", run.environment["ANET_DB_PORT"] ?: "5432")
run.environment("ANET_DB_EXPOSED_PORT", run.environment["ANET_DB_EXPOSED_PORT"] ?: isTestEnv ? "5433" : "5432")
run.environment("ANET_DB_DROP", run.environment["ANET_DB_DROP"] ?: isTestEnv ? "true" : "false")
run.environment("ANET_DB_MIGRATE", run.environment["ANET_DB_MIGRATE"] ?: "true")
run.environment("ANET_PORT", run.environment["ANET_PORT"] ?: isTestEnv ? "8180" : "8080")
run.environment("ANET_ADMIN_PORT", run.environment["ANET_ADMIN_PORT"] ?: isTestEnv ? "8181" : "8081")
run.environment("ANET_SMTP_DISABLE", run.environment["ANET_SMTP_DISABLE"] ?: isTestEnv ? "false" : "true")
run.environment("ANET_SMTP_SERVER", run.environment["ANET_SMTP_SERVER"] ?: "localhost")
run.environment("ANET_SMTP_USERNAME", run.environment["ANET_SMTP_USERNAME"] ?: "")
run.environment("ANET_SMTP_PASSWORD", run.environment["ANET_SMTP_PASSWORD"] ?: "")
run.environment("ANET_SMTP_PORT", run.environment["ANET_SMTP_PORT"] ?: isTestEnv ? 1125 : 1025)
run.environment("ANET_SMTP_STARTTLS", run.environment["ANET_SMTP_STARTTLS"] ?: "true")
run.environment("ANET_SMTP_SSLTRUST", run.environment["ANET_SMTP_SSLTRUST"] ?: run.environment["ANET_SMTP_SERVER"])
run.environment("ANET_SMTP_HTTP_PORT", run.environment["ANET_SMTP_HTTP_PORT"] ?: isTestEnv ? 1180 : 1080)
run.environment("ANET_DICTIONARY_NAME", run.environment["ANET_DICTIONARY_NAME"] ?: "anet-dictionary.yml")
run.environment("ANET_TEST_MODE", run.environment["ANET_TEST_MODE"] ?: isTestEnv ? "true" : "false")
String NON_DEFAULT_DB_PROFILE = run.environment["ANET_DB_NAME"] in [DEV_DB, TEST_DB] ? "" : "prod"
run.environment("SPRING_PROFILES_ACTIVE", run.environment["SPRING_PROFILES_ACTIVE"] ?: isTestEnv ? "test" : (NON_DEFAULT_DB_PROFILE ?: "dev"))
String adminOrgName = run.environment["ANET_ADMIN_ORG_NAME"] ?: "ANET Administrators"
String adminPosName = run.environment["ANET_ADMIN_POS_NAME"] ?: "ANET Administrator"
String adminFullName = run.environment["ANET_ADMIN_FULL_NAME"] ?: "DMIN, Arthur"
String adminDomainUsername = run.environment["ANET_ADMIN_DOMAIN_USERNAME"] ?: "arthur"
String dbContainerName = isTestEnv ? "anet-psql-test-server" : "anet-psql-server"
String fakeSmtpContainerName = isTestEnv ? "anet-fake-smtp-test-server" : "anet-fake-smtp-server"
String keycloakContainerName = "anet-keycloak-server"
// In this section you declare where to find the dependencies of your project
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
// Let Spring manage the Spring (Boot) dependencies
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
}
}
// In this section you declare the dependencies for your production and test code
dependencies {
// Supported database is PostgreSQL:
implementation 'org.postgresql:postgresql:42.7.4'
implementation 'org.liquibase:liquibase-core:4.30.0'
implementation "org.jdbi:jdbi3-postgres:${jdbi3Version}" // For the SqlObjectPlugin
implementation "org.jdbi:jdbi3-spring:${jdbi3Version}"
implementation 'com.google.guava:guava:33.4.0-jre' // Pick the non-Android version
// For caching domain users (used in every authenticated request)
implementation('org.ehcache:ehcache:3.10.8') {
capabilities {
requireCapability('org.ehcache:ehcache-jakarta')
}
}
implementation 'javax.cache:cache-api:1.1.1'
implementation 'commons-beanutils:commons-beanutils:1.9.4'
implementation "org.simplejavamail:simple-java-mail:${simplejavamailVersion}"
implementation 'org.eclipse.angus:jakarta.mail:2.0.3'
implementation 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:20240325.1'
implementation 'com.mikesamuel:json-sanitizer:1.2.3'
// Used for converting GraphQL request output to XML:
implementation 'com.github.javadev:underscore-lodash:1.26'
// For JSON schema validation, supports detailed error reporting
implementation 'com.networknt:json-schema-validator:1.5.4'
// used for writing Excel documents
implementation "org.apache.poi:poi:${poiVersion}"
implementation "org.apache.poi:poi-ooxml:${poiVersion}"
// For inferring MIME types of attachments
implementation 'org.apache.tika:tika-core:3.0.0'
// For parsing HTML to check for 'empty' input
implementation 'org.jsoup:jsoup:1.18.3'
// GraphQL dependencies
implementation 'com.graphql-java:graphql-java:21.5'
implementation 'com.graphql-java:java-dataloader:3.4.0'
// GraphQL/Spring integration
implementation 'io.leangen.graphql:graphql-spqr-spring-boot-starter:1.0.1'
// Spring dependencies
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-freemarker"
implementation "org.springframework.boot:spring-boot-starter-oauth2-client"
implementation "org.springframework.boot:spring-boot-starter-oauth2-resource-server"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.shell:spring-shell-starter:${springShellVersion}"
// The graphql-java-client-runtime module aggregates all dependencies for the generated code,
// including the plugin runtime
testImplementation 'com.graphql-java-generator:graphql-java-client-runtime:2.8'
testImplementation "org.springframework.boot:spring-boot-starter-test"
// We use some extended scalars in `generateClientCodeConf` below
testImplementation 'com.graphql-java:graphql-java-extended-scalars:21.0'
testImplementation 'org.assertj:assertj-core:3.26.3'
testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${jupiterVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}"
}
configurations.all {
// Exclude transitive dependency Apache Xalan (e.g. through poi-ooxml), so we use the TransformerFactoryImpl from the JVM
exclude module: 'xalan'
// Also exclude XML API's to avoid (Eclipse) warnings like
// "The package org.w3c.dom is accessible from more than one module: <unnamed>, java.xml"
exclude group: 'xml-apis'
// For Spring:
exclude module: 'commons-logging'
}
test {
useJUnitPlatform()
jacoco {
destinationFile = file("$buildDir/jacoco/test-${run.environment['DB_DRIVER']}.exec")
}
}
jacoco {
toolVersion = "0.8.12"
}
jacocoTestReport {
executionData.setFrom project.fileTree(dir: "$buildDir", include: "jacoco/test-*.exec")
reports {
xml.required = true
html.required = true
}
}
//Set project version to git tag
def proc = "git describe".execute(null, projectDir);
proc.waitFor();
project.version = proc.text.trim();
runtime {
options = ['--vm=server', '--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
modules = [
'java.sql',
'java.desktop',
'java.xml',
'java.logging',
'java.management',
'jdk.crypto.cryptoki',
'jdk.crypto.ec',
'jdk.unsupported',
'java.security.jgss',
'java.naming',
'java.transaction.xa',
'java.security.sasl',
'java.instrument',
'java.scripting',
'java.xml.crypto'
]
jpackage {
appVersion = project.version.replace("-",".") // rpmbuild doesn't like versions with dashes
}
}
processResources {
filesMatching('**/version.properties') {
filter {
it.replace('APP_VERSION_TOKEN', project.version)
}
}
}
processResources.outputs.upToDateWhen{ false }
def projectBranch = "git rev-parse --abbrev-ref HEAD".execute(null, projectDir);
projectBranch.waitFor();
projectBranch = projectBranch.text.trim();
project.group = "ncia"
application {
mainClass = "mil.dds.anet.AnetApplication"
applicationDefaultJvmArgs = ["-Djava.library.path=MY_APP_HOME/lib"]
}
String dbLoc = run.environment['ANET_DB_SERVER']
if (run.environment['ANET_DB_EXPOSED_PORT']) {
dbLoc = dbLoc + ":" + run.environment['ANET_DB_EXPOSED_PORT'].toString()
}
if (!run.environment['ANET_DB_USERNAME']) {
run.environment('ANET_DB_USERNAME', run.environment['USER'])
}
if (run.environment['DB_DRIVER'] == "sqlserver") {
run.environment("ANET_DB_DRIVER", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
run.environment("ANET_DB_URL", "jdbc:sqlserver://${dbLoc};databaseName=${run.environment['ANET_DB_NAME']}")
} else if (run.environment['DB_DRIVER'] == "postgresql") {
run.environment("ANET_DB_DRIVER", "org.postgresql.Driver")
run.environment("ANET_DB_URL", "jdbc:postgresql://${dbLoc}/${run.environment['ANET_DB_NAME']}")
} else {
throw new GradleException( "Unsupported DB_DRIVER value \'${run.environment['DB_DRIVER']}\'")
}
test.environment = run.environment
task checkConfig(type: JavaExec, dependsOn: 'compileJava') {
classpath = sourceSets.main.runtimeClasspath
environment(run.environment)
mainClass = application.mainClass
args = ["check"]
}
task buildClient(dependsOn: 'yarn', type: YarnTask) {
group = "build"
description = "Builds the client application."
inputs.file("client/yarn.lock").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir("client/src").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir("client/config").withPathSensitivity(PathSensitivity.RELATIVE)
inputs.dir("client/public").withPathSensitivity(PathSensitivity.RELATIVE)
outputs.dir("$buildDir/resources/main/assets/client")
outputs.cacheIf { true }
environment = [ "ANET_TEST_MODE": run.environment["ANET_TEST_MODE"] ]
args = ['run', 'build']
}
// Create the task that runs the initialization command. Run with:
// ./gradlew dbInit
// to use the defaults. You can override the defaults with environment variables:
// env ANET_ADMIN_ORG_NAME="ACME Administrators Inc." \
// ANET_ADMIN_POS_NAME="The ANET admin" \
// ANET_ADMIN_FULL_NAME="DOE, John" \
// ANET_ADMIN_DOMAIN_USERNAME="johndoe" \
// ./gradlew dbInit
// To see all options, run:
// ./gradlew dbInit -Pargs="--help"
// which will print the help.
task dbInit(type: JavaExec, dependsOn: 'compileJava') {
group = "database runtime"
description = "Runs the ANET database initialization command."
classpath = sourceSets.main.runtimeClasspath
environment(run.environment)
mainClass = application.mainClass
def cmdline = ["init"]
if (project.hasProperty("args")) {
cmdline.addAll(project.args.split("\\s+"))
} else {
cmdline.addAll([
"--adminOrgName", adminOrgName,
"--adminPosName", adminPosName,
"--adminFullName", adminFullName,
"--adminDomainUsername", adminDomainUsername
])
}
args cmdline
}
task dbDropLargeObjects(type: DockerExecContainer) {
group = "database runtime"
description = "Drop unreferenced large objects from the database"
containerId = dbContainerName
commands = [ ["vacuumlo", "-v", "-U", run.environment["ANET_DB_USERNAME"], run.environment["ANET_DB_NAME"]] as String[] ]
}
task pushPsqlImageData(type: DockerCopyFileToContainer) {
group = "database runtime"
description = "Push SQL base data to PostgreSQL"
containerId = dbContainerName
hostPath = "${projectDir}/src/test/resources/assets/"
remotePath = psqlPushDataPath
}
task dbLoad(type: JavaExec, dependsOn: pushPsqlImageData) {
group = "database runtime"
description = "Runs the ANET database load command for PostgreSQL; loads demo data."
classpath = sourceSets.main.runtimeClasspath
def dbLoadEnvironment = [*:run.environment]
dbLoadEnvironment["ANET_DB_DROP"] = "false"
dbLoadEnvironment["ANET_DB_MIGRATE"] = "false"
environment(dbLoadEnvironment)
mainClass = application.mainClass
args = ["dbScript", "-S", "insertBaseData-psql.sql"]
}
task deleteDbDump(type: DockerExecContainer) {
group = "database runtime"
description = "Deletes the database dump in the container"
containerId = dbContainerName
commands = [ ["rm", "-f", "${psqlPushDataPath}/${run.environment["ANET_DB_NAME"]}-db-dump.sql"] as String[] ]
}
task dbDump(type: DockerExecContainer, dependsOn: deleteDbDump) {
group = "database runtime"
description = "Dumps the ANET database in the container"
containerId = dbContainerName
commands = [ ["pg_dump", "-c", "-U", run.environment["ANET_DB_USERNAME"], "-d", run.environment["ANET_DB_NAME"], "-f", "${psqlPushDataPath}/${run.environment["ANET_DB_NAME"]}-db-dump.sql"] as String[] ]
}
task extractDbDump(type: DockerCopyFileFromContainer, dependsOn: dbDump) {
group = "database runtime"
description = "Extracts the dumped database from the container"
containerId = dbContainerName
hostPath = "${buildDir}/db/${run.environment["ANET_DB_NAME"]}-db-dump.sql"
remotePath = "${psqlPushDataPath}/${run.environment["ANET_DB_NAME"]}-db-dump.sql"
}
task pushDbDump(type: DockerCopyFileToContainer) {
group = "database runtime"
description = "Copies the database dump to the container"
containerId = dbContainerName
hostPath = "${buildDir}/db/${run.environment["ANET_DB_NAME"]}-db-dump.sql"
remotePath = psqlPushDataPath
}
task dbRestore(type: DockerExecContainer, dependsOn: pushDbDump) {
group = "database runtime"
description = "Restores the ANET database in the container"
containerId = dbContainerName
commands = [ ["psql", "-U", run.environment["ANET_DB_USERNAME"], "-d", run.environment["ANET_DB_NAME"], "-f", "${psqlPushDataPath}/${run.environment["ANET_DB_NAME"]}-db-dump.sql"] as String[] ]
}
dbRestore.finalizedBy('dbDropLargeObjects')
task dockerBuildImage(dependsOn: installDist, type: DockerBuildImage) {
description = "Builds anet-app-server container image."
doFirst {
copy {
from 'docker/anet-app-server/Dockerfile'
into 'build/install'
}
}
inputDir = project.file('build/install')
def resultTags = ["ncia/anet-app-server:${project.version}"]
if (projectBranch=="main")
resultTags << 'ncia/anet-app-server:latest'
images = resultTags
}
task dockerPushLatestImage(type: DockerPushImage) {
images = ['ncia/anet-app-server:latest']
}
task dockerPushImage(type: DockerPushImage) {
images = ["ncia/anet-app-server:${project.version}"]
}
// Database container (PostgreSQL)
task dockerPullDB(type: DockerPullImage) {
group = "database container"
image = "postgres:${run.environment['DB_VERSION']}"
description = "Pulls a docker image for the ANET DB from ${image}."
}
task dockerCreateDB(dependsOn: dockerPullDB, type: DockerCreateContainer) {
group = "database container"
imageId = dockerPullDB.getImage()
containerName = dbContainerName
description = "Creates an ANET SQL DB container named ${dbContainerName}."
hostConfig.shmSize = 1024*1024*1024L
hostConfig.binds = ["${projectDir}":"/hostdata"] + run.environment.get("DOCKER_MOUNTS", [:])
withEnvVar('POSTGRES_DB', run.environment["ANET_DB_NAME"])
withEnvVar('POSTGRES_USER', run.environment["ANET_DB_USERNAME"])
withEnvVar('POSTGRES_PASSWORD', run.environment["ANET_DB_PASSWORD"])
hostConfig.portBindings = ["${run.environment["ANET_DB_EXPOSED_PORT"]}:${run.environment["ANET_DB_PORT"]}"]
}
task dockerCreateAdditionalDB(dependsOn: dockerPullDB, type: DockerExecContainer) {
group = "database runtime"
description = "Create PostgreSQL database" + run.environment["ANET_DB_NAME"]
containerId = dbContainerName
commands = [["createdb", "-U", run.environment["ANET_DB_USERNAME"], run.environment["ANET_DB_NAME"]] as String[]]
}
// need to make this invoke dockerCreateDB if there is no ${dbContainerName} and possibly get newer image if available
task dockerStartDB(type: DockerStartContainer, dependsOn: pushPsqlImageData) {
group = "database container"
description = "Starts ${dbContainerName} container."
targetContainerId { dbContainerName }
}
dockerStartDB.mustRunAfter('dockerCreateDB')
task dockerStopDB(type: DockerStopContainer) {
group = "database container"
description = "Stops ${dbContainerName} container."
targetContainerId { dbContainerName }
}
task dockerRemoveDB(type: DockerRemoveContainer) {
group = "database container"
description = "Removes ${dbContainerName} container."
targetContainerId { dbContainerName }
}
dockerRemoveDB.mustRunAfter('dockerStopDB')
// Keycloak container
task dockerPullKeycloak(type: DockerPullImage) {
group = "keycloak container"
image = "quay.io/keycloak/keycloak:${keycloakVersion}"
description = "Pulls a docker image for keycloak from ${image}."
}
task dockerCreateKeycloak(dependsOn: dockerPullKeycloak, type: DockerCreateContainer) {
group = "keycloak container"
imageId = dockerPullKeycloak.getImage()
containerName = keycloakContainerName
description = "Creates a keycloak container named ${keycloakContainerName}."
hostConfig.portBindings = ["9080:8080", "9443:8443"]
hostConfig.binds = run.environment.get("DOCKER_MOUNTS", [:])
withEnvVar("KEYCLOAK_ADMIN", "admin")
withEnvVar("KEYCLOAK_ADMIN_PASSWORD", "admin")
cmd = ["start-dev", "--import-realm"]
}
task dockerConfigureKeycloak(dependsOn: dockerCreateKeycloak, type: DockerCopyFileToContainer) {
group = "keycloak container"
description = "Push REALM configuration to Keycloak"
containerId = keycloakContainerName
hostPath = "${rootProject.projectDir}/keycloak/import"
remotePath = keycloakPushDataPath
}
task dockerStartKeycloak(type: DockerStartContainer) {
group = "keycloak container"
description = "Starts ${keycloakContainerName} container."
containerId = keycloakContainerName
}
task dockerCopyKeycloakRealmH2DB(type: DockerExecContainer) {
group = "keycloak container"
description = "Copies ANET-Realm H2 DB inside ${keycloakContainerName} container."
containerId = keycloakContainerName
commands = [ ["/bin/cp", "-rp", "${keycloakContainerPath}/data/h2", "/tmp"] as String[] ]
}
task dockerExportKeycloakRealm(dependsOn: dockerCopyKeycloakRealmH2DB, type: DockerExecContainer) {
group = "keycloak container"
description = "Exports ANET-Realm from ${keycloakContainerName} container."
containerId = keycloakContainerName
commands = [ ["/bin/bash", "${keycloakContainerPath}/bin/kc.sh", "export", "--dir", "${keycloakPushDataPath}/export", "--users", "realm_file", "--db", "dev-file", "--db-url", "jdbc:h2:file:/tmp/h2/keycloakdb;NON_KEYWORDS=VALUE"] as String[] ]
}
task dockerGetKeycloakConfiguration(dependsOn: dockerExportKeycloakRealm, type: DockerCopyFileFromContainer) {
description = "Pull REALM configuration from Keycloak"
containerId = keycloakContainerName
hostPath = "${hostKeycloakPath}/import/ANET-realm.json"
remotePath = "${keycloakPushDataPath}/export/ANET-realm.json"
}
task dockerStopKeycloak(type: DockerStopContainer) {
group = "keycloak container"
description = "Stops ${keycloakContainerName} container."
containerId = keycloakContainerName
}
task dockerRemoveKeycloak(type: DockerRemoveContainer) {
group = "keycloak container"
description = "Removes ${keycloakContainerName} container."
containerId = keycloakContainerName
}
dockerRemoveKeycloak.mustRunAfter('dockerStopKeycloak')
// Fake SMTP server container
task dockerPullFakeSmtpServer(type: DockerPullImage) {
group = "fake-smtp-server container"
image = "devoto13/fake-smtp-server:0.1.0" // No 'latest' available yet
description = "Pulls a docker image for the fake-smtp-server from ${image}."
}
task dockerCreateFakeSmtpServer(dependsOn: dockerPullFakeSmtpServer, type: DockerCreateContainer) {
group = "fake-smtp-server container"
imageId = dockerPullFakeSmtpServer.getImage()
containerName = fakeSmtpContainerName
description = "Creates a fake-smtp-server container named ${fakeSmtpContainerName}."
exposePorts("tcp", [1025, 1080])
hostConfig.portBindings = ["${run.environment["ANET_SMTP_PORT"]}:1025", "${run.environment["ANET_SMTP_HTTP_PORT"]}:1080"]
}
task dockerStartFakeSmtpServer(type: DockerStartContainer) {
group = "fake-smtp-server container"
description = "Starts ${fakeSmtpContainerName} container."
containerId = fakeSmtpContainerName
}
task dockerStopFakeSmtpServer(type: DockerStopContainer) {
group = "fake-smtp-server container"
description = "Stops ${fakeSmtpContainerName} container."
containerId = fakeSmtpContainerName
}
task dockerRemoveFakeSmtpServer(type: DockerRemoveContainer) {
group = "fake-smtp-server container"
description = "Removes ${fakeSmtpContainerName} container."
containerId = fakeSmtpContainerName
}
dockerRemoveFakeSmtpServer.mustRunAfter('dockerStopFakeSmtpServer')
// Create the task that runs the maintenance command. Run e.g. with:
// ./gradlew dbMaintenance -Pargs="clearEmptyBiographies"
// To see all options, run just:
// ./gradlew dbMaintenance
// which will print the help.
task dbMaintenance(type: JavaExec, dependsOn: 'compileJava') {
group = "database runtime"
description = "Runs the ANET database maintenance command."
classpath = sourceSets.main.runtimeClasspath
environment(run.environment)
mainClass = application.mainClass
def cmdline = ["maintenance"]
if (project.hasProperty("args")) {
cmdline.addAll(project.args.split("\\s+"))
} else {
cmdline << "--help"
}
args cmdline
}
compileJava {
options.encoding = "UTF-8"
}
// Execute the GraphQL plugin before Java compile, so that all test (re)sources are generated on time
compileTestJava.dependsOn generateClientCode
processTestResources.dependsOn generateClientCode
// Add the generated (re)sources as a Java test (re)source folder
sourceSets.test.java.srcDirs += 'build/generated/sources/graphqlGradlePlugin'
sourceSets.test.resources.srcDirs += 'build/generated/resources/graphqlGradlePlugin'
// and ignore optional problems in Eclipse
eclipse.classpath.file {
whenMerged { classpath ->
classpath.entries.each { entry ->
if (entry.path.contains('graphqlGradlePlugin')) {
entry.entryAttributes['ignore_optional_problems'] = true
}
}
}
}
// And remove the auto-added generated (re)sources from the main Java (re)source
task prepareCompileJava(dependsOn: 'generateClientCode') {
doFirst {
logger.info("De-registering generated folders for task prepareCompileJava")
def mainJavaSrcDirs = sourceSets.main.java.srcDirs.toList()
mainJavaSrcDirs.removeAll { it.name == 'graphqlGradlePlugin' }
sourceSets.main.java.srcDirs = mainJavaSrcDirs
}
}
compileJava.dependsOn prepareCompileJava
task prepareProcessResources(dependsOn: 'generateClientCode') {
doFirst {
logger.info("De-registering generated folders for task prepareProcessResources")
def mainResourceSrcDirs = sourceSets.main.resources.srcDirs.toList()
mainResourceSrcDirs.removeAll { it.name == 'graphqlGradlePlugin' }
sourceSets.main.resources.srcDirs = mainResourceSrcDirs
}
}
processResources.dependsOn('prepareProcessResources', 'buildClient')
// Configure the GraphQL Gradle Plugin; all available parameters are described here:
// https://graphql-maven-plugin-project.graphql-java-generator.com/graphql-maven-plugin/generateClientCode-mojo.html
generateClientCodeConf {
schemaFileFolder = 'src/test/resources/'
schemaFilePattern = 'anet.graphql'
packageName = 'mil.dds.anet.test.client'
separateUtilityClasses = true
copyRuntimeSources = false
generateDeprecatedRequestResponse = false
skipGenerationIfSchemaHasNotChanged = true
customScalars = [
[
graphQLTypeName: "Instant",
javaType: "java.time.Instant",
graphQLScalarTypeStaticField: "mil.dds.anet.graphql.DateTimeMapper.GraphQLInstant"
],
[
graphQLTypeName: "Base64String",
javaType: "byte[]",
graphQLScalarTypeStaticField: "com.graphql_java_generator.customscalars.GraphQLScalarTypeBase64String.GraphQLBase64String"
],
[
graphQLTypeName: "Long",
javaType: "java.lang.Long",
graphQLScalarTypeStaticField: "graphql.scalars.ExtendedScalars.GraphQLLong"
],
[
graphQLTypeName: "Map_String_ObjectScalar",
javaType: "java.util.HashMap",
graphQLScalarTypeStaticField: "graphql.scalars.ExtendedScalars.Object"
],
[
graphQLTypeName: "UNREPRESENTABLE",
javaType: "java.lang.Object",
graphQLScalarTypeStaticField: "graphql.scalars.ExtendedScalars.Object"
]
]
}
jar.dependsOn buildClient
run.dependsOn(compileJava, buildClient, pushPsqlImageData)
test.dependsOn(pushPsqlImageData)
run.mustRunAfter('dockerStartKeycloak')
test.mustRunAfter('dockerStartKeycloak', 'dockerStartFakeSmtpServer')
jar {
// Add classpath to manifest to prevent variables in startScripts getting too long
manifest {
attributes "Class-Path": configurations.runtimeClasspath.files*.name.join(" ")
}
}
//Configure the Java Checkstyle settings. Run with ./gradlew check
checkstyle {
configFile = rootProject.file('config/google_checks.xml')
toolVersion = '10.21.0'
}
//Easiest way to avoid checking generated code
checkstyleTest {
source = fileTree('src/test/java')
}
//Work-around for https://github.com/gradle/gradle/issues/27035
configurations.checkstyle {
resolutionStrategy.capabilitiesResolution.withCapability('com.google.collections:google-collections') {
select('com.google.guava:guava:33.4.0-jre')
}
}
spotless {
java {
importOrderFile 'config/google.importorder'
eclipse().configFile('config/eclipse-java-google-style.xml')
// Exclude generated code
targetExclude 'build/generated/**'
}
}
//Configure extra files to include the distribution file
distributions {
main {
contents {
into('docs/') {
from('application.yml') { rename('application.yml', 'application.yml.template') }
from('anet-dictionary.yml') { rename('anet-dictionary.yml', 'anet-dictionary.yml.template') }
}
}
}
}
startScripts {
// Clear up the classpath because the jar has it in its manifest
classpath = jar.outputs.files
doLast {
unixScript.text = unixScript.text.replace('MY_APP_HOME', '\$APP_HOME')
windowsScript.text = windowsScript.text.replace('MY_APP_HOME', '%APP_HOME%')
}
}
node {
nodeProjectDir = file("${project.projectDir}/client")
version = '20.10.0'
yarnVersion = '1.22.19'
download = true
}
task prettierCheck(type: YarnTask) {
args = ["run", "prettier:check"]
}
task distRpm(dependsOn: "jpackageImage", type: Rpm) {
release = '0'
prefix '/opt' // Relocations: /opt
arch = 'x86_64'
os = LINUX
into '/opt'
from(jpackageImage.outputs.files)
into('anet/') {
from('logback-spring.xml')
}
into('anet/docs/') {
from('application.yml') { rename('application.yml', 'application.yml.template') }
from('anet-dictionary.yml') { rename('anet-dictionary.yml', 'anet-dictionary.yml.template') }
}
}