-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
261 lines (224 loc) · 10.2 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
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch 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.
*/
import org.elasticsearch.gradle.MavenFilteringHack
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.test.RestIntegTestTask
version = '0.5'
ext.versions = [
elasticsearch: '5.4.0'
]
buildscript {
repositories {
jcenter()
maven {
url "https://artifacts.elastic.co/maven"
}
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.elasticsearch.gradle:build-tools:5.4.0"
classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0"
}
}
// Hack to restore the original test task from the java plugin, which has been removed by Elasticsearch build-tools
def restoreJavaPluginTestTask(Project project, JavaPluginConvention pluginConvention) {
def oldTestTask = project.tasks.findByPath('test')
if (oldTestTask == null) {
// no test task, ok, user will use testing task on their own
return
}
tasks.remove(oldTestTask)
Map properties = [
name : 'test',
type : Test.class,
dependsOn : oldTestTask.dependsOn,
group : JavaBasePlugin.VERIFICATION_GROUP,
description: 'Runs regular unit tests'
]
Test testTask = project.tasks.create(properties);
testTask.classpath = oldTestTask.classpath
testTask.testClassesDir = oldTestTask.testClassesDir
testTask.exclude('**/*IT*')
Task checkTask = project.tasks.findByPath('check')
checkTask.dependsOn.remove(oldTestTask)
checkTask.dependsOn.add(testTask)
}
apply plugin: 'elasticsearch.build'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'com.github.hierynomus.license'
restoreJavaPluginTestTask(project, project.convention.plugins.java)
license {
header rootProject.file('LICENSE-header.txt')
strictCheck true
mapping {
java = 'SLASHSTAR_STYLE'
}
}
repositories {
jcenter()
mavenCentral()
maven {
url "https://artifacts.elastic.co/maven"
}
}
configurations {
// exclude securemock which is a repackaged mockito 1.x that conflict with this project's version of mockito
testCompile.exclude group: 'org.elasticsearch', module: 'securemock'
// hacks to re-enable transitive dependencies for tests, otherwise you have to declare everything
testCompile.dependencies.all { dep ->
if (dep.group.startsWith('org.mockito') || dep.group.startsWith('com.github.tomakehurst')) {
dep.transitive = true
}
}
// ugly hack to force wiremock dependency versions
all {
resolutionStrategy {
force "com.google.guava:guava:18.0"
force "com.fasterxml.jackson.core:jackson-core:2.8.6"
force "com.fasterxml.jackson.core:jackson-databind:2.8.6"
force "com.fasterxml.jackson.core:jackson-annotations:2.8.6"
force "net.sf.jopt-simple:jopt-simple:5.0.2"
force "org.apache.commons:commons-lang3:3.5"
force "junit:junit:4.12"
force "org.apache.httpcomponents:httpclient:4.5.2"
force "org.apache.httpcomponents:httpcore:4.4.5"
force "commons-logging:commons-logging:1.2"
force "commons-codec:commons-codec:1.10"
force "org.slf4j:slf4j-api:1.7.12"
// force accessors-smart 1.2, because accessors-smart 1.1 shadows asm as well which was causing jarHell task to scream
force "net.minidev:accessors-smart:1.2"
}
}
}
dependencies {
// note, elasticsearch disable by default transitive dependencies
compile "com.squareup.okhttp3:okhttp:3.8.0"
compile "com.squareup.okio:okio:1.13.0"
provided "org.apache.logging.log4j:log4j-api:2.8.2"
provided "org.elasticsearch:elasticsearch:${versions.elasticsearch}"
provided "org.elasticsearch.plugin:x-pack-api:${versions.elasticsearch}"
provided "org.elasticsearch:jna:4.4.0"
testCompile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
testCompile "org.mockito:mockito-core:2.8.9"
testCompile "org.assertj:assertj-core:3.7.0"
testCompile "com.fasterxml.jackson.core:jackson-core:2.8.6"
testCompile "com.fasterxml.jackson.core:jackson-databind:2.8.6"
testCompile "com.fasterxml.jackson.core:jackson-annotations:2.8.6"
testCompile "org.apache.commons:commons-lang3:3.5"
testCompile "com.github.tomakehurst:wiremock:2.6.0"
testRuntime "org.elasticsearch.plugin:x-pack:${versions.elasticsearch}@zip"
}
Map generateSubstitutions() {
def stringSnap = { version ->
if (version.endsWith("-SNAPSHOT")) {
return version.substring(0, version.length() - 9)
}
return version
}
return [
'version' : stringSnap(version),
'xpack.version': stringSnap(VersionProperties.elasticsearch),
'java.version' : targetCompatibility as String,
]
}
// Disabling Elasticsearch imported tasks that I'd like to avoid because too cumbersome
copyCheckstyleConf.enabled false
checkstyleMain.enabled false
checkstyleTest.enabled false
forbiddenApisTest.enabled false
dependencyLicenses.enabled false
namingConventions.enabled false
thirdPartyAudit.enabled false
ext.integrationProperties = [
'integ.idp.port': 9201,
'integ.es.http.port': 9400,
'integ.es.transport.port': 9500,
'integ.es.num.nodes': 1
]
processResources {
MavenFilteringHack.filter(it, generateSubstitutions())
}
processTestResources {
MavenFilteringHack.filter(it, integrationProperties)
}
task buildZip(type: Zip, dependsOn: [jar]) {
from 'build/resources/main/x-pack-extension-descriptor.properties'
from 'build/resources/main/x-pack-extension-security.policy'
from configurations.compile - configurations.provided
from project.jar
archiveName "${project.name}-${project.version}-xpack_${versions.elasticsearch}.zip"
}
RestIntegTestTask integTest = project.tasks.create('integTest', RestIntegTestTask.class) {
runner.systemProperty 'tests.security.manager', 'false'
}
integTest.dependsOn(project.buildZip)
integTest.mustRunAfter(project.precommit, project.test)
project.check.dependsOn(integTest)
integTestCluster {
// Cluster is created in 'build/cluster/integTestCluster node0/'
// See
// - org.elasticsearch.gradle.test.ClusterConfiguration
// - org.elasticsearch.gradle.test.ClusterFormationTasks
numNodes integrationProperties['integ.es.num.nodes']
httpPort integrationProperties['integ.es.http.port']
transportPort integrationProperties['integ.es.transport.port']
// allow debugging when passing -Pdebug=true on the command line
// if true, adds -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000
debug findProperty("debug") == 'true'
extraConfigFile 'x-pack/oauth_role_mapping.yml', file('build/resources/test/oauth_role_mapping.yml')
extraConfigFile 'x-pack/roles.yml', file('build/resources/test/roles.yml')
setting "xpack.monitoring.enabled", "false" // monitoring depends on painless which is not available to us
setting "xpack.ml.enabled", "false"
// ml has named writeables and the check for cluster state consistency doesn't know about them
setting "xpack.security.authc.realms.oauth-integ.order", "0"
setting "xpack.security.authc.realms.oauth-integ.type", "oauth"
setting "xpack.security.authc.realms.oauth-integ.files.role_mapping", "config/x-pack/oauth_role_mapping.yml"
setting "xpack.security.authc.realms.oauth-integ.token-info.url", "http://localhost:${integrationProperties['integ.idp.port']}/nidp/oauth/nam/tokeninfo"
setting "xpack.security.authc.realms.oauth-integ.idp.connection-timeout-in-millis", "10000"
setting "xpack.security.authc.realms.oauth-integ.idp.read-timeout-in-millis", "10000"
setting "xpack.security.authc.realms.oauth-integ.idp.write-timeout-in-millis", "10000"
setting "xpack.security.authc.realms.oauth-integ.token-info.field.user", "user_id"
setting "xpack.security.authc.realms.oauth-integ.token-info.field.scope", "scope"
setting "xpack.security.authc.realms.oauth-integ.token-info.field.expires-in", "expires_in"
setting "xpack.security.authc.realms.oauth-integ.token-info.field.expires-in.unit", "SECONDS"
setting "xpack.security.authc.realms.file.order", "1"
setting "xpack.security.authc.realms.file.type", "file"
// see https://www.elastic.co/guide/en/x-pack/current/auditing.html
setting "xpack.security.audit.enabled", "true"
setting "xpack.security.audit.logfile.events.include", [ "access_denied", "access_granted", "anonymous_access_denied", "authentication_failed", "connection_denied", "tampered_request", "run_as_denied", "run_as_granted" ]
setupCommand 'installXPackPlugin',
'bin/elasticsearch-plugin', 'install', configurations.testRuntime.filter { File file -> file.getName().equals("x-pack-${versions.elasticsearch}.zip".toString()) }.getSingleFile().toURI().toString()
setupCommand 'setupDummyUser',
'bin/x-pack/users', 'useradd', 'admin_user', '-p', 'changeme', '-r', 'superuser'
setupCommand 'installExtension',
'bin/x-pack/extension', 'install', 'file:' + buildZip.archivePath
waitCondition = { node, ant ->
File tmpFile = new File(node.cwd, 'wait.success')
ant.get(src: "http://${node.httpUri()}",
dest: tmpFile.toString(),
username: 'admin_user',
password: 'changeme',
ignoreerrors: true,
retries: 10)
return tmpFile.exists()
}
}