You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2019/06/07 08:04:45 UTC
[lucene-solr] 04/05: SOLR-13452: Add solr-core javacc queryparser
task.
This is an automated email from the ASF dual-hosted git repository.
markrmiller pushed a commit to branch jira/SOLR-13452_gradle_3
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit b750f5e6756060c68d52f4ee06e648dd8b0eb5f7
Author: markrmiller <ma...@apache.org>
AuthorDate: Thu Jun 6 16:16:03 2019 -0500
SOLR-13452: Add solr-core javacc queryparser task.
---
buildSrc/build.gradle | 2 +
.../groovy/org/apache/lucene/gradle/JavaCC.groovy | 94 ++++++++++++++++++++++
solr/build.gradle | 5 ++
solr/core/build.gradle | 5 ++
4 files changed, 106 insertions(+)
diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle
index 3d81a98..9911832 100644
--- a/buildSrc/build.gradle
+++ b/buildSrc/build.gradle
@@ -40,6 +40,7 @@ configurations {
jflex
rat
junit4
+ javacc
jflex.extendsFrom implementation
}
@@ -48,6 +49,7 @@ dependencies {
jflex "de.jflex:jflex:1.7.0"
rat "org.apache.rat:apache-rat:0.11"
junit4 "com.carrotsearch.randomizedtesting:junit4-ant"
+ javacc "net.java.dev.javacc:javacc:5.0"
}
sourceSets {
diff --git a/buildSrc/src/main/groovy/org/apache/lucene/gradle/JavaCC.groovy b/buildSrc/src/main/groovy/org/apache/lucene/gradle/JavaCC.groovy
new file mode 100644
index 0000000..08106fa
--- /dev/null
+++ b/buildSrc/src/main/groovy/org/apache/lucene/gradle/JavaCC.groovy
@@ -0,0 +1,94 @@
+package org.apache.lucene.gradle
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.gradle.api.DefaultTask
+import org.gradle.api.tasks.Input
+import org.gradle.api.tasks.Optional
+import org.gradle.api.tasks.InputDirectory
+import org.gradle.api.tasks.InputFile
+import org.gradle.api.tasks.OutputDirectory
+import org.gradle.api.tasks.TaskAction
+
+class JavaCC extends DefaultTask {
+
+ @InputFile
+ File inputFile
+
+ @OutputDirectory
+ File target
+
+ @TaskAction
+ void javacc() {
+
+ String javaCCHome
+ String javaCCJarName
+
+ project.project(":buildSrc").configurations.javacc.files.each {
+ if (it.getName().startsWith("javacc") && it.getName().endsWith(".jar")) {
+ javaCCHome = it.getParentFile().getAbsolutePath()
+ javaCCJarName = it.getName()
+ }
+ }
+
+ project.sync {
+ from (javaCCHome + "/" + javaCCJarName)
+ into (javaCCHome)
+ rename { String fileName ->
+ fileName = "javacc.jar"
+ }
+ }
+
+ ant.taskdef(classname: 'org.apache.tools.ant.taskdefs.optional.javacc.JavaCC',
+ name: 'javacc',
+ classpath: project.project(":buildSrc").configurations.javacc.asPath)
+
+ project.mkdir("src/java/org/apache/solr/parser")
+
+ ant.delete() {
+ ant.fileset(dir: "${target}", includes: "*.java") {
+ ant.containsregexp(expression: "Generated.*By.*JavaCC")
+ }
+ }
+
+ ant.javacc(target: inputFile.getAbsolutePath(), outputDirectory: target.getAbsolutePath(), javacchome: javaCCHome)
+
+
+ // Change the incorrect public ctors for QueryParser to be protected instead
+ ant.replaceregexp(file:"src/java/org/apache/solr/parser/QueryParser.java",
+ byline: "true",
+ match: "public QueryParser\\(CharStream ",
+ replace: "protected QueryParser(CharStream ")
+ ant.replaceregexp(file:"src/java/org/apache/solr/parser/QueryParser.java",
+ byline: "true",
+ match: "public QueryParser\\(QueryParserTokenManager ",
+ replace:"protected QueryParser(QueryParserTokenManager ")
+ // change an exception used for signaling to be static
+ ant.replaceregexp(file: "src/java/org/apache/solr/parser/QueryParser.java",
+ byline: "true",
+ match: "final private LookaheadSuccess jj_ls =",
+ replace: "static final private LookaheadSuccess jj_ls =")
+ ant.replace(token: "StringBuffer", value: "StringBuilder", encoding: "UTF-8") {
+ ant.fileset(dir: "src/java/org/apache/solr/parser", includes: "ParseException.java TokenMgrError.java")
+ }
+
+ ant.fixcrlf(srcdir: "${target}", includes: "*.java", encoding: "UTF-8") {
+ ant.containsregexp(expression: "Generated.*By.*JavaCC")
+ }
+ }
+}
+
+
diff --git a/solr/build.gradle b/solr/build.gradle
index 9ea77bc..d05b0e4 100644
--- a/solr/build.gradle
+++ b/solr/build.gradle
@@ -36,7 +36,12 @@ task packageDist(type: org.apache.lucene.gradle.PackageLuceneSolrDist) {
subprojects {
File target = File.createTempDir()
+ target.deleteOnExit()
tasks.create("jdepsReport", org.apache.lucene.gradle.JdepsReport, target)
tasks.create("unusedDeps", org.apache.lucene.gradle.UnusedDeps, target)
unusedDeps.dependsOn jdepsReport
+
+ unusedDeps.doLast {
+ deleteDirectory(target)
+ }
}
diff --git a/solr/core/build.gradle b/solr/core/build.gradle
index ffd12ca..824c869 100644
--- a/solr/core/build.gradle
+++ b/solr/core/build.gradle
@@ -208,3 +208,8 @@ forbiddenApisTest {
exclude 'org/apache/solr/internal/**'
exclude 'org/apache/hadoop/**'
}
+
+task javacc(type: org.apache.lucene.gradle.JavaCC) {
+ inputFile file("${projectDir}/src/java/org/apache/solr/parser/QueryParser.jj")
+ target file("${projectDir}/src/java/org/apache/lucene/analysis/standard")
+}