ErickErickson commented on a change in pull request #1218: LUCENE-9134: Javacc skeleton URL: https://github.com/apache/lucene-solr/pull/1218#discussion_r371828729
########## File path: gradle/generation/javacc.gradle ########## @@ -0,0 +1,102 @@ +// Add a top-level pseudo-task to which we will attach individual regenerate tasks. +import static groovy.io.FileType.* + +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 old files so we can regenerate them + def parentDir = javaccFile.parentFile + parentDir.eachFileMatch FILES, ~/.*\.java/, { file -> + if (file.text.contains("Generated By:JavaCC")) { + file.delete() + } + } + logger.lifecycle("Regenerating JavaCC:\n from: ${javaccFile}\n to: ${parentDir}") + + project.javaexec { + classpath { + project.rootProject.configurations.javacc + } + main = "org.javacc.parser.Main" + args += "-OUTPUT_DIRECTORY=${parentDir}" + args += [javaccFile] + } + } +} + + +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 Review comment: That _should_ be the end product already, that's one of the reasons I spent so much time on the ant version and why all those files were changed when I committed. At least I _think_ I got them all. At least that's what I remember doing... That said I'll try not to go off in the weeds. Now that I've got the structure right, I'll see if I can get this to happen. Shouldn't actually be that much. Oh, and ignore PR 1219, I had a bad title for this PR and it didn't link. When I changed the title of this one it took a while to show up and I got impatient. 1219 and 1218 are identical. Finally, many thanks for your coaching (well, ok, outright fixing things)! ---------------------------------------------------------------- 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