aboutsummaryrefslogtreecommitdiff
path: root/build.gradle
blob: 17fcd70e90f434914f9eab6d70773c465ec5e5ab (plain)
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
buildscript {
    repositories {
        mavenCentral()
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'org.yaml:snakeyaml:1.17'
        classpath "gradle.plugin.com.github.jk1:gradle-license-report:0.7.1"
    }
}

plugins {
    id "de.undercouch.download" version "3.2.0"
}

apply plugin: 'de.undercouch.download'


import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify
import org.logstash.gradle.RubyGradleUtils
import org.yaml.snakeyaml.Yaml

allprojects {
  group = 'org.logstash'

  apply plugin: 'java'
  apply plugin: 'idea'

  project.sourceCompatibility = JavaVersion.VERSION_1_8
  project.targetCompatibility = JavaVersion.VERSION_1_8

  tasks.withType(JavaCompile).all {
      def env = System.getenv()
      boolean ci = env['CI']

      //don't lint when running CI builds
      if(!ci){
          options.compilerArgs.add("-Xlint:all")
      }
  }

  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

      // 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 {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        compile "gradle.plugin.com.github.jk1:gradle-license-report:0.7.1"
    }

    apply plugin: 'com.github.jk1.dependency-license-report'

    licenseReport {
        renderer = new com.github.jk1.license.render.CsvReportRenderer()
        configurations = ['compile', 'runtime']
    }
}

// fetch version from Logstash's master versions.yml file
def versionMap = (Map) (new Yaml()).load(new File("${projectDir}/versions.yml").text)
version = versionMap['logstash-core']

String jRubyURL
String jRubyVersion
String jRubySha1
Boolean doChecksum

if (versionMap["jruby-runtime-override"]) {
    jRubyVersion = versionMap["jruby-runtime-override"]["version"]
    jRubyURL = versionMap["jruby-runtime-override"]["url"]
    doChecksum = false
} else {
    jRubyVersion = versionMap["jruby"]["version"]
    jRubySha1 = versionMap["jruby"]["sha1"]
    jRubyURL = "http://jruby.org.s3.amazonaws.com/downloads/${jRubyVersion}/jruby-bin-${jRubyVersion}.tar.gz"
    doChecksum = true
}

// Tasks

clean {
  delete "${projectDir}/Gemfile"
  delete "${projectDir}/Gemfile.lock"
  delete "${projectDir}/vendor"
  delete "${projectDir}/NOTICE.TXT"
  delete "${projectDir}/.bundle"
  delete "${projectDir}/qa/integration/Gemfile.lock"
  delete "${projectDir}/qa/integration/.bundle"
  delete "${projectDir}/build/licenseReportFolders.txt"
  delete "${projectDir}/build/rubyDependencies.csv"
}

task bootstrap {}

RubyGradleUtils rubyGradleUtils = new RubyGradleUtils(buildDir, projectDir)

project(":logstash-core") {
  ["rubyTests", "test"].each { tsk ->
    tasks.getByPath(":logstash-core:" + tsk).configure {
      dependsOn bootstrap
    }
  }
}

def jrubyTarPath = "${projectDir}/vendor/_/jruby-bin-${jRubyVersion}.tar.gz"

task downloadJRuby(type: Download) {
    description "Download JRuby artifact from this specific URL: ${jRubyURL}"
    src jRubyURL
    onlyIfNewer true
    inputs.file("${projectDir}/versions.yml")
    outputs.file(jrubyTarPath)
    dest new File("${projectDir}/vendor/_", "jruby-bin-${jRubyVersion}.tar.gz")
}

task verifyFile(dependsOn: downloadJRuby, type: Verify) {
    description "Verify the SHA1 of the download JRuby artifact"
    inputs.file(jrubyTarPath)
    outputs.file(jrubyTarPath)
    src new File(jrubyTarPath)
    algorithm 'SHA-1'
    checksum jRubySha1
}

task downloadAndInstallJRuby(dependsOn: verifyFile, type: Copy) {
    description "Install JRuby in the vendor directory"
    inputs.file(jrubyTarPath)
    outputs.dir("${projectDir}/vendor/jruby")
    from tarTree(downloadJRuby.dest)
    eachFile { f ->
      f.path = f.path.replaceFirst("^jruby-${jRubyVersion}", '')
    }
    exclude "**/stdlib/rdoc/**"
    includeEmptyDirs = false
    into "${projectDir}/vendor/jruby"
}

task installDefaultGems(dependsOn: downloadAndInstallJRuby) {
  inputs.files file("${projectDir}/Gemfile.template")
  inputs.files fileTree("${projectDir}/rakelib")
  inputs.files file("${projectDir}/versions.yml")
  outputs.file("${projectDir}/Gemfile")
  outputs.file("${projectDir}/Gemfile.lock")
  outputs.dir("${projectDir}/logstash-core/lib/jars")
  outputs.dir("${projectDir}/vendor/bundle/jruby/2.3.0")
  doLast {
    rubyGradleUtils.rake('plugin:install-default')
  }
}

