dweiss commented on a change in pull request #1186: LUCENE-9134: Port ant-regenerate tasks to Gradle build URL: https://github.com/apache/lucene-solr/pull/1186#discussion_r369250838
########## File path: lucene/queryparser/build.gradle ########## @@ -7,3 +7,224 @@ dependencies { testImplementation project(':lucene:test-framework') } + +configure(":lucene:queryparser") { + configurations { + javaCCDeps + } + + dependencies { + javaCCDeps "net.java.dev.javacc:javacc:5.0" + } +} + +String lineSeparator = System.lineSeparator() + +task runJavaccQueryParser(type: JavaCC) { + outputs.upToDateWhen { false } //nocommit + inputFile file('src/java/org/apache/lucene/queryparser/classic/QueryParser.jj') + target file('src/java/org/apache/lucene/queryparser/classic') + doLast { + ant.replaceregexp(file: "src/java/org/apache/lucene/queryparser/classic/QueryParser.java", + byline: "true", + match: "public QueryParser\\(CharStream ", + replace: "protected QueryParser(CharStream ") + ant.replaceregexp(file: "src/java/org/apache/lucene/queryparser/classic/QueryParser.java", + byline: "true", + match: "public QueryParser\\(QueryParserTokenManager ", + replace: "protected QueryParser(QueryParserTokenManager ") + } +} + +task runJavaccSurround(type: JavaCC) { + outputs.upToDateWhen { false } //nocommit + inputFile file('src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.jj') + target file('src/java/org/apache/lucene/queryparser/surround/parser') +} + +task runJavaccFlexible(type: JavaCC) { + outputs.upToDateWhen { false } //nocommit + inputFile file('src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj') + target file('src/java/org/apache/lucene/queryparser/flexible/standard/parser') + doLast { + ant.replaceregexp(file: "src/java/org/apache/lucene/queryparser/flexible/standard/parser/ParseException.java", + match: "public class ParseException extends Exception", + replace: "public class ParseException extends QueryNodeParseException", + flags: "g", + byline: "false") + ant.replaceregexp(file: "src/java/org/apache/lucene/queryparser/flexible/standard/parser/ParseException.java", + match: "package org.apache.lucene.queryparser.flexible.standard.parser;", + replace: "package org.apache.lucene.queryparser.flexible.standard.parser;${lineSeparator}${lineSeparator}" + + "import org.apache.lucene.queryparser.flexible.messages.Message;${lineSeparator}" + + "import org.apache.lucene.queryparser.flexible.messages.MessageImpl;${lineSeparator}" + + "import org.apache.lucene.queryparser.flexible.core.*;${lineSeparator}" + + "import org.apache.lucene.queryparser.flexible.core.messages.*;", + flags: "g", + byline: "false") + ant.replaceregexp(file: "src/java/org/apache/lucene/queryparser/flexible/standard/parser/ParseException.java", + match: "^ public ParseException\\(Token currentTokenVal.*\$(\\s\\s[^}].*\\n)* \\}", + replace: " public ParseException(Token currentTokenVal,${lineSeparator}" + + " int[][] expectedTokenSequencesVal, String[] tokenImageVal) {${lineSeparator}" + + " super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, initialise(${lineSeparator}" + + " currentTokenVal, expectedTokenSequencesVal, tokenImageVal)));${lineSeparator}" + + " this.currentToken = currentTokenVal;${lineSeparator}" + + " this.expectedTokenSequences = expectedTokenSequencesVal;${lineSeparator}" + + " this.tokenImage = tokenImageVal;${lineSeparator}" + + " }", + flags: "gm", + byline: "false") + ant.replaceregexp(file:"src/java/org/apache/lucene/queryparser/flexible/standard/parser/ParseException.java", + match: "^ public ParseException\\(String message.*\$(\\s\\s[^}].*\\n)* \\}", + replace: " public ParseException(Message message) {${lineSeparator}" + + " super(message);${lineSeparator}" + + " }", + flags: "gm", + byline: "false") + ant.replaceregexp(file:"src/java/org/apache/lucene/queryparser/flexible/standard/parser/ParseException.java", + match: "^ public ParseException\\(\\).*\$(\\s\\s[^}].*\\n)* \\}", + replace: " public ParseException() {${lineSeparator}" + + " super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, \"Error\"));${lineSeparator}" + + " }", + flags: "gm", + byline: "false") + ant.replaceregexp(file: "src/java/org/apache/lucene/queryparser/flexible/standard/parser/ParseException.java", + match: "^ public String getMessage\\(\\).*\$(\\s\\s\\s\\s[^}].*\n)* \\}", + replace: " private static String initialise(Token currentToken, int[][] expectedTokenSequences, String[] tokenImage) {${lineSeparator}" + + "String eol = System.getProperty("lineSeparator", "\n");", + flags: "gm", + byline: "false") + ant.replaceregexp(file: "src/java/org/apache/lucene/queryparser/flexible/standard/parser/ParseException.java", + match: "\\s*protected String add_escapes.*", + replace: " static private String add_escapes(String str) {", + flags: "g", + byline: "true") + } + + task runJavacc { + outputs.upToDateWhen { false } //nocommit + group = 'Build Regenerate' + description = "Regenerates javacc generated src files." + dependsOn runJavaccQueryParser, runJavaccSurround, runJavaccFlexible + } + + task regenerate { + group = 'Build Regenerate' + description = "Regenerates various generated src files, automoton, packedints, jflex, javacc, etc" + dependsOn runJavacc + } +} + +class JavaCC extends DefaultTask { + + @InputFile + File inputFile + + @OutputDirectory + File target + + String lineSeparator = System.lineSeparator() + @TaskAction + void javacc() { + + + String javaCCClasspath = project.project(":lucene:queryparser").configurations.javaCCDeps.asPath + String javaCCHome = javaCCClasspath.substring(0, javaCCClasspath.lastIndexOf("/")) + + // This bit seems really awkward, but I didn't find a good way to either convince the ant task to accept a different + // name than javacc.jar... + // nocommit So I'm taking the javacc-5.0.jar file that's downloaded to Gradle's cache and renaming it. Review comment: I know there are plugins for that. We should stick to the exact javacc version ant currently uses though (so that the output code is the same). By the way - the shuffled generated code may be a result of a HashMap somewhere in the javacc code. Sigh. ---------------------------------------------------------------- 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