forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
882 lines (748 loc) · 31.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
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
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
buildscript {
repositories {
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'org.yaml:snakeyaml:1.29'
}
}
plugins {
id "de.undercouch.download" version "4.0.4"
id "com.dorongold.task-tree" version "2.1.0"
}
apply plugin: 'de.undercouch.download'
apply from: "rubyUtils.gradle"
import org.yaml.snakeyaml.Yaml
import de.undercouch.gradle.tasks.download.Download
import groovy.json.JsonSlurper
import org.logstash.gradle.tooling.ListProjectDependencies
allprojects {
group = 'org.logstash'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'java-library'
project.sourceCompatibility = JavaVersion.VERSION_1_8
project.targetCompatibility = JavaVersion.VERSION_1_8
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.add("-Xlint:all")
options.compilerArgs.add("-Xlint:-processing")
options.compilerArgs.add("-Werror")
}
tasks.withType(Javadoc).configureEach {
if (JavaVersion.current().compareTo(JavaVersion.VERSION_14) > 0) {
// with JDK 15 the -Xwerror undocumented feature becomes official with switch -Werror
options.addBooleanOption("Werror", true)
} else {
options.addBooleanOption("Xwerror", true)
}
options.addBooleanOption("Xdoclint:all,-missing", true)
if (JavaVersion.current().compareTo(JavaVersion.VERSION_1_9) > 0) {
options.addBooleanOption("html5", true)
}
}
tasks.withType(Copy).configureEach {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
clean {
delete "${projectDir}/out/"
}
//https://stackoverflow.com/questions/3963708/gradle-how-to-display-test-results-in-the-console-in-real-time
tasks.withType(Test) {
testLogging {
// set options for log level LIFECYCLE
events "passed", "skipped", "failed", "standardOut"
showExceptions true
exceptionFormat "full"
showCauses true
showStackTraces true
enableAssertions false
// set options for log level DEBUG and INFO
debug {
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat "full"
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
}
subprojects {
repositories {
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
tasks.register("generateLicenseReport", ListProjectDependencies) {
outputs.dir "${buildDir}/reports/dependency-license"
}
}
version = versionMap['logstash-core']
String artifactVersionsApi = "https://artifacts-api.elastic.co/v1/versions"
tasks.register("configureArchitecture") {
String arch = System.properties['os.arch']
String osName = System.properties['os.name']
String beatsArch = arch
String esArch = arch
// For aarch64 architectures, beats and elasticsearch name their artifacts differently
if (arch == "aarch64") {
beatsArch="arm64"
esArch="aarch64"
} else if (arch == "amd64") {
beatsArch="x86_64"
esArch="x86_64"
}
if (osName ==~ /Mac OS X/) {
osName = "darwin"
} else {
osName = "linux"
}
project.ext.set("beatsArchitecture", "${osName}-${beatsArch}")
project.ext.set("esArchitecture", "${osName}-${esArch}")
}
tasks.register("configureArtifactInfo") {
dependsOn configureArchitecture
description "Set the url to download stack artifacts for select stack version"
doLast {
def versionQualifier = System.getenv('VERSION_QUALIFIER')
if (versionQualifier) {
version = "$version-$versionQualifier"
}
def isReleaseBuild = System.getenv('RELEASE') == "1" || versionQualifier
String apiResponse = artifactVersionsApi.toURL().text
def dlVersions = new JsonSlurper().parseText(apiResponse)
String qualifiedVersion = dlVersions['versions'].grep(isReleaseBuild ? ~/^${version}$/ : ~/^${version}-SNAPSHOT/)[0]
if (qualifiedVersion == null) {
throw new GradleException("could not find the current artifact from the artifact-api ${artifactVersionsApi} for ${version}")
}
// find latest reference to last build
String buildsListApi = "${artifactVersionsApi}/${qualifiedVersion}/builds/"
apiResponse = buildsListApi.toURL().text
def dlBuilds = new JsonSlurper().parseText(apiResponse)
def stackBuildVersion = dlBuilds["builds"][0]
project.ext.set("artifactApiVersionedBuildUrl", "${artifactVersionsApi}/${qualifiedVersion}/builds/${stackBuildVersion}")
project.ext.set("stackArtifactSuffix", qualifiedVersion)
}
}
abstract class SignAliasDefinitionsTask extends DefaultTask {
/**
* Relative path to the AliasRegistry.yml file to use, relative to project's root
* */
@Input
String registryPath
/**
* Full file path to the file containing the marked AliasRegistry file
* */
@OutputFile
File hashedFile
@TaskAction
def sign() {
String aliases_defs = new File("${project.projectDir}/${registryPath}").text
String hash = aliases_defs.digest('SHA-256')
hashedFile.withWriter('utf-8') { writer ->
writer.writeLine "#CHECKSUM: ${hash}"
writer.writeLine "# DON'T EDIT THIS FILE, PLEASE REFER TO ${registryPath}"
writer.write aliases_defs
}
}
}
tasks.register("markAliasDefinitions", SignAliasDefinitionsTask) {
description "Create an hashes aliases file from original aliases yml definition"
registryPath = 'logstash-core/src/main/resources/org/logstash/plugins/AliasRegistry.yml'
hashedFile = project.file("${project.buildDir}/plugin_aliases_hashed.yml")
}
tasks.register("markTestAliasDefinitions", SignAliasDefinitionsTask) {
description "Create an hashes aliases file for testing aliases yml definition"
registryPath = 'logstash-core/src/test/resources/org/logstash/plugins/AliasRegistry.yml'
hashedFile = project.file("${project.buildDir}/plugin_aliases_hashed_test.yml")
}
tasks.register("copyPluginAlias", Copy) {
description "Copy the marked plugin_aliases.yml file to destination folders"
dependsOn = [copyPluginAlias_ruby, copyPluginAlias_java]
}
tasks.register("copyPluginAlias_ruby", Copy) {
description "Copy the marked plugin_aliases.yml file to destination folders"
dependsOn "markAliasDefinitions"
inputs.file("${buildDir}/plugin_aliases_hashed.yml")
from(markAliasDefinitions.hashedFile) {
rename "plugin_aliases_hashed.yml", "plugin_aliases.yml"
}
into "lib/pluginmanager/"
}
tasks.register("copyPluginAlias_java", Copy) {
description "Copy the marked plugin_aliases.yml file to destination folders"
dependsOn "markAliasDefinitions"
inputs.file("${buildDir}/plugin_aliases_hashed.yml")
from(markAliasDefinitions.hashedFile) {
rename "plugin_aliases_hashed.yml", "plugin_aliases.yml"
}
into "logstash-core/src/main/resources/org/logstash/plugins/"
}
tasks.register("copyPluginTestAlias") {
description "Copy the marked test plugin_aliases.yml file to destination folders"
dependsOn = [copyPluginTestAlias_ruby, copyPluginTestAlias_java]
}
tasks.register("copyPluginTestAlias_ruby", Copy) {
description "Copy the marked test plugin_aliases.yml file into Ruby's plugin_manager specs"
dependsOn "markTestAliasDefinitions"
inputs.file(markTestAliasDefinitions.hashedFile)
from(markTestAliasDefinitions.hashedFile) {
rename "plugin_aliases_hashed_test.yml", "plugin_aliases.yml"
}
into "spec/unit/plugin_manager/"
}
tasks.register("copyPluginTestAlias_java", Copy) {
description "Copy the marked test plugin_aliases.yml file into logstash-core's test resources"
dependsOn "markTestAliasDefinitions"
inputs.file("${buildDir}/plugin_aliases_hashed_test.yml")
from(markTestAliasDefinitions.hashedFile) {
rename "plugin_aliases_hashed_test.yml", "plugin_aliases.yml"
}
into "logstash-core/src/test/resources/org/logstash/plugins/"
}
tasks.findByPath(':logstash-core:processResources').dependsOn(copyPluginAlias)
tasks.findByPath(':logstash-core:processTestResources').dependsOn(copyPluginTestAlias)
// Tasks
clean {
delete "${projectDir}/Gemfile"
delete "${projectDir}/Gemfile.lock"
delete "${projectDir}/vendor"
delete "${projectDir}/.bundle"
delete "${projectDir}/qa/integration/Gemfile.lock"
delete "${projectDir}/qa/integration/.bundle"
delete "${projectDir}/build/licenseReportFolders.txt"
delete "${projectDir}/build/rubyDependencies.csv"
delete "${projectDir}/lib/pluginmanager/plugin_aliases.yml"
delete "${projectDir}/spec/unit/plugin_manager/plugin_aliases.yml"
delete "${projectDir}/logstash-core/build/resources/test/org/logstash/plugins/plugin_aliases.yml"
delete "${projectDir}/logstash-core/build/resources/main/org/logstash/plugins/plugin_aliases.yml"
delete "${projectDir}/logstash-core/src/test/resources/org/logstash/plugins/plugin_aliases.yml"
delete "${projectDir}/logstash-core/src/main/resources/org/logstash/plugins/plugin_aliases.yml"
}
def assemblyDeps = [downloadAndInstallJRuby, assemble] + subprojects.collect {
it.tasks.findByName("assemble")
}
tasks.register("installBundler") {
dependsOn assemblyDeps
outputs.files file("${projectDir}/vendor/bundle/jruby/2.5.0/bin/bundle")
doLast {
gem(projectDir, buildDir, "bundler", "~> 2", "${projectDir}/vendor/bundle/jruby/2.5.0")
}
}
tasks.register("bootstrap"){
dependsOn installBundler
doLast {
setupJruby(projectDir, buildDir)
}
}
tasks.register("installDefaultGems") {
dependsOn bootstrap
doLast {
rake(projectDir, buildDir, 'plugin:install-default')
}
}
tasks.register("installTestGems") {
dependsOn bootstrap
doLast {
rake(projectDir, buildDir, 'plugin:install-development-dependencies')
}
}
tasks.register("compileGrammar") {
dependsOn bootstrap
doLast {
rake(projectDir, buildDir, 'compile:grammar')
}
}
tasks.register("assembleTarDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/modules")
inputs.files fileTree("${projectDir}/logstash-core-plugin-api")
inputs.files fileTree("${projectDir}/logstash-core/lib")
inputs.files fileTree("${projectDir}/logstash-core/src")
inputs.files fileTree("${projectDir}/x-pack")
outputs.files file("${buildDir}/logstash-${project.version}-SNAPSHOT.tar.gz")
doLast {
rake(projectDir, buildDir, 'artifact:no_bundle_jdk_tar')
}
}
tasks.register("assembleOssTarDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/modules")
inputs.files fileTree("${projectDir}/logstash-core-plugin-api")
inputs.files fileTree("${projectDir}/logstash-core/lib")
inputs.files fileTree("${projectDir}/logstash-core/src")
doLast {
rake(projectDir, buildDir, 'artifact:archives_oss')
}
}
tasks.register("assembleZipDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/modules")
inputs.files fileTree("${projectDir}/logstash-core-plugin-api")
inputs.files fileTree("${projectDir}/logstash-core/lib")
inputs.files fileTree("${projectDir}/logstash-core/src")
inputs.files fileTree("${projectDir}/x-pack")
outputs.files file("${buildDir}/logstash-${project.version}.zip")
doLast {
rake(projectDir, buildDir, 'artifact:archives')
}
}
tasks.register("assembleOssZipDistribution") {
dependsOn bootstrap
inputs.files fileTree("${projectDir}/rakelib")
inputs.files fileTree("${projectDir}/bin")
inputs.files fileTree("${projectDir}/config")
inputs.files fileTree("${projectDir}/lib")
inputs.files fileTree("${projectDir}/modules")
inputs.files fileTree("${projectDir}/logstash-core-plugin-api")
inputs.files fileTree("${projectDir}/logstash-core/lib")
inputs.files fileTree("${projectDir}/logstash-core/src")
outputs.files file("${buildDir}/logstash-${project.version}.zip")
doLast {
rake(projectDir, buildDir, 'artifact:archives_oss')
}
}
project(":logstash-core") {
["rubyTests", "test"].each { tsk ->
tasks.getByPath(":logstash-core:" + tsk).configure {
dependsOn copyPluginTestAlias
dependsOn installTestGems
}
}
}
def logstashBuildDir = "${buildDir}/logstash-${project.version}-SNAPSHOT"
tasks.register("unpackTarDistribution", Copy) {
dependsOn assembleTarDistribution
def tar = file("${buildDir}/logstash-${project.version}-SNAPSHOT.tar.gz")
inputs.files tar
outputs.files fileTree(logstashBuildDir)
from tarTree(tar)
into {buildDir}
}
def qaBuildPath = "${buildDir}/qa/integration"
def qaVendorPath = "${qaBuildPath}/vendor"
def qaBundledGemPath = "${qaVendorPath}/jruby/2.5.0".toString()
def qaBundleBin = "${qaBundledGemPath}/bin/bundle"
tasks.register("installIntegrationTestBundler"){
dependsOn unpackTarDistribution
outputs.files file("${qaBundleBin}")
doLast {
gem(projectDir, buildDir, "bundler", "~> 2", qaBundledGemPath)
}
}
tasks.register("installIntegrationTestGems") {
dependsOn installIntegrationTestBundler
inputs.files file("${projectDir}/qa/integration/Gemfile")
inputs.files file("${projectDir}/qa/integration/integration_tests.gemspec")
inputs.files file("${logstashBuildDir}/Gemfile")
inputs.files file("${logstashBuildDir}/Gemfile.lock")
inputs.files file("${logstashBuildDir}/logstash-core/logstash-core.gemspec")
outputs.files fileTree("${qaVendorPath}")
outputs.files file("${projectDir}/qa/integration/Gemfile.lock")
doLast {
bundleWithEnv(
projectDir, buildDir,
qaBuildPath, qaBundleBin, ['install', '--path', qaVendorPath],
[ GEM_PATH: qaBundledGemPath, GEM_HOME: qaBundledGemPath ]
)
}
}
tasks.register("downloadFilebeat") {
dependsOn configureArtifactInfo
description "Download Filebeat Snapshot for current branch version: ${version}"
project.ext.set("versionFound", true)
inputs.file("${projectDir}/versions.yml")
doLast {
download {
String downloadedFilebeatName = "filebeat-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("beatsArchitecture")}"
project.ext.set("unpackedFilebeatName", downloadedFilebeatName)
// find url of build artifact
String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/beats/packages/${downloadedFilebeatName}.tar.gz"
String apiResponse = artifactApiUrl.toURL().text
def buildUrls = new JsonSlurper().parseText(apiResponse)
project.ext.set("filebeatSnapshotUrl", System.getenv("FILEBEAT_SNAPSHOT_URL") ?: buildUrls["package"]["url"])
project.ext.set("filebeatDownloadLocation", "${projectDir}/build/${downloadedFilebeatName}.tar.gz")
src project.ext.filebeatSnapshotUrl
onlyIfNewer true
dest new File(project.ext.filebeatDownloadLocation)
retries 3
}
System.out.println "Downloaded to ${project.ext.filebeatDownloadLocation}"
}
}
tasks.register("deleteLocalFilebeat", Delete) {
delete ('./build/filebeat')
}
tasks.register("copyFilebeat") {
dependsOn = [downloadFilebeat, deleteLocalFilebeat]
doLast {
copy {
from tarTree(resources.gzip(project.ext.filebeatDownloadLocation))
into "./build/"
}
file("./build/${project.ext.unpackedFilebeatName}").renameTo('./build/filebeat')
System.out.println "Unzipped ${project.ext.filebeatDownloadLocation} to ./build/filebeat"
System.out.println "Deleting ${project.ext.filebeatDownloadLocation}"
delete(project.ext.filebeatDownloadLocation)
}
}
tasks.register("checkEsSHA") {
dependsOn configureArtifactInfo
description "Download ES version remote's fingerprint file"
doLast {
String downloadedElasticsearchName = "elasticsearch-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("esArchitecture")}"
// find url of build artifact
String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/elasticsearch/packages/${downloadedElasticsearchName}.tar.gz"
String apiResponse = artifactApiUrl.toURL().text
def buildUrls = new JsonSlurper().parseText(apiResponse)
String remoteSHA = buildUrls.package.sha_url.toURL().text
def localESArchive = new File("${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
if (localESArchive.exists()) {
// this create a file named localESArchive with ".SHA-512" postfix
ant.checksum(file: localESArchive, algorithm: "SHA-512", forceoverwrite: true)
File localESCalculatedSHAFile = new File("${projectDir}/build/${downloadedElasticsearchName}.tar.gz.SHA-512")
String localESCalculatedSHA = localESCalculatedSHAFile.text.trim()
def splitted = remoteSHA.split(' ')
String remoteSHACode = splitted[0]
if (localESCalculatedSHA != remoteSHACode) {
println "ES package calculated fingerprint is different from remote, deleting local archive"
delete(localESArchive)
}
}/* else {
mkdir project.buildDir
// touch the SHA file else downloadEs task doesn't start, this file his input for the other task
new File("${projectDir}/build/${downloadedElasticsearchName}.tar.gz.SHA-512").withWriter { w ->
w << "${downloadedElasticsearchName} not yet downloaded"
w.close()
}
}*/
}
}
tasks.register("downloadEs") {
dependsOn = [configureArtifactInfo, checkEsSHA]
description "Download ES Snapshot for current branch version: ${version}"
inputs.file("${projectDir}/versions.yml")
doLast {
download {
String downloadedElasticsearchName = "elasticsearch-${project.ext.get("stackArtifactSuffix")}-${project.ext.get("esArchitecture")}"
project.ext.set("unpackedElasticsearchName", "elasticsearch-${project.ext.get("stackArtifactSuffix")}")
// find url of build artifact
String artifactApiUrl = "${project.ext.get("artifactApiVersionedBuildUrl")}/projects/elasticsearch/packages/${downloadedElasticsearchName}.tar.gz"
String apiResponse = artifactApiUrl.toURL().text
def buildUrls = new JsonSlurper().parseText(apiResponse)
project.ext.set("elasticsearchSnapshotURL", System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: buildUrls["package"]["url"])
project.ext.set("elasticsearchDownloadLocation", "${projectDir}/build/${downloadedElasticsearchName}.tar.gz")
src project.ext.elasticsearchSnapshotURL
onlyIfNewer true
retries 3
dest new File(project.ext.elasticsearchDownloadLocation)
}
System.out.println "Downloaded to ${project.ext.elasticsearchDownloadLocation}"
}
}
tasks.register("deleteLocalEs", Delete) {
delete ('./build/elasticsearch')
}
tasks.register("copyEs") {
dependsOn = [downloadEs, deleteLocalEs]
doLast {
println "copyEs executing.."
copy {
from tarTree(resources.gzip(project.ext.elasticsearchDownloadLocation))
into "./build/"
}
file("./build/${project.ext.unpackedElasticsearchName}").renameTo('./build/elasticsearch')
println "Unzipped ${project.ext.elasticsearchDownloadLocation} to ./build/elasticsearch"
println "Deleting ${project.ext.elasticsearchDownloadLocation}"
}
}
def rubyIntegrationSpecs = project.hasProperty("rubyIntegrationSpecs") ? ((String) project.property("rubyIntegrationSpecs")).split(/\s+/).join(",") : "specs/**/*_spec.rb"
def integrationTestPwd = "${projectDir}/qa/integration"
project(":logstash-integration-tests") {
tasks.getByPath(":logstash-integration-tests:integrationTests").configure {
systemProperty 'org.logstash.integration.specs', rubyIntegrationSpecs
environment "FEATURE_FLAG", System.getenv('FEATURE_FLAG')
workingDir integrationTestPwd
dependsOn = [installIntegrationTestGems, copyProductionLog4jConfiguration]
}
}
tasks.register("runIntegrationTests") {
dependsOn tasks.getByPath(":logstash-integration-tests:integrationTests")
dependsOn copyEs
dependsOn copyFilebeat
shouldRunAfter ":logstash-core:test"
}
tasks.register("generateLicenseReport", JavaExec) {
dependsOn generateLicenseReportInputs
dependsOn ":dependencies-report:assemble"
def jarFile = project('dependencies-report').getBuildDir().toString() + "/libs/dependencies-report.jar"
String licenseReportInputCSV = project.hasProperty("licenseReportInputCSV") ? project.property("licenseReportInputCSV") : "build/dependencies.csv.ruby"
String licenseReportOutputCSV = project.hasProperty("licenseReportOutputCSV") ? project.property("licenseReportOutputCSV") : "build/dependencies.csv"
String noticePath = "NOTICE.txt"
classpath = project.files([jarFile])
main = "org.logstash.dependencies.Main"
args licenseReportInputCSV,
project.getBuildDir().toString() + "/licenseReportFolders.txt",
licenseReportOutputCSV, noticePath
}
tasks.register("generateLicenseReportInputs") {
dependsOn subprojects.generateLicenseReport
doLast {
// write location of all license reports for subprojects containing artifacts that are distributed to single file
StringBuilder licenseReportFolders = new StringBuilder()
subprojects.findAll { s1 -> !s1.hasProperty("isDistributedArtifact") || s1.property("isDistributedArtifact") == 'true' }.each { s ->
s.tasks.findAll { t2 -> t2.getName() == "generateLicenseReport" }.each { t3 ->
licenseReportFolders.append(t3.reportDir.toString() + "\n")
}
}
if (gradle.startParameter.taskNames.contains("generateLicenseReport")) {
if (!project.getBuildDir().exists()) {
project.getBuildDir().mkdirs()
}
def licenseReportPath = project.getBuildDir().toString() + "/licenseReportFolders.txt"
def licenseReportFolder = new File(licenseReportPath)
licenseReportFolder.delete()
licenseReportFolder = new File(licenseReportPath)
licenseReportFolder.createNewFile()
if (licenseReportFolder.canWrite()) {
licenseReportFolder.text = licenseReportFolders.toString()
}
}
}
}
tasks.register("generatePluginsVersion") {
dependsOn installDefaultGems
doLast {
rake(projectDir, buildDir, 'generate_plugins_version')
}
}
bootstrap.dependsOn assemblyDeps
// FIXME: adding the integration tests task to check will mean
// that any registered task will be evaluated. This creates an issue
// where the downloadES task may throw an error on versions where
// Elasticsearch doesn't yet have a build we can fetch
// So for now we'll remove this to unblock builds, but finding a way
// to compartimentalize failures is needed going forward
//check.dependsOn runIntegrationTest
def selectOsType() {
if (project.ext.has("jdk_bundle_os")) {
return project.ext.jdk_bundle_os
}
String osName = System.properties['os.name']
switch (osName.toLowerCase()) {
case ~/mac os x/:
return "darwin"
case ~/windows.*/:
return "windows"
case ~/linux/:
return "linux"
default:
throw new IllegalArgumentException("Can't determine OS type from name: $osName")
}
}
def selectArch() {
if (project.ext.has("jdk_arch")) {
return project.ext.jdk_arch
}
String cpu_arch = System.properties["os.arch"]
switch (cpu_arch) {
case "amd64":
case "x86_64":
return "x86_64"
case "aarch64":
case "arm64":
return "arm64"
default:
throw new IllegalArgumentException("Can't handle os.arch of type $cpu_arch")
}
}
class JDKDetails {
final String revision
final String build
final String vendor
final int major
private final String osName
private final String extension
final String localPackageName
final String unpackedJdkName
private String arch
JDKDetails(versionYml, osName, jdkArch) {
revision = versionYml.bundled_jdk.revision
build = versionYml.bundled_jdk.build
vendor = versionYml.bundled_jdk.vendor
major = revision.split('\\.').first() as int
this.osName = osName
switch (osName) {
case "windows":
extension = "zip"
break
default:
extension = "tar.gz"
}
arch = parseJdkArchitecture(jdkArch)
unpackedJdkName = "jdk-${revision}-${osName}"
localPackageName = "${unpackedJdkName}-${arch}.${extension}"
}
String createDownloadUrl() {
switch (vendor) {
case "adoptopenjdk":
String releaseName = major > 8 ?
"jdk-${revision}+${build}":
"jdk${revision}u${build}"
String adoptOsName = adaptOsName(osName)
return "https://api.adoptopenjdk.net/v3/binary/version/${releaseName}/${adoptOsName}/${arch}/jdk/hotspot/normal/${vendor}"
default:
throw RuntimeException("Can't handle vendor: ${vendor}")
}
}
private String adaptOsName(String osName) {
if (osName == "darwin")
return "mac"
return osName
}
private String parseJdkArchitecture(String jdkArch) {
switch (jdkArch) {
case "x86_64":
return "x64"
break
case "arm64":
return "aarch64"
break
default:
throw RuntimeException("Can't handle CPU architechture: ${jdkArch}")
}
}
}
tasks.register("downloadJdk", Download) {
// CLI project properties: -Pjdk_bundle_os=[windows|linux|darwin] -Pjdk_arch=[arm64|x86_64]
project.ext.set("versionFound", true)
String osName = selectOsType()
def versionYml = new Yaml().load(new File("$projectDir/versions.yml").text)
String jdkArch = selectArch()
def jdkDetails = new JDKDetails(versionYml, osName, jdkArch)
description "Download JDK ${jdkDetails.major}, OS: ${osName}"
// find url of build artifact
String artifactApiUrl = jdkDetails.createDownloadUrl()
project.ext.set("jdkURL", System.getenv("JDK_URL") ?: artifactApiUrl)
project.ext.set("jdkDownloadLocation", "${projectDir}/build/${jdkDetails.localPackageName}")
project.ext.set("jdkDirectory", "${projectDir}/build/${jdkDetails.unpackedJdkName}")
String jdkFolderName = osName == "darwin" ? "jdk.app" : "jdk"
project.ext.set("jdkBundlingDirectory", "${projectDir}/${jdkFolderName}")
src project.ext.jdkURL
onlyIfNewer true
overwrite false
inputs.file("${projectDir}/versions.yml")
outputs.file(project.ext.jdkDownloadLocation)
dest new File(project.ext.jdkDownloadLocation)
doLast {
mkdir project.ext.jdkBundlingDirectory
println "Downloaded to ${project.ext.jdkDownloadLocation}"
}
}
tasks.register("deleteLocalJdk", Delete) {
// CLI project properties: -Pjdk_bundle_os=[windows|linux|darwin]
String osName = selectOsType()
String jdkFolderName = osName == "darwin" ? "jdk.app" : "jdk"
String jdkBundlingDirectory = "${projectDir}/${jdkFolderName}"
delete jdkBundlingDirectory
}
// Cannot use tarTree as it does not handle symlinks
tasks.register("untarJdk", Exec) {
dependsOn downloadJdk
description = "unpack the downloaded JDK's tar.gz"
commandLine 'tar', 'xf', project.ext.jdkDownloadLocation, '-C', project.ext.jdkBundlingDirectory, '--strip-components', '1'
inputs.file(project.ext.jdkDownloadLocation)
outputs.dir(project.ext.jdkBundlingDirectory)
}
tasks.register("unzipJdk", Copy) {
dependsOn downloadJdk
description = "unpack the downloaded JDK's zip"
String rootName = null
from(zipTree("$project.ext.jdkDownloadLocation")) {
eachFile { fcd ->
rootName = rootName ?: fcd.relativePath.segments[0]
fcd.relativePath = new RelativePath(true, fcd.relativePath.segments.drop(1))
}
}
into project.ext.jdkBundlingDirectory
doLast {
delete "${project.ext.jdkBundlingDirectory}/$rootName"
}
}
tasks.register("decompressJdk") {
description = "unpack the downloaded JDK's (wrapper task for unzipJdk, untarJdk)"
String osName = selectOsType()
switch (osName) {
case "windows":
dependsOn ":unzipJdk"
break
default:
dependsOn ":untarJdk"
}
}
tasks.register("copyJdk", Copy) {
dependsOn = [decompressJdk, bootstrap]
description = "Download, unpack and copy the JDK"
// CLI project properties: -Pjdk_bundle_os=[windows|linux|darwin] -Pjdk_arch=[arm64|x86_64]
doLast {
System.out.println "Download location is ${project.ext.jdkDownloadLocation}, Decompressing ${project.ext.jdkDirectory} to \"${project.ext.jdkBundlingDirectory}\""
}
}
if (System.getenv('OSS') != 'true') {
project(":logstash-xpack") {
["rubyTests", "rubyIntegrationTests", "test"].each { tsk ->
tasks.getByPath(":logstash-xpack:" + tsk).configure {
dependsOn installTestGems
}
}
}
}
tasks.register("runXPackUnitTests") {
dependsOn copyPluginTestAlias
dependsOn ":logstash-xpack:rubyTests"
}
tasks.register("runXPackIntegrationTests"){
dependsOn copyPluginTestAlias
dependsOn ":logstash-xpack:rubyIntegrationTests"
}