use of org.gradle.process.ExecResult in project gradle by gradle.
the class ForkingGradleHandle method waitForStop.
protected ExecutionResult waitForStop(boolean expectFailure) {
ExecHandle execHandle = getExecHandle();
ExecResult execResult = execHandle.waitForFinish();
if (durationMeasurement != null) {
durationMeasurement.stop();
}
// nop if all ok
execResult.rethrowFailure();
String output = getStandardOutput();
String error = getErrorOutput();
boolean didFail = execResult.getExitValue() != 0;
ExecutionResult executionResult = expectFailure ? toExecutionFailure(output, error) : toExecutionResult(output, error);
if (didFail != expectFailure) {
String message = String.format("Gradle execution %s in %s with: %s %s%nOutput:%n%s%n-----%nError:%n%s%n-----%nExecution result:%n%s%n-----%n", expectFailure ? "did not fail" : "failed", execHandle.getDirectory(), execHandle.getCommand(), execHandle.getArguments(), output, error, execResult.toString());
Exception exception = executionResult instanceof OutputScrapingExecutionFailure ? ((OutputScrapingExecutionFailure) executionResult).getException() : null;
throw exception == null ? new UnexpectedBuildFailure(message) : new UnexpectedBuildFailure(message, exception);
}
resultAssertion.execute(executionResult);
return executionResult;
}
use of org.gradle.process.ExecResult in project gradle by gradle.
the class JavaInstallationProbe method getMetadataInternal.
private EnumMap<SysProp, String> getMetadataInternal(File jdkPath) {
JavaExecAction exec = factory.newJavaExecAction();
exec.executable(javaExe(jdkPath, "java"));
File workingDir = Files.createTempDir();
exec.setWorkingDir(workingDir);
exec.setClasspath(new SimpleFileCollection(workingDir));
try {
writeProbe(workingDir);
exec.setMain(JavaProbe.CLASSNAME);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exec.setStandardOutput(baos);
ByteArrayOutputStream errorOutput = new ByteArrayOutputStream();
exec.setErrorOutput(errorOutput);
exec.setIgnoreExitValue(true);
ExecResult result = exec.execute();
int exitValue = result.getExitValue();
if (exitValue == 0) {
return parseExecOutput(baos.toString());
}
return error("Command returned unexpected result code: " + exitValue + "\nError output:\n" + errorOutput);
} catch (ExecException ex) {
return error(ex.getMessage());
} finally {
try {
FileUtils.deleteDirectory(workingDir);
} catch (IOException e) {
throw new GradleException("Unable to delete temp directory", e);
}
}
}
use of org.gradle.process.ExecResult in project gradle by gradle.
the class GccVersionDeterminer method transform.
private String transform(File gccBinary, List<String> args) {
ExecAction exec = execActionFactory.newExecAction();
exec.executable(gccBinary.getAbsolutePath());
exec.setWorkingDir(gccBinary.getParentFile());
exec.args(args);
StreamByteBuffer buffer = new StreamByteBuffer();
exec.setStandardOutput(buffer.getOutputStream());
exec.setErrorOutput(NullOutputStream.INSTANCE);
exec.setIgnoreExitValue(true);
ExecResult result = exec.execute();
int exitValue = result.getExitValue();
if (exitValue == 0) {
return buffer.readAsString();
} else {
return null;
}
}
use of org.gradle.process.ExecResult in project gradle by gradle.
the class CommandLineJavaCompiler method executeCompiler.
private void executeCompiler(ExecHandle handle) {
handle.start();
ExecResult result = handle.waitForFinish();
if (result.getExitValue() != 0) {
throw new CompilationFailedException(result.getExitValue());
}
}
use of org.gradle.process.ExecResult in project gradle by gradle.
the class ProcessLauncherServer method launchExternalProcess.
/**
* This launches an external process in a thread and waits for it to exit.
*/
private void launchExternalProcess() {
Thread thread = new Thread(new Runnable() {
public void run() {
ExecutionInfo executionInfo = null;
ExecHandle execHandle = null;
ByteArrayOutputStream output = null;
try {
executionInfo = protocol.getExecutionInfo(getPort());
ExecHandleBuilder builder = new DefaultExecHandleBuilder();
builder.workingDir(executionInfo.getWorkingDirectory());
builder.commandLine((Object[]) executionInfo.getCommandLineArguments());
builder.environment(executionInfo.getEnvironmentVariables());
output = new ByteArrayOutputStream();
builder.setStandardOutput(output);
builder.setErrorOutput(output);
execHandle = builder.build();
setExternalProcess(execHandle);
execHandle.start();
} catch (Throwable e) {
LOGGER.error("Starting external process", e);
notifyClientExited(-1, e.getMessage());
setExternalProcess(null);
return;
}
ExecResult result = execHandle.waitForFinish();
LOGGER.debug("External process completed with exit code {}", result.getExitValue());
//clear our external process member variable (we're using our local variable below). This is so we know the process has already stopped.
setExternalProcess(null);
executionInfo.processExecutionComplete();
notifyClientExited(result.getExitValue(), output.toString());
}
});
thread.start();
}
Aggregations