LUCENE-9134: Port ant-regenerate tasks to Gradle build (util and packed) (#1251)

* LUCENE-9134: Port ant-regenerate tasks to Gradle build
This commit is contained in:
Erick Erickson 2020-02-11 18:56:11 -05:00 committed by GitHub
parent c3e44e1fec
commit f9357ab0d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 8 deletions

View File

@ -23,6 +23,7 @@ plugins {
id "com.palantir.consistent-versions" version "1.14.0"
id 'de.thetaphi.forbiddenapis' version '2.7' apply false
id "org.owasp.dependencycheck" version "5.3.0"
id "de.undercouch.download" version "4.0.2" apply false
}
// Project version and main properties. Applies to all projects.
@ -83,6 +84,7 @@ apply from: file('gradle/validation/owasp-dependency-check.gradle')
// Source or data regeneration tasks
apply from: file('gradle/generation/jflex.gradle')
apply from: file('gradle/generation/javacc.gradle')
apply from: file('gradle/generation/util.gradle')
// Additional development aids.
apply from: file('gradle/maven/maven-local.gradle')

View File

@ -0,0 +1,100 @@
/*
* 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.
*/
apply plugin: "de.undercouch.download"
configure(rootProject) {
configurations {
utilgen
}
task utilgen {
description "Regenerate sources for ...lucene/util/automaton and ...lucene/util/packed."
group "generation"
dependsOn ":lucene:core:utilGenPacked"
dependsOn ":lucene:core:utilGenLev"
}
}
def momanDir = new File(buildDir, "moman").getAbsolutePath()
task installMoman(type: Download) {
def momanZip = new File(momanDir, "moman.zip").getAbsolutePath()
src "https://bitbucket.org/jpbarrette/moman/get/5c5c2a1e4dea.zip"
dest momanZip
onlyIfModified true
doLast {
logger.lifecycle("Downloading moman to: ${buildDir}")
ant.unzip(src: momanZip, dest: momanDir, overwrite: "true") {
ant.cutdirsmapper(dirs: "1")
}
}
}
configure(project(":lucene:core")) {
task utilGenPacked(dependsOn: installMoman) {
description "Regenerate util/PackedBulkOperationsPacked*.java and Packed64SingleBlock.java"
group "generation"
def workDir = "src/java/org/apache/lucene/util/packed"
doLast {
['gen_BulkOperation.py', 'gen_Packed64SingleBlock.py'].each { prog ->
logger.lifecycle("Executing: ${prog} in ${workDir}")
project.exec {
workingDir workDir
executable "python"
args = ['-B', "${prog}"]
}
}
// Correct line endings for Windows.
project.ant.fixcrlf(
srcDir: workDir,
includes: 'Packed64SingleBlock.java, BulkOperation*.java',
encoding: 'UTF-8',
eol: 'lf'
)
}
}
task utilGenLev(dependsOn: installMoman) {
description "Regenerate util/automaton Lev*ParametricDescription.java"
group "generation"
doLast {
def workDir = 'src/java/org/apache/lucene/util/automaton'
['1', '2'].each { num ->
['True', 'False'].each { transpose ->
project.exec {
workingDir workDir
executable "python"
args = ['-B', 'createLevAutomata.py', num, transpose, "${momanDir}/finenight/python"]
}
}
}
project.ant.fixcrlf(
srcDir: workDir,
includes: '*ParametricDescription.java',
encoding: 'UTF-8',
eol: 'lf'
)
}
}
}

View File

@ -75,6 +75,8 @@
<arg value="createLevAutomata.py"/>
<arg value="@{n}"/>
<arg value="True"/>
<!-- Hack while transitioning to Gradle build in 9.0 -->
<arg value="../../../../../../../../build/core/moman/finenight/python"/>
</exec>
<exec dir="src/java/org/apache/lucene/util/automaton"
executable="${python.exe}" failonerror="true">
@ -83,6 +85,8 @@
<arg value="createLevAutomata.py"/>
<arg value="@{n}"/>
<arg value="False"/>
<!-- Hack while transitioning to Gradle build in 9.0 -->
<arg value="../../../../../../../../build/core/moman/finenight/python"/>
</exec>
<fixcrlf srcdir="src/java/org/apache/lucene/util/automaton" includes="*ParametricDescription.java" encoding="UTF-8"/>
</sequential>

View File

@ -21,12 +21,7 @@
import math
import os
import sys
# sys.path.insert(0, 'moman/finenight/python')
sys.path.insert(0, '../../../../../../../../build/core/moman/finenight/python')
try:
from possibleStates import genTransitions
except ImportError:
from finenight.possibleStates import genTransitions
MODE = 'array'
PACKED = True
@ -96,9 +91,9 @@ def charVarNumber(charVar):
def main():
if len(sys.argv) != 3:
if len(sys.argv) != 4:
print
print 'Usage: python -u %s N <True/False>' % sys.argv[0]
print 'Usage: python -u %s N <True/False> path_to_moman_dir' % sys.argv[0]
print
print 'NOTE: the resulting .java file is created in the current working dir!'
print
@ -108,6 +103,14 @@ def main():
transpose = (sys.argv[2] == "True")
sys.path.insert(0, sys.argv[3])
try:
from possibleStates import genTransitions
except ImportError:
from finenight.possibleStates import genTransitions
tables = genTransitions(n, transpose)
stateMap = {}