mirror of https://github.com/apache/lucene.git
117 lines
3.6 KiB
Groovy
117 lines
3.6 KiB
Groovy
|
|
||
|
// This adds javacc generation support.
|
||
|
|
||
|
configure(rootProject) {
|
||
|
configurations {
|
||
|
javacc
|
||
|
}
|
||
|
|
||
|
dependencies {
|
||
|
javacc "net.java.dev.javacc:javacc:${scriptDepVersions['javacc']}"
|
||
|
}
|
||
|
|
||
|
task javacc() {
|
||
|
description "Regenerate sources for corresponding javacc grammar files."
|
||
|
group "generation"
|
||
|
|
||
|
dependsOn ":lucene:queryparser:javaccParserClassic"
|
||
|
dependsOn ":lucene:queryparser:javaccParserSurround"
|
||
|
dependsOn ":lucene:queryparser:javaccParserFlexible"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// We always regenerate, no need to declare outputs.
|
||
|
class JavaCCTask extends DefaultTask {
|
||
|
@Input
|
||
|
File javaccFile
|
||
|
|
||
|
JavaCCTask() {
|
||
|
dependsOn(project.rootProject.configurations.javacc)
|
||
|
}
|
||
|
|
||
|
@TaskAction
|
||
|
def generate() {
|
||
|
if (!javaccFile || !javaccFile.exists()) {
|
||
|
throw new RuntimeException("JavaCC input file does not exist: ${javaccFile}")
|
||
|
}
|
||
|
|
||
|
// Remove previous files so we can regenerate them. javacc doesn't want to overwrite
|
||
|
// locally modified files.
|
||
|
def parentDir = javaccFile.parentFile
|
||
|
def toDelete = project.fileTree(parentDir, {
|
||
|
include "**/*.java"
|
||
|
}).findAll { file -> file.getText("UTF-8").contains("Generated By:JavaCC") }
|
||
|
project.delete(toDelete)
|
||
|
|
||
|
logger.lifecycle("Regenerating JavaCC:\n from: ${javaccFile}\n to: ${parentDir}")
|
||
|
|
||
|
def output = new ByteArrayOutputStream()
|
||
|
def result = project.javaexec {
|
||
|
classpath {
|
||
|
project.rootProject.configurations.javacc
|
||
|
}
|
||
|
|
||
|
ignoreExitValue = true
|
||
|
standardOutput = output
|
||
|
errorOutput = output
|
||
|
|
||
|
main = "org.javacc.parser.Main"
|
||
|
args += [
|
||
|
"-OUTPUT_DIRECTORY=${parentDir}",
|
||
|
javaccFile
|
||
|
]
|
||
|
}
|
||
|
|
||
|
// Unless we request verbose logging, don't emit javacc output.
|
||
|
if (result.exitValue != 0) {
|
||
|
throw new GradleException("JavaCC failed to compile ${javaccFile}, here is the compilation output:\n${output}")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
configure(project(":lucene:queryparser")) {
|
||
|
task javaccParserClassic(type: JavaCCTask) {
|
||
|
description "Regenerate classic query parser from java CC.java"
|
||
|
group "generation"
|
||
|
|
||
|
javaccFile = file('src/java/org/apache/lucene/queryparser/classic/QueryParser.jj')
|
||
|
def parent = javaccFile.parentFile.toString() // I'll need this later.
|
||
|
|
||
|
doLast {
|
||
|
// There'll be a lot of cleanup in here to get precommits and builds to pass, but as long as we don't
|
||
|
// run the javacc task in master and check the regenerated files in, we'll be OK.
|
||
|
// As soon as we merge this into master I can fill this in.
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
configure(project(":lucene:queryparser")) {
|
||
|
task javaccParserSurround(type: JavaCCTask) {
|
||
|
description "Regenerate surround query parser from java CC.java"
|
||
|
group "generation"
|
||
|
|
||
|
javaccFile = file('src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.jj')
|
||
|
|
||
|
doLast {
|
||
|
// There'll be a lot of cleanup in here to get precommits and builds to pass, but as long as we don't
|
||
|
// run the javacc task in master and check the regenerated files in, we'll be OK.
|
||
|
// As soon as we merge this into master I can fill this in.
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
configure(project(":lucene:queryparser")) {
|
||
|
task javaccParserFlexible(type: JavaCCTask) {
|
||
|
description "Regenerate Flexible query parser from java CC.java"
|
||
|
group "generation"
|
||
|
|
||
|
javaccFile = file('src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj')
|
||
|
|
||
|
doLast {
|
||
|
// There'll be a lot of cleanup in here to get precommits and builds to pass, but as long as we don't
|
||
|
// run the javacc task in master and check the regenerated files in, we'll be OK.
|
||
|
// As soon as we merge this into master I can fill this in.
|
||
|
}
|
||
|
}
|
||
|
}
|