madrob commented on a change in pull request #1199: LUCENE-9134: Port 
ant-regenerate tasks to Gradle build
URL: https://github.com/apache/lucene-solr/pull/1199#discussion_r370864083
 
 

 ##########
 File path: lucene/queryparser/build.gradle
 ##########
 @@ -7,3 +7,305 @@ dependencies {
 
   testImplementation project(':lucene:test-framework')
 }
+
+configure(":lucene:queryparser") {
+  configurations {
+    javaCCDeps
+
+    dependencies {
+      javaCCDeps "net.java.dev.javacc:javacc:5.0"
+    }
+  }
+}
+def conf = [
+    "queryParser": ["inputFile": 
file('src/java/org/apache/lucene/queryparser/classic/QueryParser.jj'), 
"outputDir": file('src/java/org/apache/lucene/queryparser/classic')],
+    "surround"   : ["inputFile": 
file('src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.jj'), 
"outputDir": file('src/java/org/apache/lucene/queryparser/surround/parser/')],
+    "flexible"   : ["inputFile": 
file('src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj'),
 "outputDir": 
file('src/java/org/apache/lucene/queryparser/flexible/standard/parser')]
+]
+
+String javaCCClasspath
+String javaCCHome
+
+task installJavacc {
+  doLast {
+    javaCCClasspath = 
project.project(":lucene:queryparser").configurations.javaCCDeps.asPath
+    javaCCHome = javaCCClasspath.substring(0, javaCCClasspath.lastIndexOf("/"))
+
+    String hacky = javaCCHome + "/" + "javacc.jar"
+    File hackyFile = new File(hacky)
+    println hackyFile
+    println hackyFile.exists()
+    if (hackyFile.exists() == false) {
+      hackyFile.bytes = new File(javaCCClasspath).bytes
+      hackyFile.setExecutable(true)
+    }
+  }
+}
+String lineSeparator = System.lineSeparator()
+
+task cleanOldGeneratedFiles {
+  doLast {
+    println "Removing old generated files"
+    conf.each { key, val ->
+      val["outputDir"].eachFileMatch ~/.*\.java/, { f ->
+        if (f.text =~ /Generated.*By.*JavaCC/) {
+          f.delete()
+        }
+      }
+    }
+  }
+}
+
+task runJavaccQueryParser(dependsOn: installJavacc) {
 
 Review comment:
   I think because there is so much commonality between all of the javacc 
tasks, I would create a `task JavaCC` class and put all the clean up logic in 
one place rather than repeating it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to