Skip to content

Commit

Permalink
Convert Version to Java - clusterformation part1 (#32009)
Browse files Browse the repository at this point in the history
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

This backport pulls in some changes from the non backported #27397
but that should be fine
  • Loading branch information
alpar-t committed Jul 18, 2018
1 parent ba0ecae commit f1007c6
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 240 deletions.
41 changes: 0 additions & 41 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/LoggedExec.java

This file was deleted.

157 changes: 0 additions & 157 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy

This file was deleted.

44 changes: 44 additions & 0 deletions buildSrc/src/main/java/org/elasticsearch/gradle/LoggedExec.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.elasticsearch.gradle;

import org.gradle.api.GradleException;
import org.gradle.api.tasks.Exec;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;

/**
* A wrapper around gradle's Exec task to capture output and log on error.
*/
@SuppressWarnings("unchecked")
public class LoggedExec extends Exec {

protected ByteArrayOutputStream output = new ByteArrayOutputStream();

public LoggedExec() {
if (getLogger().isInfoEnabled() == false) {
setStandardOutput(output);
setErrorOutput(output);
setIgnoreExitValue(true);
doLast((unused) -> {
if (getExecResult().getExitValue() != 0) {
try {
for (String line : output.toString("UTF-8").split("\\R")) {
getLogger().error(line);
}
} catch (UnsupportedEncodingException e) {
throw new GradleException("Failed to read exec output", e);
}
throw new GradleException(
String.format(
"Process '%s %s' finished with non-zero exit value %d",
getExecutable(),
getArgs(),
getExecResult().getExitValue()
)
);
}
}
);
}
}
}
Loading

0 comments on commit f1007c6

Please sign in to comment.