forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
255 lines (218 loc) · 8.99 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
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.yaml:snakeyaml:1.17'
}
}
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.ExecLogOutputStream
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))
}
}
}
}
}
// 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"
}
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 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}/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")
outputs.files file("${buildDir}/logstash-${project.version}.tar.gz")
doLast {
rubyGradleUtils.rake('artifact:tar')
}
}
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")
outputs.files file("${buildDir}/logstash-${project.version}.zip")
doLast {
rubyGradleUtils.rake('artifact:zip')
}
}
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, type: Exec) {
outputs.files fileTree("${qaBundledGemPath}/gems/bundler-1.16.0")
standardOutput = new ExecLogOutputStream(System.out)
errorOutput = new ExecLogOutputStream(System.err)
// directly invoke bin/gem to install bundlers and force install dir "-i" into qaBundledGemPath
commandLine "${projectDir}/vendor/jruby/bin/gem", "install", "bundler", "-v", "1.16.0", "-i", qaBundledGemPath
}
task installIntegrationTestGems(dependsOn: installIntegrationTestBundler, type: Exec) {
workingDir "${projectDir}/qa/integration"
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")
standardOutput = new ExecLogOutputStream(System.out)
errorOutput = new ExecLogOutputStream(System.err)
// directly invoke bin/bundler and force install gem path to qaVendorPath
// note that bundler appends jruby/2.3.0 to the install path
commandLine qaBundleBin, "install", "--path", qaVendorPath
}
def rubyIntegrationSpecs = project.hasProperty("rubyIntegrationSpecs") ? ((String) project.property("rubyIntegrationSpecs")).split(/\s+/) : []
def rubyBin = "${projectDir}" +
(System.getProperty("os.name").startsWith("Windows") ? '/vendor/jruby/bin/jruby.bat' : '/bin/ruby')
task runIntegrationTests(dependsOn: installIntegrationTestGems, type: Exec) {
workingDir "${projectDir}/qa/integration"
environment "LS_GEM_PATH", qaBundledGemPath
environment "LS_GEM_HOME", qaBundledGemPath
// FEATURE_FLAG is set in the CI to configure testing with enabled PQ
environment "FEATURE_FLAG", System.getenv('FEATURE_FLAG')
standardOutput = new ExecLogOutputStream(System.out)
errorOutput = new ExecLogOutputStream(System.err)
// indirect launching of bin/bundle via bin/ruby so that the bundle exec command inherit
// the correct gem path environment which is not settable by command line
commandLine([rubyBin, qaBundleBin, "exec", "rspec"].plus((Collection<String>)rubyIntegrationSpecs))
}
// 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