task installTestGems(dependsOn: downloadAndInstallJRuby) {
  inputs.files file("${projectDir}/Gemfile.template")
  inputs.files fileTree("${projectDir}/rakelib")
  inputs.files file("${projectDir}/versions.yml")
  outputs.file("${projectDir}/Gemfile")
  outputs.file("${projectDir}/Gemfile.lock")
  outputs.dir("${projectDir}/logstash-core/lib/jars")
  outputs.dir("${projectDir}/vendor/bundle/jruby/2.3.0")
  doLast {
    rubyGradleUtils.rake('test:install-core')
  }
}

task assembleTarDistribution(dependsOn: downloadAndInstallJRuby) {
  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 {
    rubyGradleUtils.rake('artifact:tar')
  }
}

task assembleOssTarDistribution() {
  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 {
    rubyGradleUtils.rake('artifact:tar_oss')
  }
}

task assembleZipDistribution(dependsOn: downloadAndInstallJRuby) {
  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 {
    rubyGradleUtils.rake('artifact:zip')
  }
}

task assembleOssZipDistribution(dependsOn: downloadAndInstallJRuby) {
  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 {
    rubyGradleUtils.rake('artifact:zip_oss')
  }
}

def logstashBuildDir = "${buildDir}/logstash-${project.version}-SNAPSHOT"

task unpackTarDistribution(dependsOn: assembleTarDistribution, type: Copy) {
  def tar = file("${buildDir}/logstash-${project.version}-SNAPSHOT.tar.gz")
  inputs.files tar
  outputs.files fileTree(logstashBuildDir)
  from tarTree(tar)
  into {buildDir}
}

def qaVendorPath = "${buildDir}/qa/integration/vendor"
def qaBundledGemPath = "${qaVendorPath}/jruby/2.3.0"
def qaBundleBin = "${qaBundledGemPath}/bin/bundle"

task installIntegrationTestBundler(dependsOn: unpackTarDistribution) {
  outputs.files fileTree("${qaBundledGemPath}/gems/bundler-1.16.0")
  doLast {
    rubyGradleUtils.gem("bundler", "1.16.0", qaBundledGemPath)
  }
}

task 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 {
    rubyGradleUtils.bundle(
      "${projectDir}/qa/integration", qaBundleBin, ['install', '--path', qaVendorPath],
      [LS_GEM_PATH: qaBundledGemPath, LS_GEM_HOME: qaBundledGemPath]
    )
  }
}

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
  }
}

task runIntegrationTests(dependsOn: [tasks.getByPath(":logstash-integration-tests:integrationTests")]) {}

task generateLicenseReport(type: 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
}

task generateLicenseReportInputs() {
    dependsOn subprojects.generateLicenseReport

    // 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.outputs.files.asPath + "\n")
        }
    }

    if (gradle.startParameter.taskNames.contains("generateLicenseReport")) {
        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()
        }
    }
}

// If you are running a JRuby snapshot we will skip the integrity check.
verifyFile.onlyIf { doChecksum }
bootstrap.dependsOn installTestGems

runIntegrationTests.shouldRunAfter tasks.getByPath(":logstash-core:test")
check.dependsOn runIntegrationTests


String elasticsearchSnapshotURL = System.getenv("ELASTICSEARCH_SNAPSHOT_URL") ?: "https://snapshots.elastic.co/downloads/elasticsearch/elasticsearch-${version}-SNAPSHOT.tar.gz"
String elasticsearchDownloadLocation = "${projectDir}/build/elasticsearch-${version}-SNAPSHOT.tar.gz"

task downloadEs(type: Download) {
    description "Download ES Snapshot for current branch version: ${version}"
    src elasticsearchSnapshotURL
    onlyIfNewer true
    inputs.file("${projectDir}/versions.yml")
    outputs.file(elasticsearchDownloadLocation)
    dest new File(elasticsearchDownloadLocation)
    doLast {
        System.out.println "Downloaded to ${elasticsearchDownloadLocation}"
    }
}

task deleteLocalEs(type: Delete) {
    delete ('./build/elasticsearch')
}

task copyEs(type: Copy, dependsOn: [downloadEs, deleteLocalEs]) {
    from tarTree(resources.gzip(elasticsearchDownloadLocation))
    into "./build/"
    doLast {
        file("./build/elasticsearch-${version}-SNAPSHOT").renameTo('./build/elasticsearch')
    }
}

Boolean oss = System.getenv('OSS').equals('true')

if (!oss) {
  project(":logstash-xpack") {
    ["rubyTests", "rubyIntegrationTests", "test"].each { tsk ->
      tasks.getByPath(":logstash-xpack:" + tsk).configure {
        dependsOn bootstrap
      }
    }
    tasks.getByPath(":logstash-xpack:rubyIntegrationTests").configure {
      dependsOn copyEs
    }
  }

  task runXPackUnitTests(dependsOn: [tasks.getByPath(":logstash-xpack:rubyTests")]) {}
  task runXPackIntegrationTests(dependsOn: [tasks.getByPath(":logstash-xpack:rubyIntegrationTests")]) {}
}