OpenSearch/modules/lang-painless/build.gradle

197 lines
5.9 KiB
Groovy
Raw Normal View History

/*
* 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.testclusters.DefaultTestClustersTask;
apply plugin: 'elasticsearch.validate-rest-spec'
esplugin {
description 'An easy, safe and fast scripting language for Elasticsearch'
classname 'org.elasticsearch.painless.PainlessPlugin'
}
testClusters.integTest {
module project(':modules:mapper-extras').tasks.bundlePlugin.archiveFile
systemProperty 'es.scripting.update.ctx_in_params', 'false'
// TODO: remove this once cname is prepended to transport.publish_address by default in 8.0
systemProperty 'es.transport.cname_in_publish_address', 'true'
}
dependencies {
compile 'org.antlr:antlr4-runtime:4.5.3'
compile 'org.ow2.asm:asm-util:7.2'
compile 'org.ow2.asm:asm-tree:7.2'
compile 'org.ow2.asm:asm-commons:7.2'
compile 'org.ow2.asm:asm-analysis:7.2'
compile 'org.ow2.asm:asm:7.2'
compile project('spi')
2015-12-28 22:38:55 -05:00
}
dependencyLicenses {
mapping from: /asm-.*/, to: 'asm'
}
restResources {
restApi {
includeCore '_common', 'cluster', 'nodes', 'indices', 'index', 'search', 'get', 'bulk', 'update',
'scripts_painless_execute', 'put_script', 'delete_script'
}
}
test {
// in WhenThingsGoWrongTests we intentionally generate an out of memory error, this prevents the heap from being dumped to disk
jvmArgs '-XX:-OmitStackTraceInFastThrow', '-XX:-HeapDumpOnOutOfMemoryError'
}
Generate reference links for painless API (#22775) Adds "Appending B. Painless API Reference", a reference of all classes and methods available from Painless. Removes links to java packages because they contain methods that we don't expose and don't contain methods that we do expose (the ones in Augmentation). Instead this generates a list of every class and every exposed method using the same type information available to the interpreter/compiler/whatever-we-call-it. From there you can jump to the relevant docs. Right now you build all the asciidoc files by running ``` gradle generatePainlessApi ``` These files are expected to be committed because we build the docs without running `gradle`. Also changes the output of `Debug.explain` so that it is easy to search for the class in the generated reference documentation. You can also run it in an IDE safely if you pass the path to the directory in which to generate the docs as the first parameter. It'll blow away the entire directory an recreate it from scratch so be careful. And then you can build the docs by running something like: ``` ../docs/build_docs.pl --out ../built_docs/ --doc docs/reference/index.asciidoc --open ``` That is, if you have checked out https://github.com/elastic/docs in `../docs`. Wait a minute or two and your browser will pop open in with all of Elasticsearch's reference documentation. If you go to `http://localhost:8000/painless-api-reference.html` you can see this list. Or you can get there by following the links to `Modules` and `Scripting` and `Painless` and then clicking the link in the paragraphs below titled `Appendix B. Painless API Reference`. I like having these in asciidoc because we can deep link to them from the rest of the guide with constructs like `<<painless-api-reference-Object-hashCode-0>>` and `<<painless-api-reference->>` and we get link checking. Then the only brittle link maintenance bit is the link generation for javadoc. Which sucks. But I think it is important that we link to the methods directly so they are easy to find. Relates to #22720
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 */
task apiJavadoc(type: Javadoc) {
source = sourceSets.main.allJava
classpath = sourceSets.main.runtimeClasspath
include '**/org/elasticsearch/painless/api/'
destinationDir = new File(docsDir, 'apiJavadoc')
}
task apiJavadocJar(type: Jar) {
classifier = 'apiJavadoc'
from apiJavadoc
}
assemble.dependsOn apiJavadocJar
Generate reference links for painless API (#22775) Adds "Appending B. Painless API Reference", a reference of all classes and methods available from Painless. Removes links to java packages because they contain methods that we don't expose and don't contain methods that we do expose (the ones in Augmentation). Instead this generates a list of every class and every exposed method using the same type information available to the interpreter/compiler/whatever-we-call-it. From there you can jump to the relevant docs. Right now you build all the asciidoc files by running ``` gradle generatePainlessApi ``` These files are expected to be committed because we build the docs without running `gradle`. Also changes the output of `Debug.explain` so that it is easy to search for the class in the generated reference documentation. You can also run it in an IDE safely if you pass the path to the directory in which to generate the docs as the first parameter. It'll blow away the entire directory an recreate it from scratch so be careful. And then you can build the docs by running something like: ``` ../docs/build_docs.pl --out ../built_docs/ --doc docs/reference/index.asciidoc --open ``` That is, if you have checked out https://github.com/elastic/docs in `../docs`. Wait a minute or two and your browser will pop open in with all of Elasticsearch's reference documentation. If you go to `http://localhost:8000/painless-api-reference.html` you can see this list. Or you can get there by following the links to `Modules` and `Scripting` and `Painless` and then clicking the link in the paragraphs below titled `Appendix B. Painless API Reference`. I like having these in asciidoc because we can deep link to them from the rest of the guide with constructs like `<<painless-api-reference-Object-hashCode-0>>` and `<<painless-api-reference->>` and we get link checking. Then the only brittle link maintenance bit is the link generation for javadoc. Which sucks. But I think it is important that we link to the methods directly so they are easy to find. Relates to #22720
2017-01-26 10:39:19 -05:00
/**********************************************
* Context API Generation *
**********************************************/
sourceSets {
doc
}
dependencies {
docCompile project(':server')
docCompile project(':modules:lang-painless')
}
testClusters {
generateContextCluster {
testDistribution = 'DEFAULT'
}
}
task generateContextDoc(type: DefaultTestClustersTask) {
useCluster testClusters.generateContextCluster
doFirst {
project.javaexec {
main = 'org.elasticsearch.painless.ContextDocGenerator'
classpath = sourceSets.doc.runtimeClasspath
systemProperty "cluster.uri", "${-> testClusters.generateContextCluster.singleNode().getAllHttpSocketURI()}"
}.assertNormalExitValue()
}
Generate reference links for painless API (#22775) Adds "Appending B. Painless API Reference", a reference of all classes and methods available from Painless. Removes links to java packages because they contain methods that we don't expose and don't contain methods that we do expose (the ones in Augmentation). Instead this generates a list of every class and every exposed method using the same type information available to the interpreter/compiler/whatever-we-call-it. From there you can jump to the relevant docs. Right now you build all the asciidoc files by running ``` gradle generatePainlessApi ``` These files are expected to be committed because we build the docs without running `gradle`. Also changes the output of `Debug.explain` so that it is easy to search for the class in the generated reference documentation. You can also run it in an IDE safely if you pass the path to the directory in which to generate the docs as the first parameter. It'll blow away the entire directory an recreate it from scratch so be careful. And then you can build the docs by running something like: ``` ../docs/build_docs.pl --out ../built_docs/ --doc docs/reference/index.asciidoc --open ``` That is, if you have checked out https://github.com/elastic/docs in `../docs`. Wait a minute or two and your browser will pop open in with all of Elasticsearch's reference documentation. If you go to `http://localhost:8000/painless-api-reference.html` you can see this list. Or you can get there by following the links to `Modules` and `Scripting` and `Painless` and then clicking the link in the paragraphs below titled `Appendix B. Painless API Reference`. I like having these in asciidoc because we can deep link to them from the rest of the guide with constructs like `<<painless-api-reference-Object-hashCode-0>>` and `<<painless-api-reference->>` and we get link checking. Then the only brittle link maintenance bit is the link generation for javadoc. Which sucks. But I think it is important that we link to the methods directly so they are easy to find. Relates to #22720
2017-01-26 10:39:19 -05:00
}
/**********************************************
* Parser regeneration *
**********************************************/
configurations {
regenerate
}
dependencies {
regenerate 'org.antlr:antlr4:4.5.3'
}
String grammarPath = 'src/main/antlr'
String outputPath = 'src/main/java/org/elasticsearch/painless/antlr'
task cleanGenerated(type: Delete) {
delete fileTree(grammarPath) {
include '*.tokens'
}
delete fileTree(outputPath) {
include 'Painless*.java'
}
}
task regenLexer(type: JavaExec) {
dependsOn cleanGenerated
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',
'-package', 'org.elasticsearch.painless.antlr',
'-o', outputPath,
"${file(grammarPath)}/PainlessLexer.g4"
}
task regenParser(type: JavaExec) {
dependsOn regenLexer
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',
'-package', 'org.elasticsearch.painless.antlr',
'-no-listener',
'-visitor',
// '-Xlog',
'-o', outputPath,
"${file(grammarPath)}/PainlessParser.g4"
}
task regen {
dependsOn regenParser
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+)',
replace: '\\1',
encoding: 'UTF-8') {
fileset(dir: outputPath, includes: 'Painless*.java')
}
// make the lexer abstract
ant.replaceregexp(match: '(class \\QPainless\\ELexer)',
replace: 'abstract \\1',
encoding: 'UTF-8') {
fileset(dir: outputPath, includes: 'PainlessLexer.java')
}
// nuke timestamps/filenames in generated files
ant.replaceregexp(match: '\\Q// Generated from \\E.*',
replace: '\\/\\/ ANTLR GENERATED CODE: DO NOT EDIT',
encoding: 'UTF-8') {
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
ant.fixcrlf(srcdir: outputPath, eol: 'lf') {
patternset(includes: 'Painless*.java')
}
}
}