: new UnixCommandBuilder();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ByteArrayOutputStream errStream = new ByteArrayOutputStream();
ExecHandleBuilder builder = new ExecHandleBuilder() {
@Override
public File getWorkingDir() {
// Override this, so that the working directory is not canonicalised. Some int tests require that
// the working directory is not canonicalised
return ForkingGradleExecuter.this.getWorkingDir();
}
};
builder.setStandardOutput(outStream);
builder.setErrorOutput(errStream);
builder.environment("GRADLE_HOME", "");
builder.environment("JAVA_HOME", System.getProperty("java.home"));
builder.environment("GRADLE_OPTS", "-ea");
builder.environment(getEnvironmentVars());
builder.workingDir(getWorkingDir());
commandBuilder.build(builder);
builder.args(getAllArgs());
LOG.info(String.format("Execute in %s with: %s %s", builder.getWorkingDir(), builder.getExecutable(),
builder.getArgs()));
ExecHandle proc = builder.build();
int exitValue = proc.start().waitForFinish().getExitValue();
String output = outStream.toString();
String error = errStream.toString();
boolean failed = exitValue != 0;
LOG.info("OUTPUT: " + output);
LOG.info("ERROR: " + error);
if (failed != expectFailure) {
String message = String.format("Gradle execution %s in %s with: %s %s%nOutput:%n%s%nError:%n%s%n-----%n",
expectFailure ? "did not fail" : "failed", builder.getWorkingDir(), builder.getExecutable(),
builder.getArgs(), output, error);
System.out.println(message);
throw new RuntimeException(message);
}
return GUtil.map("output", output, "error", error);
}