mirror of https://github.com/apache/lucene.git
LUCENE-9134: this adds initial javacc support (without follow-up tweaks required to make the sources identical as those generated by ant).
This commit is contained in:
parent
7941d109bd
commit
e25dac085f
|
@ -40,7 +40,8 @@ ext {
|
|||
// https://github.com/palantir/gradle-consistent-versions/issues/383
|
||||
scriptDepVersions = [
|
||||
"apache-rat": "0.11",
|
||||
"jflex": "1.7.0"
|
||||
"javacc": "5.0",
|
||||
"jflex": "1.7.0",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -81,6 +82,7 @@ apply from: file('gradle/validation/owasp-dependency-check.gradle')
|
|||
|
||||
// Source or data regeneration tasks
|
||||
apply from: file('gradle/generation/jflex.gradle')
|
||||
apply from: file('gradle/generation/javacc.gradle')
|
||||
|
||||
// Additional development aids.
|
||||
apply from: file('gradle/maven/maven-local.gradle')
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
|
||||
// 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.
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue