-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
335 lines (289 loc) · 10.9 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
/*
* Copyright <2019> Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file 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 {
ext {
es_version = System.getProperty("es.version", "7.3.2")
}
// This isn't applying from repositories.gradle so repeating it here
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath "org.elasticsearch.gradle:build-tools:${es_version}"
classpath 'org.ajoberstar:gradle-git:0.2.3'
}
}
plugins {
id 'java'
id 'nebula.ospackage' version "8.2.0"
id 'com.github.spotbugs' version '4.0.0'
}
spotbugsMain {
excludeFilter = file("checkstyle/findbugs-exclude.xml")
effort = 'max'
ignoreFailures = false
reports {
xml.enabled = false
html.enabled = true
}
}
spotbugsTest {
ignoreFailures = true
}
ext {
opendistroVersion = '1.10.0'
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
}
group = "com.amazon.opendistroforelasticsearch"
version = "${opendistroVersion}.0"
if (isSnapshot) {
version += "-SNAPSHOT"
}
apply plugin: 'elasticsearch.esplugin'
ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
}
test {
enabled = true
}
licenseHeaders.enabled = false
esplugin {
name 'opendistro_performance_analyzer'
description 'Performance Analyzer Plugin'
classname 'com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerPlugin'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava {
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility);
if (targetVersion.isJava9Compatible()) {
options.compilerArgs += ["--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED"]
}
}
javadoc {
options.addStringOption("-add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED")
}
project.afterEvaluate {
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility)
// cannot contain the first version
// should be '8' or '11' etc.
String version = targetVersion.toString()
if (version.length() > 2) {
version = targetVersion.toString().substring(2)
}
compileJava.options.compilerArgs.removeAll(['--release', version])
}
repositories {
mavenCentral()
mavenLocal()
}
configurations {
includeJars
}
tasks.withType(JavaCompile) {
options.warnings = false
}
dependencies {
if (JavaVersion.current() <= JavaVersion.VERSION_1_8) {
compile files("${System.properties['java.home']}/../lib/tools.jar")
}
configurations {
// jarHell reports class name conflicts between securemock and mockito-core
// has to disable one of them.
all*.exclude group: "org.elasticsearch", module: "securemock"
}
compile 'com.google.guava:guava:27.0.1-jre'
compile 'org.jooq:jooq:3.10.8'
compile 'org.apache.commons:commons-lang3:3.6'
compile 'org.bouncycastle:bcprov-jdk15on:1.60'
compile 'org.bouncycastle:bcpkix-jdk15on:1.60'
compile 'com.amazon.opendistro.elasticsearch:performanceanalyzer-rca:1.10'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.11'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.11'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.11'
// JDK9+ has to run powermock 2+. https://github.com/powermock/powermock/issues/888
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.0'
testCompile group: 'org.powermock', name: 'powermock-core', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.0'
testCompile group: 'org.javassist', name: 'javassist', version: '3.24.0-GA'
testCompile group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0'
testCompile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.3'
testCompile group: 'org.objenesis', name: 'objenesis', version: '3.0.1'
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
}
dependencyLicenses {
mapping from: /jackson-.*/, to: 'jackson'
}
dependencyLicenses.doFirst {
updateShas.updateShas()
}
bundlePlugin {
from ("pa_config") {
into "pa_config"
}
from ("pa_bin") {
into "pa_bin"
include "performance-analyzer-agent"
}
from ("pa_bin") {
into "extensions"
include "performance-analyzer-agent"
}
from ('build/resources/main/') {
include "plugin-security.policy"
}
exclude ('tools.jar')
from ("config/opendistro_performance_analyzer") {
into "config"
}
}
gradle.startParameter.excludedTaskNames += [ "forbiddenApisMain",
"forbiddenApisTest",
"thirdPartyAudit",
"testingConventions"]
import java.nio.file.Paths
import org.ajoberstar.gradle.git.tasks.GitClone
String rcaDir
static def propEnabled(property) {
return System.getProperty(property) != null && System.getProperty(property).toLowerCase().equals("true")
}
// The following Gradle tasks are used to create a PA/RCA enabled Elasticsearch cluster
// Pass the -Dtests.enableIT property to Gradle to run ITs
/**
* cloneGitRepo clones the performance-analyzer-rca repo if the -Dtests.enableIT=true flag is passed
* to the Gradle JVM
*/
task cloneGitRepo(type: GitClone) {
onlyIf = {
propEnabled("tests.enableIT")
}
rcaDir = Paths.get(getProject().getBuildDir().toString(), "performance-analyzer-rca").toString()
def destination = file(rcaDir)
uri = "https://github.com/opendistro-for-elasticsearch/performance-analyzer-rca.git"
destinationPath = destination
bare = false
enabled = !destination.exists() // to clone only once
}
/**
* setupESCluster spins up a local 2 node ES cluster using the enableRca task in the performance-analyzer-rca
* repo. The performance-analyzer-rca repo is cloned as part of the cloneGitRepo task.
*/
task setupEsCluster() {
dependsOn(cloneGitRepo)
onlyIf = {
propEnabled("tests.enableIT")
}
doLast {
exec {
workingDir(rcaDir)
commandLine './gradlew', 'enableRca'
}
sleep(5000)
}
}
/**
* integTestRunner is a task provided by the ES test framework, which allows us to spin up clients
* and test API calls against a local or remote Elasticsearch cluster.
*
* The simplest way to run this task in a way that "just works" is to invoke
* ./gradlew integTest -Dtests.enableIT=true -Dtests.useDockerCluster=true
* which will spin up a local 2 node ES cluster on your machine, then execute the test suite against it
*
* A full list of options is provided below. Check our gradle.properties file for the defaults for
* each of these properties.
*
* -Dtests.rest.cluster the Elasticsearch REST endpoint that test clients should hit
* -Dtests.cluster the Elasticsearch <a href="https://discuss.elastic.co/t/transport-client-vs-rest-client/13936">transport</a>
* endpoint that test clients should hit
* -Dtests.enableIT a flag to enable integration testing, by default this is false
* -Dtests.useDockerCluster if true, spin up a local 2 node cluster before executing tests
* NOTE: if you specify this, don't specify -Dtests.rest.cluster or -Dtests.cluster
* -Dtests.pa.port the port number of the PerformanceAnalyzer REST endpoint
* -Dtests.https either true or false, if true, then instantiate REST and transport clients using
* the https:// protocol and basic authentication via the -Dtests.user and -Dtests.password properties
* -Dtests.user the username of the admin user, this is used in conjunction with -Dtests.https and
* -Dtests.password to authenticate requests in the opendistro-security context
* -Dtests.password the password of the admin user specified by -Dtests.user
*/
integTestRunner {
onlyIf = {
propEnabled("tests.enableIT")
}
// add "-Dtests.security.manager=false" to VM options if you want to run integ tests in IntelliJ
systemProperty 'tests.security.manager', 'false'
if (propEnabled("tests.useDockerCluster")) {
dependsOn(setupEsCluster)
}
}
// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
afterEvaluate {
ospackage {
packageName = "opendistro-performance-analyzer"
release = isSnapshot ? "0.1" : '1'
version = "${project.version}" - "-SNAPSHOT"
into '/usr/share/elasticsearch/plugins'
from(zipTree(bundlePlugin.archivePath)) {
into esplugin.name
}
configurationFile '/usr/lib/systemd/system/opendistro-elasticsearch.service'
into('/usr/lib/systemd/system') {
fileType CONFIG | NOREPLACE
from "packaging/opendistro-performance-analyzer.service"
fileMode 0644
}
into('/usr/share/elasticsearch/bin') {
from ('packaging/performance-analyzer-agent-cli') {
fileMode 0755
}
}
user 'root'
permissionGroup 'root'
fileMode 0644
dirMode 0755
requires('elasticsearch-oss', versions.elasticsearch, EQUAL)
packager = 'Amazon'
vendor = 'Amazon'
os = 'LINUX'
prefix '/usr'
license 'ASL-2.0'
maintainer 'OpenDistro for Elasticsearch Team <[email protected]>'
url 'https://opendistro.github.io/for-elasticsearch/downloads.html'
summary '''
Performance Analyzer plugin for OpenDistro for Elasticsearch.
Reference documentation can be found at https://opendistro.github.io/for-elasticsearch-docs/.
'''.stripIndent().replace('\n', ' ').trim()
}
buildRpm {
arch = 'NOARCH'
postInstall file('packaging/rpm/postinst')
archiveName "${packageName}-${version}.rpm"
dependsOn 'assemble'
}
buildDeb {
arch = 'amd64'
postInstall file('packaging/deb/postinst')
archiveName "${packageName}-${version}.deb"
dependsOn 'assemble'
}
task buildPackages(type: GradleBuild) {
tasks = ['build', 'buildRpm', 'buildDeb']
}
}