org.gradle.process.ExecResult Java Examples

The following examples show how to use org.gradle.process.ExecResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitUtils.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Nullable
public String findTravisSlug(Project project) {

    String travisSlugEnv = System.getenv("TRAVIS_REPO_SLUG");
    if (travisSlugEnv != null) {
        return travisSlugEnv.trim();
    }

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    ExecResult travisSlugResult = project.exec(execSpec -> {
        execSpec.workingDir(project.getProjectDir());
        execSpec.commandLine("git", "config", "travis.slug");
        execSpec.setStandardOutput(outputStream);
        execSpec.setIgnoreExitValue(true);
    });

    if (travisSlugResult.getExitValue() == 0) {
        return outputStream.toString().trim();
    }
    return null;
}
 
Example #2
Source File: GitUtils.java    From gradle-plugins with MIT License 6 votes vote down vote up
@Nullable
public String findTravisSlug(Project project) {

    String travisSlugEnv = System.getenv("TRAVIS_REPO_SLUG");
    if (travisSlugEnv != null) {
        return travisSlugEnv.trim();
    }

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    ExecResult travisSlugResult = project.exec(execSpec -> {
        execSpec.workingDir(project.getProjectDir());
        execSpec.commandLine("git", "config", "travis.slug");
        execSpec.setStandardOutput(outputStream);
        execSpec.setIgnoreExitValue(true);
    });

    if (travisSlugResult.getExitValue() == 0) {
        return outputStream.toString().trim();
    }
    return null;
}
 
Example #3
Source File: DockerizedExecHandle.java    From gradle-dockerized-test-plugin with Apache License 2.0 6 votes vote down vote up
public ExecResult waitForFinish() {
    lock.lock();
    try {
        while (!state.isTerminal()) {
            try {
                stateChanged.await();
            } catch (InterruptedException e) {
                //ok, wrapping up...
                throw UncheckedException.throwAsUncheckedException(e);
            }
        }
    } finally {
        lock.unlock();
    }

    // At this point:
    // If in daemon mode, the process has started successfully and all streams to the process have been closed
    // If in fork mode, the process has completed and all cleanup has been done
    // In both cases, all asynchronous work for the process has completed and we're done

    return result();
}
 
Example #4
Source File: GitUtils.java    From gradle-plugins with MIT License 6 votes vote down vote up
public String getTag(Project project) {
    String travisTagEnv = System.getenv("TRAVIS_TAG");

    if (travisTagEnv != null) {
        return travisTagEnv.trim();
    }

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    ExecResult execResult = project.exec(execSpec -> {
        execSpec.workingDir(project.getProjectDir());
        execSpec.commandLine("git", "tag", "--points-at", "HEAD");
        execSpec.setStandardOutput(outputStream);
    });

    if (execResult.getExitValue() == 0) {
        String gitTag = outputStream.toString().trim();
        if (!gitTag.isEmpty()) {
            return gitTag;
        }
    }

    return "HEAD";
}
 
Example #5
Source File: DefaultExecHandle.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ExecResult waitForFinish() {
    lock.lock();
    try {
        while (!stateIn(ExecHandleState.SUCCEEDED, ExecHandleState.ABORTED, ExecHandleState.FAILED, ExecHandleState.DETACHED)) {
            try {
                condition.await();
            } catch (InterruptedException e) {
                //ok, wrapping up...
            }
        }
    } finally {
        lock.unlock();
    }

    executor.stop();

    return result();
}
 
Example #6
Source File: ForkingGradleHandle.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected ExecutionResult waitForStop(boolean expectFailure) {
    ExecHandle execHandle = getExecHandle();
    ExecResult execResult = execHandle.waitForFinish();
    execResult.rethrowFailure(); // nop if all ok

    String output = getStandardOutput();
    String error = getErrorOutput();

    boolean didFail = execResult.getExitValue() != 0;
    if (didFail != expectFailure) {
        String message = String.format("Gradle execution %s in %s with: %s %s%nOutput:%n%s%n-----%nError:%n%s%n-----%n",
                expectFailure ? "did not fail" : "failed", execHandle.getDirectory(), execHandle.getCommand(), execHandle.getArguments(), output, error);
        throw new UnexpectedBuildFailure(message);
    }

    ExecutionResult executionResult = expectFailure ? toExecutionFailure(output, error) : toExecutionResult(output, error);
    resultAssertion.execute(executionResult);
    return executionResult;
}
 
Example #7
Source File: DefaultWorkerProcess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ExecResult waitForStop() {
    try {
        return execHandle.waitForFinish().assertNormalExitValue();
    } finally {
        cleanup();
    }
}
 
