You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2020/01/29 16:03:51 UTC

[lucene-solr] 03/04: LUCENE-9134: this adds initial javacc support (without follow-up tweaks required to make the sources identical as those generated by ant).

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch gradle-master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit e25dac085fec077cf27e8c79a6f0796059678f9f
Author: Dawid Weiss <dw...@apache.org>
AuthorDate: Wed Jan 29 17:01:34 2020 +0100

    LUCENE-9134: this adds initial javacc support (without follow-up tweaks required to make the sources identical as those generated by ant).
---
 build.gradle                    |   4 +-
 gradle/generation/javacc.gradle | 117 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index fc5d965..5db7b02 100644
--- a/build.gradle
+++ b/build.gradle
@@ -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')
diff --git a/gradle/generation/javacc.gradle b/gradle/generation/javacc.gradle
new file mode 100644
index 0000000..85f0609
--- /dev/null
+++ b/gradle/generation/javacc.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.
+    }
+  }
+}
\ No newline at end of file