forked from opendistro-for-elasticsearch/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
319 lines (266 loc) · 12.3 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
/*
* 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 {
// When upgrading to version after 7.3.0, must remove also
// project substitution from configurations.all (line 39)
es_version = System.getProperty("es.version", "7.4.2")
}
// This isn't applying from repositories.gradle so repeating it here
repositories {
mavenCentral()
}
dependencies {
classpath "org.elasticsearch.gradle:build-tools:${es_version}"
}
}
plugins {
id 'nebula.ospackage' version "5.3.0"
id 'java-library'
id 'checkstyle'
id "io.freefair.lombok" version "4.1.2"
}
/*
Temporary fix, must be removed after 7.3.0 See
https://github.com/elastic/elasticsearch/issues/45073
Also must remove include ':rest-api-spec' from settings.gradle
*/
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute project(':rest-api-spec') with module ("org.elasticsearch:rest-api-spec:${es_version}")
}
}
// Repository on root level is for dependencies that project code depends on. And this block must be placed after plugins{}
repositories {
mavenCentral() // For Elastic Libs that you can use to get started coding until open ES libs are available
}
ext {
opendistroVersion = '1.4.0'
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
}
version = "${opendistroVersion}.0"
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'jacoco'
if (!System.properties.containsKey('tests.rest.cluster') && !System.properties.containsKey('tests.cluster')){
apply from: 'build-tools/sqlplugin-coverage.gradle'
}
apply plugin: 'antlr'
jacoco {
toolVersion = "0.8.3"
}
ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.TXT')
noticeFile = rootProject.file('NOTICE')
}
// ANTLR generated parser file is too large to be checked which caused licenseHeaders stuck.
licenseHeaders {
enabled = true
excludes = ['com/amazon/opendistroforelasticsearch/sql/antlr/parser/**']
}
// TODO: need to fix java doc to enable JavaDoc
javadoc.enabled = false
esplugin {
name 'opendistro_sql' // zip file name and plugin name in ${elasticsearch.plugin.name} read by ES when plugin loading
description 'Open Distro for Elasticsearch SQL'
classname 'com.amazon.opendistroforelasticsearch.sql.plugin.SqlPlug'
licenseFile rootProject.file("LICENSE.txt")
noticeFile rootProject.file("NOTICE")
}
// Set source and target to be compatible with Java 8
// Commented them out as the default is java 8
// sourceCompatibility = '1.8'
// targetCompatibility = '1.8'
// TODO: fix compiler warnings
compileJava.options.warnings = false
compileJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
doFirst {
// TODO: do not fail build on warnings, need to fix all compiler warnings
options.compilerArgs.remove('-Werror')
// TODO: need to fix all java doc format
options.compilerArgs.remove('-Xdoclint:all')
}
}
// TODO: Similarly, need to fix compiling errors in test source code
compileTestJava.options.warnings = false
compileTestJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
doFirst {
options.compilerArgs.remove('-Werror')
options.compilerArgs.remove('-Xdoclint:all')
}
}
// TODO: Need to update integration test to use ElasticSearch test framework
test {
include '**/*Test.class'
exclude 'com/amazon/opendistroforelasticsearch/sql/intgtest/**'
// Gradle runs unit test using a working directory other and project root
// set 'project.root' property to allow unit test classes to access test resources
systemProperty('project.root', project.rootDir.absolutePath)
}
integTestRunner {
// add "-Dtests.security.manager=false" to VM options if you want to run integ tests in IntelliJ
systemProperty 'tests.security.manager', 'false'
// allows integration test classes to access test resource from project root path
systemProperty('project.root', project.rootDir.absolutePath)
// Tell the test JVM if the cluster JVM is running under a debugger so that tests can use longer timeouts for
// requests. The 'doFirst' delays reading the debug setting on the cluster till execution time.
doFirst { systemProperty 'cluster.debug', integTestCluster.debug }
// The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable
if (System.getProperty("test.debug") != null) {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
}
// Run different task based on test type. "exclude" is required for each task.
def testType = System.getProperty("testType")
if (testType == 'doctest') { // Doctest to generate documentation
include 'com/amazon/opendistroforelasticsearch/sql/doctest/**/*IT.class'
exclude 'com/amazon/opendistroforelasticsearch/sql/correctness/**'
exclude 'com/amazon/opendistroforelasticsearch/sql/esintgtest/**'
} else if (testType == 'comparison') { // Comparision testing
include 'com/amazon/opendistroforelasticsearch/sql/correctness/CorrectnessIT.class'
exclude 'com/amazon/opendistroforelasticsearch/sql/doctest/**'
exclude 'com/amazon/opendistroforelasticsearch/sql/esintgtest/**'
// Enable logging output to console
testLogging.showStandardStreams true
// Pass down system properties to IT class
systemProperty "esHost", System.getProperty("esHost")
systemProperty "dbUrl", System.getProperty("dbUrl")
systemProperty "otherDbUrls", System.getProperty("otherDbUrls")
systemProperty "queries", System.getProperty("queries")
} else { // Run all other integration tests. Skip doctest for now due to randomness in our stats API.
include 'com/amazon/opendistroforelasticsearch/sql/esintgtest/**/*IT.class'
exclude 'com/amazon/opendistroforelasticsearch/sql/doctest/**/*IT.class'
exclude 'com/amazon/opendistroforelasticsearch/sql/correctness/**'
}
}
integTestCluster {
// use elasticsearch oss distribution for integration test.
distribution = "oss-zip"
}
run {
distribution = "oss-zip"
}
generateGrammarSource {
arguments += ['-visitor', '-package', 'com.amazon.opendistroforelasticsearch.sql.antlr.parser']
source = sourceSets.main.antlr
outputDirectory = file("build/generated-src/antlr/main/com/amazon/opendistroforelasticsearch/sql/antlr/parser")
}
// Remove ANTLR plugin jars as it's specified as 'compile' dependency internally
configurations {
compile {
extendsFrom = extendsFrom.findAll { it != configurations.antlr }
}
}
check.dependsOn jacocoTestReport
// TODO: fix code style in main and test source code
checkstyle {
configFile file("config/checkstyle/checkstyle.xml")
}
checkstyleMain.ignoreFailures = false
checkstyleTest.ignoreFailures = true
// TODO: fix forbidden APIs
// from police-man plugin, see https://github.com/policeman-tools/forbidden-apis/wiki/GradleUsage
forbiddenApis.ignoreFailures = true
// TODO: fix forbidden code patterns
// introduced by elasticsearch plugin
// see https://github.com/elastic/elasticsearch/blob/master/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/ForbiddenPatternsTask.java
forbiddenPatterns {
setEnabled(false)
}
// TODO: fix license. skip dependency license checks
dependencyLicenses.enabled = false
// We don't need to follow ES testing naming conventions.
// see https://github.com/elastic/elasticsearch/blob/323f312bbc829a63056a79ebe45adced5099f6e6/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/TestingConventionsTasks.java
// enable testingConventions check will cause errors like: "Classes ending with [Tests] must subclass [LuceneTestCase]"
testingConventions.enabled = false
// TODO: need to verify the thirdPartyAudi
// currently it complains missing classes like ibatis, mysql etc, should not be a problem
thirdPartyAudit.enabled = false
//****************************************************************************/
// Dependencies
//****************************************************************************/
dependencies {
compile group: 'com.alibaba', name: 'druid', version:'1.0.15'
compile group: 'org.locationtech.spatial4j', name: 'spatial4j', version:'0.7'
compile group: "org.elasticsearch.plugin", name: 'parent-join-client', version: "${es_version}"
compile group: "org.elasticsearch.plugin", name: 'reindex-client', version: "${es_version}"
compile group: 'com.google.guava', name: 'guava', version:'15.0'
compile group: 'org.json', name: 'json', version:'20180813'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
// ANTLR gradle plugin and runtime dependency
antlr "org.antlr:antlr4:4.7.1"
compile "org.antlr:antlr4-runtime:4.7.1"
//compileOnly group: 'org.locationtech.jts', name: 'jts-core', version:'1.15.0'
// compileOnly group: 'org.elasticsearch', name: 'elasticsearch', version:'6.5.3'
// compileOnly group: 'com.unboundid', name: 'unboundid-ldapsdk', version:'3.2.0'
// compileOnly group: 'org.bouncycastle', name: 'bcprov-jdk15on', version:'1.58'
// compileOnly group: 'log4j', name: 'log4j', version:'1.2.17'
// compileOnly group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.7'
// compileOnly group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.7'
compileOnly group: 'javax.servlet', name: 'servlet-api', version:'2.5'
// testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
// testCompile group: 'junit', name: 'junit', version:'4.11'
// testCompile group: 'com.alibaba', name: 'fastjson', version:'1.2.56'
// testCompile group: 'org.mockito', name: 'mockito-core', version:'2.23.4'
testCompile group: "org.elasticsearch.client", name: 'transport', version: "${es_version}"
// JDBC drivers for comparison test. Somehow Apache Derby throws security permission exception.
testCompile group: 'com.amazon.opendistroforelasticsearch.client', name: 'opendistro-sql-jdbc', version: '1.3.0.0'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
testCompile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
//testCompile group: 'org.apache.derby', name: 'derby', version: '10.15.1.3'
}
apply plugin: 'nebula.ospackage'
// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
afterEvaluate {
ospackage {
packageName = "${name}"
release = isSnapshot ? "0.1" : '1'
version = "${project.version}" - "-SNAPSHOT"
into '/usr/share/elasticsearch/plugins'
from(zipTree(bundlePlugin.archivePath)) {
into esplugin.name
}
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/elasticsearch/downloads'
summary '''
SQL 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'
archiveName "${packageName}-${version}.rpm"
dependsOn 'assemble'
}
buildDeb {
arch = 'amd64'
archiveName "${packageName}-${version}.deb"
dependsOn 'assemble'
}
task buildPackages(type: GradleBuild) {
tasks = ['build', 'buildRpm', 'buildDeb']
}
}