Example #8
Source File: DefaultWorkerProcess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onProcessStop(ExecResult execResult) {
    lock.lock();
    try {
        try {
            execResult.rethrowFailure().assertNormalExitValue();
        } catch (Throwable e) {
            processFailure = e;
        }
        running = false;
        condition.signalAll();
    } finally {
        lock.unlock();
    }
}
 
Example #9
Source File: AspectJCompiler.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void executeCompiler(ExecHandle handle) {
    handle.start();
    ExecResult result = handle.waitForFinish();
    if (result.getExitValue() != 0) {
        throw new CompilationFailedException(result.getExitValue());
    }
}
 
Example #10
Source File: DefaultWorkerProcess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onProcessStop(ExecResult execResult) {
    lock.lock();
    try {
        try {
            execResult.rethrowFailure().assertNormalExitValue();
        } catch (Throwable e) {
            processFailure = e;
        }
        running = false;
        condition.signalAll();
    } finally {
        lock.unlock();
    }
}
 
Example #11
Source File: DaemonGreeter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DaemonStartupInfo parseDaemonOutput(String output, ExecResult result) {
    DaemonStartupCommunication startupCommunication = new DaemonStartupCommunication();
    if (!startupCommunication.containsGreeting(output)) {
        throw new GradleException(prepareMessage(output, result));
    }
    String[] lines = output.split("\n");
    //Assuming that the diagnostics were printed out to the last line. It's not bullet-proof but seems to be doing fine.
    String lastLine = lines[lines.length-1];
    return startupCommunication.readDiagnostics(lastLine);
}
 
Example #12
Source File: VirtualEnvCustomizer.java    From pygradle with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(File file) {
    if (distutilsCfg != null) {
        final Path path = file.toPath();
        try {
            Files.write(path.resolve(
                Paths.get("virtualenv_embedded", "distutils.cfg")),
                distutilsCfg.getBytes(),
                StandardOpenOption.APPEND);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        // Since virtualenv-16.2.0 the rebuild script was renamed and relocated.
        Path rebuildScriptPath = path.resolve(Paths.get("bin", "rebuild-script.py"));
        if (!Files.exists(rebuildScriptPath)) {
            rebuildScriptPath = path.resolve(Paths.get("tasks", "update_embedded.py"));
        }

        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
        final File rebuildScript = rebuildScriptPath.toFile();
        ExecResult execResult = exec.exec(execSpec -> {
            execSpec.commandLine(pythonDetails.getSystemPythonInterpreter(), rebuildScript);
            execSpec.setStandardOutput(stream);
            execSpec.setErrorOutput(stream);
            execSpec.setIgnoreExitValue(true);
        });

        /*
         * Starting with virtualenv-16.1.0 the rebuild script returns 1 when there's a change.
         * Since the change is exactly what we want, we cannot allow the failure for exit code 1.
         */
        if (execResult.getExitValue() != NO_CHANGE && execResult.getExitValue() != CHANGED) {
            log.lifecycle(stream.toString());
            execResult.assertNormalExitValue();
        }

        log.info("Customized distutils.cfg");
    }
}
 
Example #13
Source File: AbstractPythonMainSourceDefaultTask.java    From pygradle with Apache License 2.0 5 votes vote down vote up
void executePythonProcess() {

        final TeeOutputContainer container = new TeeOutputContainer(stdOut, errOut);

        ExecResult result = externalExec.exec(execSpec -> {
            execSpec.environment(getComponent().pythonEnvironment);
            execSpec.environment(getComponent().pythonEnvironmentDistgradle);
            execSpec.commandLine(getPythonDetails().getVirtualEnvInterpreter());
            // arguments are passed to the python interpreter
            execSpec.args(arguments);
            // subArguments are arguments for previous arguments. eg: arguments to py.test like -k
            execSpec.args(subArguments);
            // additionalArguments are same as subArguments, but are expected from user's build script
            execSpec.args(additionalArguments);
            execSpec.setIgnoreExitValue(true);

            container.setOutputs(execSpec);

            configureExecution(execSpec);
        });

        output = container.getCommandOutput();

        if (!ignoreExitValue) {
            result.assertNormalExitValue();
        }

        processResults(result);
    }
 
Example #14
Source File: AbstractPipAction.java    From pygradle with Apache License 2.0 5 votes vote down vote up
ExecResult execCommand(Map<String, String> mergedEnv, List<String> commandLine, OutputStream stream) {
    return externalExec.exec(execSpec -> {
        execSpec.environment(mergedEnv);
        execSpec.commandLine(commandLine);
        execSpec.setStandardOutput(stream);
        execSpec.setErrorOutput(stream);
        execSpec.setIgnoreExitValue(true);
    });
}
 
Example #15
Source File: DefaultExecHandle.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ExecResult result() {
    lock.lock();
    try {
        execResult.rethrowFailure();
        return execResult;
    } finally {
        lock.unlock();
    }
}
 
Example #16
Source File: DefaultWorkerProcess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ExecResult waitForStop() {
    try {
        return execHandle.waitForFinish().assertNormalExitValue();
    } finally {
        cleanup();
    }
}
 
Example #17
Source File: GitUtils.java    From gradle-plugins with MIT License 5 votes vote down vote up
public String getRemoteUrl(Project project, String remote) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    ExecResult execResult = project.exec(execSpec -> {
        execSpec.workingDir(project.getProjectDir());
        execSpec.commandLine("git", "ls-remote", "--get-url", remote);
        execSpec.setStandardOutput(outputStream);
    });

    execResult.rethrowFailure().assertNormalExitValue();

    return outputStream.toString().trim();
}
 
