Search in sources :

Example 1 with JavaExecAction

use of org.gradle.process.internal.JavaExecAction 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);
        }
    }
}
Also used : JavaExecAction(org.gradle.process.internal.JavaExecAction) SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) ExecException(org.gradle.process.internal.ExecException) GradleException(org.gradle.api.GradleException) ExecResult(org.gradle.process.ExecResult)

Example 2 with JavaExecAction

use of org.gradle.process.internal.JavaExecAction in project gradle by gradle.

the class DefaultFileOperations method javaexec.

public ExecResult javaexec(Action<? super JavaExecSpec> action) {
    JavaExecAction javaExecAction = instantiator.newInstance(DefaultJavaExecAction.class, fileResolver);
    action.execute(javaExecAction);
    return javaExecAction.execute();
}
Also used : JavaExecAction(org.gradle.process.internal.JavaExecAction) DefaultJavaExecAction(org.gradle.process.internal.DefaultJavaExecAction)

Aggregations

JavaExecAction (org.gradle.process.internal.JavaExecAction)2 GradleException (org.gradle.api.GradleException)1 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)1 ExecResult (org.gradle.process.ExecResult)1 DefaultJavaExecAction (org.gradle.process.internal.DefaultJavaExecAction)1 ExecException (org.gradle.process.internal.ExecException)1