ErickErickson 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_r370969094
########## 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) { + doLast { + println "Generating QueryParser parser" + + def inputFile = conf["queryParser"]["inputFile"].getAbsolutePath() + def outputDir = conf["queryParser"]["outputDir"].getAbsolutePath() + ant.javacc(target: inputFile, outputDirectory: outputDir, javacchome: javaCCHome) + + + ant.replaceregexp(file: new File(outputDir, "QueryParser.java"), + byline: "true", + match: "public QueryParser\\(CharStream ", + replace: "protected QueryParser(CharStream ") + ant.replaceregexp(file: new File(outputDir, "QueryParser.java"), + byline: "true", + match: "public QueryParser\\(QueryParserTokenManager ", + replace: "protected QueryParser(QueryParserTokenManager ") + } +} + +task runJavaccSurround(dependsOn: installJavacc) { + doLast { + println "Generating Surroundf parser" + def inputFile = conf["surround"]["inputFile"].getAbsolutePath() + def outputDir = conf["surround"]["outputDir"].getAbsolutePath() + + ant.javacc(target: inputFile, outputDirectory: outputDir, javacchome: javaCCHome) + + // This is very clumsy, but these are unused imports that are necessary other generated files + [ + "import java.util.Vector;", + "import org.apache.lucene.queryparser.flexible.messages.Message;", + "import org.apache.lucene.queryparser.flexible.messages.MessageImpl;", + "import org.apache.lucene.queryparser.flexible.core.QueryNodeParseException;", + "import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages;", + "import org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.BoostQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode;", + "import org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.SlopQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.QueryNode;", + "import org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode;", + "import org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser;", + "import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode;", + "import java.io.StringReader;", + "import java.util.ArrayList;", + "import java.util.Arrays;", + "import java.util.HashSet;", + "import java.util.List;", + "import java.util.Locale;", + "import java.util.Set;", + "import org.apache.lucene.analysis.Analyzer;", + "import org.apache.lucene.document.DateTools;", + "import org.apache.lucene.search.BooleanClause;", + "import org.apache.lucene.search.Query;", + "import org.apache.lucene.search.TermRangeQuery;", + "import org.apache.lucene.analysis.TokenStream;", + "import org.apache.lucene.queryparser.surround.query.SrndQuery;", + "import org.apache.lucene.queryparser.surround.query.FieldsQuery;", + "import org.apache.lucene.queryparser.surround.query.OrQuery;", + "import org.apache.lucene.queryparser.surround.query.AndQuery;", + "import org.apache.lucene.queryparser.surround.query.NotQuery;", + "import org.apache.lucene.queryparser.surround.query.DistanceQuery;", + "import org.apache.lucene.queryparser.surround.query.SrndTermQuery;", + "import org.apache.lucene.queryparser.surround.query.SrndPrefixQuery;", + "import org.apache.lucene.queryparser.surround.query.SrndTruncQuery;" + ].each { + ant.replaceregexp(match: "${it}.*${lineSeparator}", replace: "", encoding: "UTF-8") { + ant.fileset(dir: outputDir, includes: "*TokenManager.java") + } + } + // StringBuffer -> StringBuilder + ant.replace(token: "StringBuffer", value: "StringBuilder", encoding: "UTF-8") { + ant.fileset(dir: outputDir, includes: "ParseException.java TokenMgrError.java") + } + + [ + "import org.apache.lucene.analysis.TokenStream;", + ].each { + ant.replaceregexp(match: "${it}.*${lineSeparator}", replace: "", encoding: "UTF-8") { + ant.fileset(dir: outputDir, includes: "QueryParser.java") + } + } + // StringBuffer -> StringBuilder Review comment: Not any more ;) ---------------------------------------------------------------- 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