Example #18
Source File: DefaultWorkerProcess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onProcessStop(ExecResult execResult) {
    lock.lock();
    try {
        try {
            execResult.rethrowFailure().assertNormalExitValue();
        } catch (Throwable e) {
            processFailure = e;
        }
        running = false;
        condition.signalAll();
    } finally {
        lock.unlock();
    }
}
 
Example #19
Source File: DefaultWorkerProcess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ExecResult waitForStop() {
    try {
        return execHandle.waitForFinish().assertNormalExitValue();
    } finally {
        cleanup();
    }
}
 
Example #20
Source File: DefaultWorkerProcess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onProcessStop(ExecResult execResult) {
    lock.lock();
    try {
        try {
            execResult.rethrowFailure().assertNormalExitValue();
        } catch (Throwable e) {
            processFailure = e;
        }
        running = false;
        condition.signalAll();
    } finally {
        lock.unlock();
    }
}
 
Example #21
Source File: DefaultWorkerProcess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ExecResult waitForStop() {
    try {
        return execHandle.waitForFinish().assertNormalExitValue();
    } finally {
        cleanup();
    }
}
 
Example #22
Source File: DefaultExecHandle.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ExecResult result() {
    lock.lock();
    try {
        execResult.rethrowFailure();
        return execResult;
    } finally {
        lock.unlock();
    }
}
 
Example #23
Source File: DefaultJavaExecAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ExecResult execute() {
    ExecHandle execHandle = build();
    ExecResult execResult = execHandle.start().waitForFinish();
    if (!isIgnoreExitValue()) {
        execResult.assertNormalExitValue();
    }
    return execResult;
}
 
Example #24
Source File: DefaultExecHandle.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ExecResult result() {
    lock.lock();
    try {
        execResult.rethrowFailure();
        return execResult;
    } finally {
        lock.unlock();
    }
}
 
Example #25
Source File: CommandLineJavaCompiler.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void executeCompiler(ExecHandle handle) {
    handle.start();
    ExecResult result = handle.waitForFinish();
    if (result.getExitValue() != 0) {
        throw new CompilationFailedException(result.getExitValue());
    }
}
 
Example #26
Source File: DaemonGreeter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DaemonDiagnostics parseDaemonOutput(String output, ExecResult result) {
    if (!new DaemonStartupCommunication().containsGreeting(output)) {
        throw new GradleException(prepareMessage(output, result));
    }
    String[] lines = output.split("\n");
    //TODO SF don't assume it is the last line
    String lastLine = lines[lines.length-1];
    return new DaemonStartupCommunication().readDiagnostics(lastLine);
}
 
Example #27
Source File: DefaultFileOperations.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExecResult exec(Closure cl) {
    ExecAction execAction = ConfigureUtil.configure(cl, instantiator.newInstance(DefaultExecAction.class, fileResolver));
    return execAction.execute();
}
 
Example #28
Source File: DefaultExecHandle.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExecResult assertNormalExitValue() throws ExecException {
    if (exitValue != 0) {
        throw new ExecException(String.format("Process '%s' finished with non-zero exit value %d", displayName, exitValue));
    }
    return this;
}
 
Example #29
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExecResult javaexec(Closure closure) {
    return processOperations.javaexec(closure);
}
 
Example #30
Source File: DefaultScript.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ExecResult exec(Closure closure) {
    return processOperations.exec(closure);
}