use of org.gradle.process.internal.ExecException 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.internal.ExecException in project gradle by gradle.
the class JavadocGenerator method execute.
@Override
public WorkResult execute(JavadocSpec spec) {
JavadocExecHandleBuilder javadocExecHandleBuilder = new JavadocExecHandleBuilder(execActionFactory);
javadocExecHandleBuilder.setExecutable(spec.getExecutable());
javadocExecHandleBuilder.execDirectory(spec.getWorkingDir()).options(spec.getOptions()).optionsFile(spec.getOptionsFile());
ExecAction execAction = javadocExecHandleBuilder.getExecHandle();
if (spec.isIgnoreFailures()) {
execAction.setIgnoreExitValue(true);
}
try {
execAction.execute();
} catch (ExecException e) {
LOG.info("Problems generating Javadoc." + "\n Command line issued: " + execAction.getCommandLine() + "\n Generated Javadoc options file has following contents:\n------\n{}------", GFileUtils.readFileQuietly(spec.getOptionsFile()));
throw new GradleException(String.format("Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '%s'", spec.getOptionsFile()), e);
}
return new SimpleWorkResult(true);
}
use of org.gradle.process.internal.ExecException in project gradle by gradle.
the class DefaultCommandLineToolInvocationWorker method execute.
@Override
public void execute(CommandLineToolInvocation invocation) {
ExecAction toolExec = execActionFactory.newExecAction();
toolExec.executable(executable);
if (invocation.getWorkDirectory() != null) {
GFileUtils.mkdirs(invocation.getWorkDirectory());
toolExec.workingDir(invocation.getWorkDirectory());
}
toolExec.args(invocation.getArgs());
if (!invocation.getPath().isEmpty()) {
String pathVar = OperatingSystem.current().getPathVar();
String toolPath = Joiner.on(File.pathSeparator).join(invocation.getPath());
toolPath = toolPath + File.pathSeparator + System.getenv(pathVar);
toolExec.environment(pathVar, toolPath);
if (OperatingSystem.current().isWindows() && toolExec.getEnvironment().containsKey(pathVar.toUpperCase())) {
toolExec.getEnvironment().remove(pathVar.toUpperCase());
}
}
toolExec.environment(invocation.getEnvironment());
StreamByteBuffer errOutput = new StreamByteBuffer();
StreamByteBuffer stdOutput = new StreamByteBuffer();
toolExec.setErrorOutput(errOutput.getOutputStream());
toolExec.setStandardOutput(stdOutput.getOutputStream());
try {
toolExec.execute();
invocation.getLogger().operationSuccess(invocation.getDescription(), combineOutput(stdOutput, errOutput));
} catch (ExecException e) {
invocation.getLogger().operationFailed(invocation.getDescription(), combineOutput(stdOutput, errOutput));
throw new CommandLineToolInvocationFailure(invocation, String.format("%s failed while %s.", name, invocation.getDescription()));
}
}
use of org.gradle.process.internal.ExecException in project gradle by gradle.
the class DefaultWorkerProcess method doStart.
private void doStart() {
lock.lock();
try {
running = true;
} finally {
lock.unlock();
}
execHandle.start();
Date connectExpiry = new Date(System.currentTimeMillis() + connectTimeout);
lock.lock();
try {
while (connection == null && running) {
try {
if (!condition.awaitUntil(connectExpiry)) {
throw new ExecException(format("Unable to connect to the child process '%s'.\n" + "It is likely that the child process have crashed - please find the stack trace in the build log.\n" + "This exception might occur when the build machine is extremely loaded.\n" + "The connection attempt hit a timeout after %.1f seconds (last known process state: %s, running: %s).", execHandle, ((double) connectTimeout) / 1000, execHandle.getState(), running));
}
} catch (InterruptedException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
if (connection == null) {
if (processFailure != null) {
throw UncheckedException.throwAsUncheckedException(processFailure);
} else {
throw new ExecException(format("Never received a connection from %s.", execHandle));
}
}
} finally {
lock.unlock();
}
}
Aggregations