-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.gradle
1281 lines (1029 loc) · 40.5 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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
buildscript {
configurations.classpath {
resolutionStrategy.activateDependencyLocking()
}
dependencies {
classpath 'guru.nidi:graphviz-java:0.18.1'
classpath 'net.sourceforge.plantuml:plantuml:1.2021.4'
}
}
plugins {
id 'java'
// This is both a library _and_ an application
id 'java-library'
id 'application'
id 'jacoco'
id "idea"
id "com.datastax.fallout.symlinks"
id "com.datastax.fallout.externaltools"
id "com.datastax.fallout.fork"
id "com.datastax.fallout.git"
id "com.datastax.fallout.docker"
id "com.datastax.fallout.conventions.test"
id "com.datastax.fallout.conventions.lint"
id "com.datastax.fallout.conventions.kotlin"
id "com.datastax.fallout.conventions.dependency-locking"
id "com.datastax.fallout.conventions.common-root-project"
id "com.github.johnrengelman.shadow" version "7.1.1"
id "com.github.node-gradle.node" version "3.1.1"
id "com.diffplug.spotless" version "6.2.0"
// This appears to be the only assertj plugin that:
// - handles dependencies correctly;
// - generates a single entrypoint class;
// - can generate assertions for non-project classes.
id "com.waftex.assertj-generator" version "1.1.4"
}
import com.datastax.fallout.gradle.fork.Fork
import static com.datastax.fallout.gradle.Utils.camelCase
import static com.datastax.fallout.gradle.common.CascadeTaskKt.cascadeTask
group = 'com.datastax'
version = '0.1.0-SNAPSHOT'
mainClassName = 'com.datastax.fallout.service.FalloutService'
def javaModuleJvmArgs = [
// Handle jackson reflection under Java 9+ (see
// https://github.com/FasterXML/jackson-modules-base/issues/37#issuecomment-389581245)
'--add-opens', 'java.base/java.lang=ALL-UNNAMED',
'--add-opens', 'java.base/java.nio=ALL-UNNAMED'
]
// This will be inserted into the fallout wrapper script
applicationDefaultJvmArgs = [
'-XX:+HeapDumpOnOutOfMemoryError',
'-XX:-OmitStackTraceInFastThrow',
'-server',
'-ea',
'-Djava.util.concurrent.ForkJoinPool.common.parallelism=1024'
] + javaModuleJvmArgs
// In production, falloutctl sets heap sizes; when running within gradle
// we must set something larger than the default 512m
// (https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory)
// for the test and server processes:
ext.applicationGradleJvmArgs = applicationDefaultJvmArgs + ["-Xmx2G"]
description = """DataStax Fallout"""
def defaultPropertyValue(String name, Closure valueProvider) {
if (!project.hasProperty(name)) {
ext.set(name, valueProvider.call())
}
ext.get(name)
}
def defaultPropertyValue(String name, Object value) {
defaultPropertyValue(name, { value })
}
allprojects {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
if (rootProject.hasProperty('showJavaCompilerWarnings')) {
options.compilerArgs += ['-Xlint:deprecation', '-Xlint:unchecked']
}
}
// Ensure that archive tasks have reproducible outputs: this allows
// build caching and build avoidance. See
// https://docs.gradle.org/5.6.3/userguide/working_with_files.html#sec:reproducible_archives
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
tasks.withType(Zip) {
zip64 = true
}
tasks.withType(JavaExec) {
enableAssertions = true
}
}
def dropwizardVersion = '2.0.+'
ext.jschVersion = "0.2.4"
defaultTasks ':shadowJar'
sourceSets {
testBase
integrationTest
cassandraAllShaded
}
configurations {
testBaseImplementation.extendsFrom(implementation, testConventionsImplementationDeps)
integrationTestImplementation.extendsFrom(testBaseImplementation)
integrationTestRuntimeOnly.extendsFrom(testBaseRuntimeOnly, testConventionsRuntimeOnlyDeps)
integrationTestCompileOnly.extendsFrom(testBaseCompileOnly)
testImplementation.extendsFrom(testBaseImplementation)
testRuntimeOnly.extendsFrom(testBaseRuntimeOnly, testConventionsImplementationDeps)
testCompileOnly.extendsFrom(testBaseCompileOnly)
}
// Make the following sourceSets available
// for consumption as feature variants; see
// https://docs.gradle.org/current/userguide/cross_project_publications.html#sec:variant-aware-sharing
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
registerFeature("testBase") {
usingSourceSet(sourceSets.testBase)
}
registerFeature("test") {
usingSourceSet(sourceSets.test)
}
registerFeature("cassandraAllShaded") {
usingSourceSet(sourceSets.cassandraAllShaded)
}
registerFeature("integrationTest") {
usingSourceSet(sourceSets.integrationTest)
}
}
configurations.all {
resolutionStrategy {
// The transitive dependency
// io.dropwizard.metrics:metrics-jersey2:4.1.28 brings in jersey-server
// 2.35, while io.dropwizard:dropwizard-core depends on jersey
// 2.33; the combination of the two versions causes SSE failures
force("org.glassfish.jersey.core:jersey-server:2.33")
}
}
dependencies {
// The DataStax internal version of fallout uses this project as a
// dependency, which is why several dependencies are exposed as api
// dependencies rather than implementation dependencies
api project(path: ':cassandra-all-shaded', configuration: 'shadow')
api project(path: ':jepsen', configuration: 'shadow')
cassandraAllShadedApi project(path: ':cassandra-all-shaded', configuration: 'shadow')
api(platform("io.dropwizard:dropwizard-bom:${dropwizardVersion}"))
api(platform("io.dropwizard:dropwizard-dependencies:${dropwizardVersion}"))
api "io.dropwizard:dropwizard-core"
implementation "io.dropwizard:dropwizard-views-mustache"
implementation "io.dropwizard:dropwizard-assets"
api "io.dropwizard:dropwizard-auth"
api "io.dropwizard:dropwizard-logging"
api "io.dropwizard:dropwizard-metrics-graphite"
api(platform("com.fasterxml.jackson:jackson-bom:2.12.+"))
api("com.fasterxml.jackson.core:jackson-databind")
api "com.google.guava:guava"
api "com.github.spullara.mustache.java:compiler"
implementation "org.eclipse.jetty:jetty-rewrite"
implementation "com.github.mwiede:jsch:${jschVersion}"
api "commons-io:commons-io:2.+"
api "org.yaml:snakeyaml:1.+"
implementation("com.h2database:h2:1.4.+") {
because("InMemoryCsvCheck uses this")
}
implementation "javax.mail:javax.mail-api:1.6.+"
implementation "com.sun.mail:javax.mail:1.6.+"
api "org.apache.commons:commons-csv:1.+"
api("io.netty:netty-common:4.1.+") {
because "HashedWheelTimer is used in several places"
}
implementation "com.fasterxml.jackson.core:jackson-annotations"
implementation("org.apache.httpcomponents:httpclient:4.+") {
because "HttpUtils is the only user; everything else uses jersey"
}
api "org.hdrhistogram:HdrHistogram:2.+"
api 'com.github.pingtimeout:HdrLogProcessing:274e279'
// Swagger
implementation("io.dropwizard:dropwizard-views-freemarker") {
because "Freemarker rendering is used by the dropwizard swagger bundle"
}
// See https://github.com/smoketurner/dropwizard-swagger/releases
//
// Waiting for fix of
// https://github.com/smoketurner/dropwizard-swagger/issues/210 to be
// released in an official version. Once that has
// been done, we can use that instead of this jitpack dependency,
implementation("com.github.smoketurner:dropwizard-swagger:661c79d")
// Server-Sent Events
implementation "org.glassfish.jersey.media:jersey-media-sse"
implementation("org.glassfish.jersey.security:oauth2-client") {
// Prevent the Jersey JacksonFeature (which overrides the Dropwizard
// one) from being found and registered.
// See https://github.com/dropwizard/dropwizard/issues/1341
exclude(group: "org.glassfish.jersey.media", module: "jersey-media-json-jackson")
}
implementation "javax.ws.rs:javax.ws.rs-api:2.+"
implementation('com.google.cloud:google-cloud-logging:2.2.+') {
exclude group: 'com.google.guava', module: 'guava'
}
// AutoService
def autoServiceVersion = '1.+'
annotationProcessor "com.google.auto.service:auto-service:${autoServiceVersion}"
testAnnotationProcessor "com.google.auto.service:auto-service:${autoServiceVersion}"
testBaseAnnotationProcessor "com.google.auto.service:auto-service:${autoServiceVersion}"
implementation "com.google.auto.service:auto-service-annotations:${autoServiceVersion}"
// Compile against the main classes, but leave it up to the
// test configuration to specify where the runtime is (test
// will already use sourceSets.main.output by default).
testBaseCompileOnly sourceSets.main.output
testBaseApi "org.awaitility:awaitility"
testBaseApi(platform("io.dropwizard:dropwizard-bom:${dropwizardVersion}"))
testBaseApi(platform("io.dropwizard:dropwizard-dependencies:${dropwizardVersion}"))
testBaseImplementation "io.dropwizard:dropwizard-logging"
testBaseApi("io.dropwizard:dropwizard-testing") {
exclude group: "junit", module: "junit"
}
testImplementation sourceSets.testBase.output
testApi "org.apache.sshd:sshd-core:2.+"
testApi "org.apache.sshd:sshd-sftp:2.+"
testApi "org.apache.sshd:sshd-scp:2.+"
testApi "org.mockito:mockito-core:4.+"
testApi 'org.mockito:mockito-junit-jupiter:4.+'
testApi "org.quicktheories:quicktheories:0.+"
testImplementation('com.github.tomakehurst:wiremock-jre8:2.+') {
exclude group: 'com.fasterxml.jackson'
}
// Needed for ClojureShutdownListener
testImplementation "org.junit.platform:junit-platform-launcher"
integrationTestImplementation sourceSets.testBase.output
integrationTestRuntimeOnly tasks.jar.outputs.files
implementation 'software.amazon.awssdk:s3:2.17.259'
implementation 'software.amazon.awssdk:secretsmanager:2.17.259'
}
// ----------------------------------------------------------------------------
// Git support
task setupGit {
def config = [
"core.hooksPath" : "git-hooks",
"core.whitespace": "blank-at-eol,space-before-tab,tab-in-indent,trailing-space"
]
doLast {
config.each { key, value ->
exec {
commandLine("git", "config", key, value)
}
}
exec {
commandLine("git", "secrets", "--register-aws")
}
exec {
commandLine("git", "secrets", "--add-provider", "--",
"grep", "-E", "-v", "^[[:space:]]*(#.*)?\$", ".gitforbidden")
}
}
}
// ----------------------------------------------------------------------------
// Compilation
// Supporting @JsonCreator with implicit named parameters requires
// that we store the parameter names in the generated class files
// (https://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html):
tasks.withType(JavaCompile) {
options.compilerArgs += '-parameters'
}
// ----------------------------------------------------------------------------
// IDEA integration
idea {
module {
// Exclude directories that are ignored in .gitignore; this should be
// automatic, but it isn't: see
// https://youtrack.jetbrains.com/issue/IDEA-140714
excludeDirs += [
// Ignore files created by running fallout/cassandra in
// the current directory
file('tests'), file('cassandra'), file('run'), file('logs'),
// Nothing creates tmp, but it's a convenient place to keep
// temporary things
file('tmp')
]
}
}
def ideaVersion = System.getProperty('idea.version')
if (ideaVersion) {
def (major, minor) = ideaVersion.split("\\.").collect { it.toInteger() }
// IDEA 2019 defines idea.version for _all_ gradle invocations; prior
// versions only defined it when importing. 2019 additionally
// defines sync.active when importing.
def importing = major < 2019 || System.getProperty('idea.sync.active');
if (importing) {
println "Detected IDEA ${ideaVersion} Sync"
// IDEA used to incorrectly use the annotation processor classpath as
// "Provided", which means that any library versions in the annotation
// processor classpath override the versions in the implementation
// classpath. This is no longer the case in 2020.3; it may have
// been fixed earlier
if (major < 2020 || (major == 2020 && minor < 3)) {
println "Fixing incorrect annotation processor classpaths"
dependencies {
annotationProcessor configurations.implementation
testAnnotationProcessor configurations.testImplementation
}
}
// IDEA < 2019.3 searches for annotation processors on the classpath,
// and doesn't use the annotationProcessor configuration,
// so we add it here.
if (major < 2019 || (major == 2019 && minor < 3)) {
println "Adding annotation processor classpaths"
idea {
module {
scopes.each {
it.value.plus += [configurations.annotationProcessor]
}
}
}
}
}
}
// ----------------------------------------------------------------------------
// Convenience
task publish {
group 'publish'
description "Publish all artifacts that make up a release"
}
// ----------------------------------------------------------------------------
// Run cassandra as a standalone process
def cassandraVersion = "2.1.21"
configurations {
cassandraStandalone
}
dependencies {
cassandraStandalone 'org.jmxtrans.agent:jmxtrans-agent:1.2.8'
cassandraStandalone "org.apache.cassandra:cassandra-all:${cassandraVersion}"
}
// Dummy rendezvous task
task cassandraStopped
task startCassandra(type: Fork) {
def pidFile = file("${project.rootDir}/run/cassandra.pid")
def java8Home = System.getenv('JAVA8_HOME')
def classPath = configurations.cassandraStandalone.asPath
def cassandraYaml = "${project.rootDir}/src/main/resources/cassandra.yaml"
def logbackXml = "${project.rootDir}/etc/cassandra/logback.xml"
def logDir = "${project.rootDir}/logs/cassandra"
doFirst {
if (!java8Home) {
throw new GradleException("JAVA8_HOME must be set to run startCassandra task")
}
}
workingDir "${project.rootDir}"
commandLine "${java8Home}/bin/java",
"-classpath", classPath,
"-XX:+HeapDumpOnOutOfMemoryError", "-Xms8G", "-Xmx8G", "-server", "-ea",
"-Dcassandra.config=file://${cassandraYaml}",
"-Dcassandra-pidfile=${pidFile}",
"-Dcassandra.logdir=${logDir}",
"-Dlogback.configurationFile=${logbackXml}",
"org.apache.cassandra.service.CassandraDaemon"
doLast {
def waitSeconds = 60
def port = 9096
def portOpened = false
while (!portOpened && waitSeconds && !processHandle.state.terminal) {
try {
def socket = new Socket("localhost", port);
socket.close()
portOpened = true
}
catch (ConnectException e) {
}
waitSeconds -= 1
Thread.sleep(1000)
}
if (processHandle.state.terminal) {
throw new GradleException("Cassandra exited with code ${processHandle.waitForFinish().exitValue}")
}
if (!portOpened) {
processHandle.abort()
throw new GradleException("Cassandra didn't start listening on ${port} within ${waitSeconds} seconds")
}
}
}
task stopCassandra {
finalizedBy cassandraStopped
doFirst {
startCassandra.processHandle.abort()
startCassandra.processHandle.waitForFinish()
}
}
// ----------------------------------------------------------------------------
// Git
git.describeTagPattern = "fallout-*.*.*"
// ----------------------------------------------------------------------------
// Generated resources
def generatedResourcesOutputDir = file("${buildDir}/src/main/resources")
sourceSets {
main {
resources {
srcDirs += generatedResourcesOutputDir
}
}
}
// LESS
node {
download = true
version = "16.1.0"
// Prevent the node extension from declaring a repository: see
// https://github.com/node-gradle/gradle-node-plugin/blob/6f03c21e7e51189885a384ab533ee191c971f7dc/docs/faq.md#is-this-plugin-compatible-with-centralized-repositories-declaration
distBaseUrl = null
}
task lessCompile(type: NpxTask) {
dependsOn npmInstall
def source = file("src/main/resources/assets/less/fallout.less")
def target = file("${generatedResourcesOutputDir}/assets/css/fallout.css")
// The lessCompile task doesn't declare inputs or outputs, so we do it here
inputs.files fileTree("src/main/resources/assets/less")
outputs.file target
command = "lessc"
args = ["$source", "$target"]
}
processResources.dependsOn(lessCompile)
// Version HTML file
task generateVersionFile() {
ext.target = file("${generatedResourcesOutputDir}/assets/pages/version.html")
ext.targetContent = """
<dl>
<dt>branch:
<dd><a href="https://github.com/${git.repo}/tree/${git.branch}">${git.branch}</a>
<dt>commit:
<dd><a href="https://github.com/${git.repo}/commit/${git.commit}">${git.commit}</a>
</dl>
"""
inputs.property("content", targetContent)
outputs.file target
doLast {
target.getParentFile().mkdirs()
target.text = targetContent
}
}
// fallout-client installers
task generateCliInstaller() {
ext.target = file("${generatedResourcesOutputDir}/assets/installers/cli")
ext.targetContent = """
pipx install --python python3 --force "git+ssh://[email protected]/${git.repo}.git@${git.commit}#egg=fallout-client&subdirectory=fallout-cli"
"""
inputs.property('content', targetContent)
outputs.file target
doLast {
target.getParentFile().mkdirs()
target.text = targetContent
}
}
task generateApiInstaller() {
ext.target = file("${generatedResourcesOutputDir}/assets/installers/api")
ext.targetContent = """
python3 -m pip install --upgrade "git+ssh://[email protected]/${git.repo}.git@${git.commit}#egg=fallout-client&subdirectory=fallout-cli"
"""
inputs.property('content', targetContent)
outputs.file target
doLast {
target.getParentFile().mkdirs()
target.text = targetContent
}
}
processResources.dependsOn(generateVersionFile, generateCliInstaller, generateApiInstaller)
// ----------------------------------------------------------------------------
// Generated sources
def generatedSourcesOutputDir = file("${buildDir}/src/main/java")
sourceSets {
main {
java {
srcDirs += generatedSourcesOutputDir
}
}
}
// Annotation processors
sourceSets.each { sourceSet ->
if (sourceSet.compileJavaTaskName != null) {
tasks[sourceSet.compileJavaTaskName].configure {
options.annotationProcessorGeneratedSourcesDirectory =
file("${buildDir}/src/${sourceSet.name}/java-annotation-processors")
}
}
}
// Internal version string
task generateVersionJavaFile {
ext.target = file("${generatedSourcesOutputDir}/com/datastax/fallout/FalloutVersion.java")
ext.targetContent = """
package com.datastax.fallout;
public class FalloutVersion {
public static String getVersion() { return "${git.describe}"; }
public static String getCommitHash() { return "${git.commit}"; }
}
"""
inputs.property("content", targetContent)
outputs.file target
doLast {
target.getParentFile().mkdirs()
target.text = targetContent
}
}
compileJava.dependsOn(generateVersionJavaFile)
// ----------------------------------------------------------------------------
// AssertJ custom assertion generation
assertjGenerator {
classOrPackageNames = [
'com.datastax.fallout.harness.TestResult',
'com.datastax.fallout.ops.NodeGroup',
'com.datastax.fallout.ops.commands.NodeResponse',
'com.datastax.fallout.runner.CheckResourcesResult',
'com.datastax.fallout.service.core.Test',
'com.datastax.fallout.service.core.TestRun',
'com.datastax.fallout.service.core.User',
'javax.ws.rs.core.Response',
'javax.ws.rs.core.Response$StatusType']
entryPointPackage = "com.datastax.fallout.assertj"
outputDir = file("${buildDir}/src/testBase/java")
testSourceSet = sourceSets.testBase
}
// ----------------------------------------------------------------------------
// Distribution and packaging
["startScripts", "startShadowScripts"]
.collect { tasks[it] }
*.configure {
// Insert FALLOUT_HOME and PATH into the default start script before
// the final "exec" line that runs java. It's _possible_ to work out
// where the java executable is running from within the code, but it's more
// involved and less reliable than doing it from the wrapper.
doLast {
unixScript.text = unixScript.text.replaceFirst(~'(\nexec .*\\s*$)', {
'''
export FALLOUT_DIST="$APP_HOME"
export FALLOUT_HOME="${FALLOUT_HOME:-$FALLOUT_DIST}"
export PATH="$FALLOUT_DIST/bin:$PATH"
''' + it[0]
})
}
}
// External tools
externalTools {
configuration("main") {
binary("kubectl") {
// See https://kubernetes.io/docs/tasks/tools/install-kubectl
// for location of binaries and checksums
platforms(["linux", "darwin"]) {
source.set("https://dl.k8s.io/release/v1.23.2/bin/${platform}/amd64/kubectl")
}
platform("linux") {
checksum.set("5b55b58205acbafa7f4e3fc69d9ce5a9257be63455db318e24db4ab5d651cbde")
}
platform("darwin") {
checksum.set("e4d0e8b3a5686907f4285cf5caf9cef4a22fc84f813ae6f22890078febf698f1")
}
}
tarball("helm") {
// https://github.com/helm/helm/releases
platforms(["linux", "darwin"]) {
source.set("https://get.helm.sh/helm-v3.8.0-${platform}-amd64.tar.gz")
unpackedBinDir.set("${platform}-amd64")
}
platform("linux") {
checksum.set("8408c91e846c5b9ba15eb6b1a5a79fc22dd4d33ac6ea63388e5698d1b2320c8b")
}
platform("darwin") {
checksum.set("532ddd6213891084873e5c2dcafa577f425ca662a6594a3389e288fc48dc2089")
}
}
tarball("gcloud") {
// https://console.cloud.google.com/storage/browser/cloud-sdk-release for all versions;
// https://cloud.google.com/sdk/docs/install for current
platforms(["linux", "darwin"]) {
source.set("https://dl.google.com/dl/cloudsdk/channels/rapid/" +
"downloads/google-cloud-sdk-369.0.0-${platform}-x86_64.tar.gz")
unpackedBinDir.set("google-cloud-sdk/bin")
}
platform("linux") {
checksum.set("b5a60ea86c14452580e2019d33586ab2d5dbcde375870d0a030e6b73e7c06093")
}
platform("darwin") {
checksum.set("8a09c9de7c415bdb6ad09b513138d0dffe113fb22c708e10163342e87f80b300")
}
}
}
configuration("test") {
binary("kind") {
// https://github.com/kubernetes-sigs/kind/releases
platforms(["linux", "darwin"]) {
source.set("https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-${platform}-amd64")
}
platform("linux") {
checksum.set("949f81b3c30ca03a3d4effdecda04f100fa3edc07a28b19400f72ede7c5f0491")
}
platform("darwin") {
checksum.set("432bef555a70e9360b44661c759658265b9eaaf7f75f1beec4c4d1e6bbf97ce3")
}
}
}
}
def currentOs = osdetector.os
defaultPropertyValue("externalTestToolsDir", "${buildDir}/externalTestTools")
["linux", "osx"].each { osName ->
// The same as the standard distribution plus the external-tools
distributions.create(osName) {
contents {
with distributions.main.contents
from(project.externalTools.configuration("main").platform(osName).installTask)
}
}
distributions.create(camelCase("shadow", osName)) {
contents {
with distributions.shadow.contents
from(project.externalTools.configuration("main").platform(osName).installTask)
}
}
}
distributions.create("native") {
contents {
with distributions[currentOs].contents
}
}
distributions.create("shadowNative") {
contents {
with distributions[camelCase("shadow", currentOs)].contents
}
}
distributions.matching { dist ->
dist.name == "main" || dist.name == "shadow"
}
*.contents {
// Cassandra standalone support
from(configurations.cassandraStandalone) {
into('lib/cassandra-standalone')
}
from("etc/cassandra") {
into('lib/cassandra-standalone')
}
from("src/main/resources") {
include "cassandra.yaml"
into('lib/cassandra-standalone')
}
// Include the nginx config support files
from('etc/nginx') {
into('nginx')
}
// Include tool support scripts
from('tools/support') {
into('lib/tools/support')
}
}
// Include python sources for tools
subprojects { subproject ->
subproject.afterEvaluate {
if (subproject.ext.has('isPythonTool')) {
distributions
.matching { dist ->
dist.name == "main" || dist.name == "shadow"
}
*.contents {
from(subproject.toolContents) {
into "lib/tools/${subproject.toolCategory}/${subproject.toolName}"
}
}
}
}
}
// Ensure shadowJar correctly merges all the service files and also
// caches the output (it doesn't by default)
shadowJar {
mergeServiceFiles()
manifest {
attributes('Implementation-Version': git.describe)
}
outputs.cacheIf { true }
}
// ----------------------------------------------------------------------------
// Docker
docker {
imageFiles.from(installShadowLinuxDist)
tagName = "datastax/fallout"
// Use the git version without the "fallout-" prefix e.g. "fallout-1.2.3" -> "1.2.3"
tagVersion = git.describe.replaceFirst(/^[a-z-]*/, "")
composeEnvironment.put("CASSANDRA_VERSION", cassandraVersion)
if (osdetector.os == "osx") {
composeEnvironment.put("SSH_AUTH_SOCK", "/run/host-services/ssh-auth.sock")
}
}
publish.dependsOn(dockerPush)
// ----------------------------------------------------------------------------
// Tests
// Dummy rendezvous task to allow builds that compose this build to
// serialize tests
task allTestsFinished
// Pick up any and all generated coverage files
// https://github.com/gradle/gradle/issues/5898#issuecomment-554600486
jacocoTestReport {
getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"))
}
defaultPropertyValue("testToolsRunDir", "${buildDir}/testToolsRun")
task installToolsForTesting {
dependsOn(externalTools.installAllNativeTask)
}
subprojects {
rootProject.installToolsForTesting {
dependsOn tasks.matching { it.name == "installToolForTesting" }
}
}
allprojects {
// Make sure we delete any generated coverage files before running any
// test; if we don't, then coverage reports can include data from test
// tasks that weren't run as part of the current gradle invocation
task cleanJacocoOutputs(type: Delete) {
delete jacocoTestReport.executionData
}
tasks.withType(Test) {
dependsOn(installToolsForTesting)
environment "PATH", "${externalTools.nativePath}:${System.getenv('PATH')}"
environment "FALLOUT_TOOLS_DIR", "${testToolsRunDir}/tools"
jvmArgs = project.applicationGradleJvmArgs
[
"runExpensiveTests",
"runTestsThatCostMoney",
"skipCCMTests"
].each { property ->
if (rootProject.hasProperty(property)) {
systemProperty property, true
}
}
// Pass through any -Plog.... settings as system properties
// (see LogbackConfigurator.java)
rootProject.properties.each { k, v ->
if (k =~ /log\..*/) {
systemProperty k, v
}
}
// Ensure the whole test framework uses the slf4j bridge by setting it
// in the below properties file; if we don't do this, then there'll
// be a period of time where the java.util.logging framework is used
// before gradle manually installs the slf4j bridge
systemProperties += [
'java.util.logging.config.file':
"${project.rootDir}/src/testBase/resources/java.util.logging.properties"
]
def jacocoPluginApplied = extensions.findByType(JacocoTaskExtension)
if (jacocoPluginApplied) {
// Generating coverage data has a non-negligible runtime cost, so we
// don't enable it by default
def generateCoverageData = rootProject.hasProperty('generateCoverageData')
jacoco {
enabled = generateCoverageData
}
if (generateCoverageData) {
dependsOn cleanJacocoOutputs
finalizedBy jacocoTestReport
}
}
}
}
test {
useJUnitPlatform {
excludeTags "requires-db"
}
testClassesDirs = testClassesDirs.plus(
sourceSets.testBase.output.classesDirs)
finalizedBy allTestsFinished
}
task dbTest(type: Test) {
description = 'Starts a local DB instance and runs tests marked RequiresDb.'
group = 'verification'
useJUnitPlatform {
includeTags "requires-db"
}
dependsOn startCassandra
finalizedBy stopCassandra, allTestsFinished
mustRunAfter test
}
["check", "cleanCheck"].each { taskName ->
cascadeTask(project, tasks.named(taskName))
}
// ----------------------------------------------------------------------------
// Running development versions
def nginxStandaloneDir = file("${buildDir}/nginx-standalone")
task generateStandaloneNginxFalloutYml {
ext.falloutYml = file("fallout.yml")
ext.generatedFalloutYml = file("${nginxStandaloneDir}/fallout.yml")
inputs.file falloutYml
outputs.file generatedFalloutYml
doLast {
generatedFalloutYml.getParentFile().mkdirs()
generatedFalloutYml.withOutputStream { out ->
if (falloutYml.exists()) {
falloutYml.withInputStream {
out << it.filterLine {
!it.contains("useNginxToServeArtifacts")
}
}
}
out << "\nuseNginxToServeArtifacts: true"
}
}
}
task generateStandaloneNginxConf(type: JavaExec, dependsOn: [compileJava, generateStandaloneNginxFalloutYml]) {
ext.nginxConf = file("${nginxStandaloneDir}/nginx.conf")
ext.nginxHtml = file("etc/nginx/html")
outputs.file nginxConf
main run.main
classpath run.classpath
args 'generate-nginx-conf',
'--standalone',
'--nginx-listen-port', '8090',
'--output', nginxConf,
generateStandaloneNginxFalloutYml.generatedFalloutYml, nginxHtml
}
task startStandaloneNginx(type: Fork, dependsOn: generateStandaloneNginxConf) {
commandLine "nginx", "-p", nginxStandaloneDir, "-c", generateStandaloneNginxConf.nginxConf