mirror of https://github.com/apache/lucene.git
LUCENE-9896: Add 'quiet exec' utility suppressing exec output unless a failure occurs
This commit is contained in:
parent
c7455ff561
commit
39b8e97613
|
@ -45,23 +45,14 @@ class CheckBrokenLinksTask extends DefaultTask {
|
|||
|
||||
@TaskAction
|
||||
def check() {
|
||||
def result
|
||||
output.withOutputStream { output ->
|
||||
result = project.exec {
|
||||
executable project.externalTool("python3")
|
||||
ignoreExitValue = true
|
||||
standardOutput = output
|
||||
errorOutput = output
|
||||
args = [
|
||||
"-B",
|
||||
validationScript.absolutePath,
|
||||
docsDir.get().getAsFile()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if (result.getExitValue() != 0) {
|
||||
throw new GradleException("Broken links check failed. Command output at: ${output}")
|
||||
project.quietExec {
|
||||
executable project.externalTool("python3")
|
||||
ignoreExitValue = false
|
||||
args = [
|
||||
"-B",
|
||||
validationScript.absolutePath,
|
||||
docsDir.get().getAsFile()
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -451,46 +451,11 @@ class RenderJavadocTask extends DefaultTask {
|
|||
|
||||
logger.info("Javadoc executable used: ${javadocCmd}")
|
||||
|
||||
def outputFile = project.file("${getTemporaryDir()}/javadoc-output.txt")
|
||||
def result
|
||||
|
||||
outputFile.withOutputStream { output ->
|
||||
result = project.exec {
|
||||
project.quietExec {
|
||||
executable javadocCmd
|
||||
|
||||
// we want to capture both stdout and stderr to the same
|
||||
// stream but gradle attempts to close these separately
|
||||
// (it has two independent pumping threads) and it can happen
|
||||
// that one still tries to write something when the other closed
|
||||
// the underlying output stream.
|
||||
def wrapped = new java.io.FilterOutputStream(output) {
|
||||
public void close() {
|
||||
// no-op. we close this stream manually.
|
||||
}
|
||||
}
|
||||
standardOutput = wrapped
|
||||
errorOutput = wrapped
|
||||
|
||||
args += [ "@${optionsFile}" ]
|
||||
args += jOpts
|
||||
|
||||
ignoreExitValue true
|
||||
}
|
||||
}
|
||||
|
||||
if (result.getExitValue() != 0) {
|
||||
// Pipe the output to console. Intentionally skips any encoding conversion
|
||||
// and pumps raw bytes.
|
||||
System.out.write(outputFile.bytes)
|
||||
System.out.flush()
|
||||
|
||||
def cause
|
||||
try {
|
||||
result.rethrowFailure()
|
||||
} catch (ex) {
|
||||
cause = ex
|
||||
}
|
||||
throw new GradleException("Javadoc generation failed for ${project.path},\n Options file at: ${optionsFile}\n Command output at: ${outputFile}", cause)
|
||||
}
|
||||
|
||||
// append some special table css, prettify css
|
||||
|
|
|
@ -63,9 +63,8 @@ configure(project(":lucene:analysis:icu")) {
|
|||
]
|
||||
}
|
||||
|
||||
project.exec {
|
||||
project.quietExec {
|
||||
executable gennorm
|
||||
ignoreExitValue = false
|
||||
args = [
|
||||
"-v",
|
||||
"-s",
|
||||
|
@ -77,9 +76,9 @@ configure(project(":lucene:analysis:icu")) {
|
|||
"NativeDigitFolding.txt"
|
||||
]
|
||||
}
|
||||
project.exec {
|
||||
|
||||
project.quietExec {
|
||||
executable icupkg
|
||||
ignoreExitValue = false
|
||||
args = [
|
||||
"-tb",
|
||||
"${buildDir}/utr30.tmp",
|
||||
|
@ -157,10 +156,8 @@ configure(project(":lucene:analysis:icu")) {
|
|||
project.delete icuSrcDir
|
||||
|
||||
// Extract the tgz
|
||||
project.exec {
|
||||
project.quietExec {
|
||||
executable "tar"
|
||||
ignoreExitValue false
|
||||
|
||||
workingDir icuBuildDir
|
||||
args = [
|
||||
"-zxvf",
|
||||
|
@ -169,9 +166,8 @@ configure(project(":lucene:analysis:icu")) {
|
|||
}
|
||||
|
||||
// Compile: (cd icu/source && ./configure --prefix=$(pwd) --enable-rpath && make -j4)
|
||||
project.exec {
|
||||
project.quietExec {
|
||||
executable "sh"
|
||||
ignoreExitValue false
|
||||
|
||||
workingDir icuSrcDir
|
||||
args = [
|
||||
|
@ -181,9 +177,8 @@ configure(project(":lucene:analysis:icu")) {
|
|||
]
|
||||
}
|
||||
|
||||
project.exec {
|
||||
project.quietExec {
|
||||
executable "make"
|
||||
ignoreExitValue false
|
||||
workingDir icuSrcDir
|
||||
args = [
|
||||
"-j4"
|
||||
|
@ -192,9 +187,8 @@ configure(project(":lucene:analysis:icu")) {
|
|||
|
||||
// Test that the binaries work: derb -V
|
||||
logger.lifecycle("Compiled ICU, checking...")
|
||||
project.exec {
|
||||
project.quietExec {
|
||||
executable "./derb"
|
||||
ignoreExitValue false
|
||||
workingDir icuBinDir
|
||||
args = [
|
||||
"-V"
|
||||
|
|
|
@ -157,16 +157,13 @@ configure(project(":lucene:analysis:common")) {
|
|||
doFirst {
|
||||
// Regenerate HTMLCharacterEntities.jflex first.
|
||||
def target = file('src/java/org/apache/lucene/analysis/charfilter/HTMLCharacterEntities.jflex')
|
||||
target.withOutputStream { output ->
|
||||
project.exec {
|
||||
executable = project.externalTool("python3")
|
||||
workingDir = target.parentFile
|
||||
standardOutput = output
|
||||
args += [
|
||||
"-B", // don't write any bytecode cache
|
||||
"htmlentity.py"
|
||||
]
|
||||
}
|
||||
quietExec {
|
||||
executable = project.externalTool("python3")
|
||||
workingDir = target.parentFile
|
||||
args += [
|
||||
"-B", // don't write any bytecode cache
|
||||
"htmlentity.py"
|
||||
]
|
||||
}
|
||||
|
||||
project.ant.fixcrlf(
|
||||
|
|
|
@ -71,7 +71,7 @@ configure(project(":lucene:analysis:kuromoji")) {
|
|||
}
|
||||
|
||||
// Apply patch via local git.
|
||||
project.exec {
|
||||
project.quietExec {
|
||||
workingDir = unpackedDir
|
||||
executable "git" // TODO: better use jgit to apply patch, this is not portable!!!
|
||||
args += [
|
||||
|
|
|
@ -106,7 +106,7 @@ configure(project(":lucene:analysis:common")) {
|
|||
dependsOn downloadSnowballData
|
||||
|
||||
doFirst {
|
||||
project.exec {
|
||||
project.quietExec {
|
||||
executable "bash"
|
||||
args = [snowballScript, snowballStemmerDir, snowballWebsiteDir, snowballDataDir, projectDir]
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ configure(project(":lucene:core")) {
|
|||
|
||||
['gen_BulkOperation.py', 'gen_Packed64SingleBlock.py'].each { prog ->
|
||||
logger.lifecycle("Executing: ${prog} in ${targetDir}")
|
||||
project.exec {
|
||||
quietExec {
|
||||
workingDir targetDir
|
||||
executable project.externalTool("python3")
|
||||
args = ['-B', "${prog}"]
|
||||
|
@ -69,7 +69,7 @@ configure(project(":lucene:core")) {
|
|||
|
||||
['1', '2'].each { num ->
|
||||
['True', 'False'].each { transpose ->
|
||||
project.exec {
|
||||
quietExec {
|
||||
workingDir targetDir
|
||||
executable project.externalTool("python3")
|
||||
args = ['-B', 'createLevAutomata.py', num, transpose, "${momanDir}/finenight/python"]
|
||||
|
|
|
@ -72,5 +72,58 @@ allprojects {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utility function similar to project.exec but not emitting
|
||||
// any output unless an error code is returned from the executed command.
|
||||
quietExec = { closure ->
|
||||
// Resolve any properties against the provided closure.
|
||||
resolveStrategy = Closure.DELEGATE_ONLY
|
||||
delegate = closure.delegate
|
||||
|
||||
File outputFile = File.createTempFile("exec-output-", ".txt", getTemporaryDir())
|
||||
ExecResult result
|
||||
boolean saveIgnoreExitValue
|
||||
ExecSpec saveExecSpec
|
||||
|
||||
outputFile.withOutputStream { output ->
|
||||
// we want to capture both stdout and stderr to the same
|
||||
// stream but gradle attempts to close these separately
|
||||
// (it has two independent pumping threads) and it can happen
|
||||
// that one still tries to write something when the other closed
|
||||
// the underlying output stream.
|
||||
def wrapped = new java.io.FilterOutputStream(output) {
|
||||
public void close() {
|
||||
// no-op. we close this stream manually.
|
||||
}
|
||||
}
|
||||
|
||||
result = project.exec { ExecSpec execSpec ->
|
||||
project.configure(execSpec, closure)
|
||||
|
||||
saveIgnoreExitValue = execSpec.ignoreExitValue
|
||||
saveExecSpec = execSpec
|
||||
|
||||
standardOutput = wrapped
|
||||
errorOutput = wrapped
|
||||
ignoreExitValue true
|
||||
}
|
||||
}
|
||||
|
||||
if (result.getExitValue() != 0) {
|
||||
// Pipe the output to console. Intentionally skips any encoding conversion
|
||||
// and pumps raw bytes.
|
||||
logger.error(new String(outputFile.bytes))
|
||||
|
||||
if (!saveIgnoreExitValue) {
|
||||
result.rethrowFailure()
|
||||
throw new GradleException("The executed process ${saveExecSpec.executable} " +
|
||||
"returned an odd status " +
|
||||
"code: ${result.exitValue}, " +
|
||||
"output at: ${outputFile} (and logged above).")
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue