forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
235 lines (200 loc) · 8.22 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
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.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"
}
task bootstrap {}
project(":logstash-core") {
["rubyTests", "test"].each { tsk ->
tasks.getByPath(":logstash-core:" + tsk).configure {
dependsOn bootstrap
}
}
}
task downloadJRuby(type: Download) {
description "Download JRuby artifact from this specific URL: ${jRubyURL}"
src jRubyURL
onlyIfNewer true
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"
src new File("${projectDir}/vendor/_/jruby-bin-${jRubyVersion}.tar.gz")
algorithm 'SHA-1'
checksum jRubySha1
}
task downloadAndInstallJRuby(dependsOn: verifyFile, type: Copy) {
description "Install JRuby in the vendor directory"
inputs.files file("${projectDir}/versions.yml")
outputs.files fileTree("${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"
}
def jrubyBin = "${projectDir}/vendor/jruby/bin/jruby" +
(System.getProperty("os.name").startsWith("Windows") ? '.bat' : '')
def rakeBin = "${projectDir}/vendor/jruby/bin/rake"
task installTestGems(dependsOn: downloadAndInstallJRuby, type: Exec) {
workingDir projectDir
inputs.files file("${projectDir}/Gemfile.template")
inputs.files fileTree("${projectDir}/rakelib")
inputs.files file("${projectDir}/versions.yml")
outputs.files file("${projectDir}/Gemfile")
outputs.files file("${projectDir}/Gemfile.lock")
outputs.files fileTree("${projectDir}/vendor/bundle/gems")
outputs.files fileTree("${projectDir}/vendor/jruby")
// Override z_rubycheck.rb because we execute the vendored JRuby and don't have to guard against
// any Ruby environment leaking into the build
environment "USE_RUBY", "1"
standardOutput = new ExecLogOutputStream(System.out)
errorOutput = new ExecLogOutputStream(System.err)
commandLine jrubyBin, rakeBin, "test:install-core"
}
task assembleTarDistribution(dependsOn: installTestGems, type: Exec) {
workingDir projectDir
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")
standardOutput = new ExecLogOutputStream(System.out)
errorOutput = new ExecLogOutputStream(System.err)
commandLine jrubyBin, rakeBin, "artifact:tar"
}
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 bundleBin = "${projectDir}/vendor/bundle/jruby/2.3.0/bin/bundle"
def gemPath = "${buildDir}/qa/integration/gems"
task installIntegrationTestBundler(dependsOn: unpackTarDistribution, type: Exec) {
outputs.files fileTree("${gemPath}/gems/bundler-1.16.0")
environment "GEM_PATH", gemPath
environment "GEM_HOME", gemPath
standardOutput = new ExecLogOutputStream(System.out)
errorOutput = new ExecLogOutputStream(System.err)
commandLine jrubyBin, "${projectDir}/vendor/jruby/bin/gem", "install", "bundler", "-v", "1.16.0"
}
task installIntegrationTestGems(dependsOn: installIntegrationTestBundler, type: Exec) {
workingDir "${projectDir}/qa/integration"
environment "GEM_PATH", gemPath
environment "GEM_HOME", gemPath
inputs.files file("${projectDir}/qa/integration/Gemfile")
inputs.files file("${logstashBuildDir}/Gemfile")
inputs.files file("${logstashBuildDir}/Gemfile.lock")
inputs.files file("${logstashBuildDir}/logstash-core/logstash-core.gemspec")
inputs.files file("${projectDir}/qa/integration/integration_tests.gemspec")
outputs.files fileTree("${gemPath}/gems")
outputs.files file("${projectDir}/qa/integration/Gemfile.lock")
standardOutput = new ExecLogOutputStream(System.out)
errorOutput = new ExecLogOutputStream(System.err)
commandLine jrubyBin, bundleBin, "install"
}
def rubyIntegrationSpecs = project.hasProperty("rubyIntegrationSpecs") ? ((String) project.property("rubyIntegrationSpecs")).split(/\s+/) : []
task runIntegrationTests(dependsOn: installIntegrationTestGems, type: Exec) {
workingDir "${projectDir}/qa/integration"
environment "JAVA_OPTS", ""
environment "GEM_PATH", gemPath
environment "GEM_HOME", gemPath
// 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)
commandLine([jrubyBin, bundleBin, "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