Skip to content

Commit 23198ea

Browse files
authored
Convert Version to Java - clusterformation part1 (#32009)
Implement buildSrc Version in java - This allows to move all all .java files from .groovy. - Will prevent eclipse from tangling up in this setup - make it possible to use Version from Java
1 parent f174f72 commit 23198ea

File tree

9 files changed

+449
-230
lines changed

9 files changed

+449
-230
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/LoggedExec.java

-41
This file was deleted.

buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy

-147
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.elasticsearch.gradle;
2+
3+
import org.gradle.api.GradleException;
4+
import org.gradle.api.tasks.Exec;
5+
6+
import java.io.ByteArrayOutputStream;
7+
import java.io.UnsupportedEncodingException;
8+
9+
/**
10+
* A wrapper around gradle's Exec task to capture output and log on error.
11+
*/
12+
@SuppressWarnings("unchecked")
13+
public class LoggedExec extends Exec {
14+
15+
protected ByteArrayOutputStream output = new ByteArrayOutputStream();
16+
17+
public LoggedExec() {
18+
if (getLogger().isInfoEnabled() == false) {
19+
setStandardOutput(output);
20+
setErrorOutput(output);
21+
setIgnoreExitValue(true);
22+
doLast((unused) -> {
23+
if (getExecResult().getExitValue() != 0) {
24+
try {
25+
for (String line : output.toString("UTF-8").split("\\R")) {
26+
getLogger().error(line);
27+
}
28+
} catch (UnsupportedEncodingException e) {
29+
throw new GradleException("Failed to read exec output", e);
30+
}
31+
throw new GradleException(
32+
String.format(
33+
"Process '%s %s' finished with non-zero exit value %d",
34+
getExecutable(),
35+
getArgs(),
36+
getExecResult().getExitValue()
37+
)
38+
);
39+
}
40+
}
41+
);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)