2021-04-09 15:28:18 -04:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* The OpenSearch Contributors require contributions made to
|
|
|
|
* this file be licensed under the Apache-2.0 license or a
|
|
|
|
* compatible open source license.
|
|
|
|
*
|
|
|
|
* Modifications Copyright OpenSearch Contributors. See
|
|
|
|
* GitHub history for details.
|
|
|
|
*/
|
|
|
|
|
2015-12-09 19:32:37 -05:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-04-22 15:14:03 -04:00
|
|
|
|
2021-03-10 10:15:44 -05:00
|
|
|
import org.opensearch.gradle.testclusters.DefaultTestClustersTask;
|
|
|
|
apply plugin: 'opensearch.validate-rest-spec'
|
|
|
|
apply plugin: 'opensearch.yaml-rest-test'
|
2019-11-14 06:01:23 -05:00
|
|
|
|
2021-03-18 19:14:19 -04:00
|
|
|
opensearchplugin {
|
2021-03-10 10:15:44 -05:00
|
|
|
description 'An easy, safe and fast scripting language for OpenSearch'
|
|
|
|
classname 'org.opensearch.painless.PainlessPlugin'
|
2015-12-09 19:32:37 -05:00
|
|
|
}
|
|
|
|
|
2020-07-13 14:53:05 -04:00
|
|
|
testClusters.all {
|
2020-09-03 22:26:44 -04:00
|
|
|
module ':modules:mapper-extras'
|
2021-03-18 16:19:22 -04:00
|
|
|
systemProperty 'opensearch.scripting.update.ctx_in_params', 'false'
|
2019-08-16 12:40:04 -04:00
|
|
|
// TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
|
2021-03-18 16:19:22 -04:00
|
|
|
systemProperty 'opensearch.transport.cname_in_publish_address', 'true'
|
2017-09-13 11:58:53 -04:00
|
|
|
}
|
|
|
|
|
2015-12-09 19:32:37 -05:00
|
|
|
dependencies {
|
2020-06-30 09:57:41 -04:00
|
|
|
api 'org.antlr:antlr4-runtime:4.5.3'
|
|
|
|
api 'org.ow2.asm:asm-util:7.2'
|
|
|
|
api 'org.ow2.asm:asm-tree:7.2'
|
|
|
|
api 'org.ow2.asm:asm-commons:7.2'
|
|
|
|
api 'org.ow2.asm:asm-analysis:7.2'
|
|
|
|
api 'org.ow2.asm:asm:7.2'
|
|
|
|
api project('spi')
|
2015-12-28 22:38:55 -05:00
|
|
|
}
|
|
|
|
|
2020-06-18 02:15:50 -04:00
|
|
|
tasks.named("dependencyLicenses").configure {
|
2015-12-28 22:38:55 -05:00
|
|
|
mapping from: /asm-.*/, to: 'asm'
|
2015-12-09 19:32:37 -05:00
|
|
|
}
|
|
|
|
|
2020-03-19 13:28:59 -04:00
|
|
|
restResources {
|
|
|
|
restApi {
|
2020-04-13 11:53:35 -04:00
|
|
|
includeCore '_common', 'cluster', 'nodes', 'indices', 'index', 'search', 'get', 'bulk', 'update',
|
2020-03-19 13:28:59 -04:00
|
|
|
'scripts_painless_execute', 'put_script', 'delete_script'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("test").configure {
|
2019-07-24 03:04:00 -04:00
|
|
|
// in WhenThingsGoWrongTests we intentionally generate an out of memory error, this prevents the heap from being dumped to disk
|
|
|
|
jvmArgs '-XX:-OmitStackTraceInFastThrow', '-XX:-HeapDumpOnOutOfMemoryError'
|
2017-05-04 13:11:09 -04:00
|
|
|
}
|
|
|
|
|
2017-01-26 10:39:19 -05:00
|
|
|
/* Build Javadoc for the Java classes in Painless's public API that are in the
|
|
|
|
* Painless plugin */
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("apiJavadoc", Javadoc) {
|
2017-01-23 17:16:20 -05:00
|
|
|
source = sourceSets.main.allJava
|
2017-08-23 01:15:15 -04:00
|
|
|
classpath = sourceSets.main.runtimeClasspath
|
2021-03-10 10:15:44 -05:00
|
|
|
include '**/org/opensearch/painless/api/'
|
2017-01-23 17:16:20 -05:00
|
|
|
destinationDir = new File(docsDir, 'apiJavadoc')
|
|
|
|
}
|
2019-04-23 12:10:47 -04:00
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("apiJavadocJar", Jar) {
|
2020-07-02 07:08:34 -04:00
|
|
|
archiveClassifier = 'apiJavadoc'
|
2017-01-23 17:16:20 -05:00
|
|
|
from apiJavadoc
|
|
|
|
}
|
2019-04-23 12:10:47 -04:00
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("assemble").configure {
|
|
|
|
dependsOn "apiJavadocJar"
|
|
|
|
}
|
2019-04-23 12:10:47 -04:00
|
|
|
/**********************************************
|
|
|
|
* Context API Generation *
|
|
|
|
**********************************************/
|
|
|
|
|
|
|
|
sourceSets {
|
|
|
|
doc
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2020-07-07 11:10:31 -04:00
|
|
|
docImplementation project(':server')
|
|
|
|
docImplementation project(':modules:lang-painless')
|
2019-04-23 12:10:47 -04:00
|
|
|
}
|
|
|
|
|
2019-10-08 07:39:58 -04:00
|
|
|
testClusters {
|
|
|
|
generateContextCluster {
|
2021-04-22 17:21:32 -04:00
|
|
|
testDistribution = 'ARCHIVE'
|
2019-10-08 07:39:58 -04:00
|
|
|
}
|
2019-04-23 12:10:47 -04:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("generateContextDoc", DefaultTestClustersTask) {
|
2020-07-16 16:03:36 -04:00
|
|
|
dependsOn sourceSets.doc.runtimeClasspath
|
2019-11-14 06:01:23 -05:00
|
|
|
useCluster testClusters.generateContextCluster
|
2019-10-08 07:39:58 -04:00
|
|
|
doFirst {
|
|
|
|
project.javaexec {
|
2021-03-10 10:15:44 -05:00
|
|
|
main = 'org.opensearch.painless.ContextDocGenerator'
|
2019-10-08 07:39:58 -04:00
|
|
|
classpath = sourceSets.doc.runtimeClasspath
|
2020-07-16 16:03:36 -04:00
|
|
|
systemProperty "cluster.uri", "${-> testClusters.generateContextCluster.singleNode().getAllHttpSocketURI().get(0)}"
|
2019-10-08 07:39:58 -04:00
|
|
|
}.assertNormalExitValue()
|
|
|
|
}
|
2017-01-26 10:39:19 -05:00
|
|
|
}
|
2017-03-24 12:44:53 -04:00
|
|
|
|
|
|
|
/**********************************************
|
|
|
|
* Parser regeneration *
|
|
|
|
**********************************************/
|
|
|
|
|
|
|
|
configurations {
|
|
|
|
regenerate
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2017-10-27 14:07:49 -04:00
|
|
|
regenerate 'org.antlr:antlr4:4.5.3'
|
2017-03-24 12:44:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
String grammarPath = 'src/main/antlr'
|
2021-03-10 10:15:44 -05:00
|
|
|
String outputPath = 'src/main/java/org/opensearch/painless/antlr'
|
2017-03-24 12:44:53 -04:00
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("cleanGenerated", Delete) {
|
2017-03-24 12:44:53 -04:00
|
|
|
delete fileTree(grammarPath) {
|
|
|
|
include '*.tokens'
|
|
|
|
}
|
|
|
|
delete fileTree(outputPath) {
|
|
|
|
include 'Painless*.java'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("regenLexer", JavaExec) {
|
|
|
|
dependsOn "cleanGenerated"
|
2017-03-24 12:44:53 -04:00
|
|
|
main = 'org.antlr.v4.Tool'
|
|
|
|
classpath = configurations.regenerate
|
|
|
|
systemProperty 'file.encoding', 'UTF-8'
|
|
|
|
systemProperty 'user.language', 'en'
|
|
|
|
systemProperty 'user.country', 'US'
|
|
|
|
systemProperty 'user.variant', ''
|
|
|
|
args '-Werror',
|
2021-03-10 10:15:44 -05:00
|
|
|
'-package', 'org.opensearch.painless.antlr',
|
2019-11-14 06:01:23 -05:00
|
|
|
'-o', outputPath,
|
|
|
|
"${file(grammarPath)}/PainlessLexer.g4"
|
2017-03-24 12:44:53 -04:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("regenParser", JavaExec) {
|
|
|
|
dependsOn "regenLexer"
|
2017-03-24 12:44:53 -04:00
|
|
|
main = 'org.antlr.v4.Tool'
|
|
|
|
classpath = configurations.regenerate
|
|
|
|
systemProperty 'file.encoding', 'UTF-8'
|
|
|
|
systemProperty 'user.language', 'en'
|
|
|
|
systemProperty 'user.country', 'US'
|
|
|
|
systemProperty 'user.variant', ''
|
|
|
|
args '-Werror',
|
2021-03-10 10:15:44 -05:00
|
|
|
'-package', 'org.opensearch.painless.antlr',
|
2019-11-14 06:01:23 -05:00
|
|
|
'-no-listener',
|
|
|
|
'-visitor',
|
|
|
|
// '-Xlog',
|
|
|
|
'-o', outputPath,
|
|
|
|
"${file(grammarPath)}/PainlessParser.g4"
|
2017-03-24 12:44:53 -04:00
|
|
|
}
|
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("regen") {
|
|
|
|
dependsOn "regenParser"
|
2017-03-24 12:44:53 -04:00
|
|
|
doLast {
|
|
|
|
// moves token files to grammar directory for use with IDE's
|
|
|
|
ant.move(file: "${outputPath}/PainlessLexer.tokens", toDir: grammarPath)
|
|
|
|
ant.move(file: "${outputPath}/PainlessParser.tokens", toDir: grammarPath)
|
|
|
|
// make the generated classes package private
|
|
|
|
ant.replaceregexp(match: 'public ((interface|class) \\QPainless\\E\\w+)',
|
2019-11-14 06:01:23 -05:00
|
|
|
replace: '\\1',
|
|
|
|
encoding: 'UTF-8') {
|
2017-03-24 12:44:53 -04:00
|
|
|
fileset(dir: outputPath, includes: 'Painless*.java')
|
|
|
|
}
|
|
|
|
// make the lexer abstract
|
|
|
|
ant.replaceregexp(match: '(class \\QPainless\\ELexer)',
|
2019-11-14 06:01:23 -05:00
|
|
|
replace: 'abstract \\1',
|
|
|
|
encoding: 'UTF-8') {
|
2017-03-24 12:44:53 -04:00
|
|
|
fileset(dir: outputPath, includes: 'PainlessLexer.java')
|
|
|
|
}
|
|
|
|
// nuke timestamps/filenames in generated files
|
|
|
|
ant.replaceregexp(match: '\\Q// Generated from \\E.*',
|
2019-11-14 06:01:23 -05:00
|
|
|
replace: '\\/\\/ ANTLR GENERATED CODE: DO NOT EDIT',
|
|
|
|
encoding: 'UTF-8') {
|
2017-03-24 12:44:53 -04:00
|
|
|
fileset(dir: outputPath, includes: 'Painless*.java')
|
|
|
|
}
|
|
|
|
// remove tabs in antlr generated files
|
|
|
|
ant.replaceregexp(match: '\t', flags: 'g', replace: ' ', encoding: 'UTF-8') {
|
|
|
|
fileset(dir: outputPath, includes: 'Painless*.java')
|
|
|
|
}
|
|
|
|
// fix line endings
|
2017-10-06 16:44:03 -04:00
|
|
|
ant.fixcrlf(srcdir: outputPath, eol: 'lf') {
|
2017-03-24 12:44:53 -04:00
|
|
|
patternset(includes: 'Painless*.java')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|