Java Code Examples for org.gradle.process.ExecResult#getExitValue()
The following examples show how to use
org.gradle.process.ExecResult#getExitValue() .
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: GccVersionDeterminer.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private String transform(File gccBinary, List<String> args) { ExecAction exec = execActionFactory.newExecAction(); exec.executable(gccBinary.getAbsolutePath()); exec.setWorkingDir(gccBinary.getParentFile()); exec.args(args); ByteArrayOutputStream baos = new ByteArrayOutputStream(); exec.setStandardOutput(baos); exec.setErrorOutput(new ByteArrayOutputStream()); exec.setIgnoreExitValue(true); ExecResult result = exec.execute(); int exitValue = result.getExitValue(); if (exitValue == 0) { return new String(baos.toByteArray()); } else { return null; } }
Example 2
Source File: GitUtils.java From gradle-plugins with MIT License | 6 votes |
public File findWorkingDirectory(Project project) { String travisBuildDirEnv = System.getenv("TRAVIS_BUILD_DIR"); if (travisBuildDirEnv != null) { return new File(travisBuildDirEnv); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ExecResult execResult = project.exec(execSpec -> { execSpec.workingDir(project.getProjectDir()); execSpec.commandLine("git", "rev-parse", "--show-toplevel"); execSpec.setStandardOutput(outputStream); execSpec.setIgnoreExitValue(true); }); if (execResult.getExitValue() == 0) { return new File(outputStream.toString().trim()); } else { return null; } }
Example 3
Source File: ForkingGradleHandle.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
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 4
Source File: GccVersionDeterminer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private String transform(File gccBinary, List<String> args) { ExecAction exec = execActionFactory.newExecAction(); exec.executable(gccBinary.getAbsolutePath()); exec.setWorkingDir(gccBinary.getParentFile()); exec.args(args); ByteArrayOutputStream baos = new ByteArrayOutputStream(); exec.setStandardOutput(baos); exec.setErrorOutput(new ByteArrayOutputStream()); exec.setIgnoreExitValue(true); ExecResult result = exec.execute(); int exitValue = result.getExitValue(); if (exitValue == 0) { return new String(baos.toByteArray()); } else { return null; } }
Example 5
Source File: GccVersionDeterminer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
public String transform(File gccBinary) { ExecAction exec = execActionFactory.newExecAction(); exec.executable(gccBinary.getAbsolutePath()); exec.setWorkingDir(gccBinary.getParentFile()); exec.args("-dM", "-E", "-"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); exec.setStandardOutput(baos); exec.setIgnoreExitValue(true); ExecResult result = exec.execute(); int exitValue = result.getExitValue(); if (exitValue == 0) { return new String(baos.toByteArray()); } else { return null; } }
Example 6
Source File: Flake8Task.java From pygradle with Apache License 2.0 | 6 votes |
@Override public void processResults(ExecResult execResult) { // If the first run of flake8 fails, trying running it again but ignoring the // rules/checks added by the previous version bump. if ((execResult.getExitValue() != 0) && !ignoringNewRules && (ignoreRules.size() > 0)) { ignoringNewRules = true; firstRunOutput = this.output; subArgs("--extend-ignore=" + String.join(",", ignoreRules)); executePythonProcess(); } else if ((execResult.getExitValue() == 0) && ignoringNewRules) { // The previous run failed, but flake8 succeeds when we ignore the most recent rules. // Warn the user that they are failing one or more of the new rules. log.warn(String.format(IGNORED_RULES_MSG, String.join(", ", ignoreRules), firstRunOutput)); } else { execResult.assertNormalExitValue(); } }
Example 7
Source File: PythonVersionParser.java From pygradle with Apache License 2.0 | 6 votes |
public static PythonVersion parsePythonVersion(final Project project, final File pythonInterpreter) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ExecResult execResult = project.exec(execSpec -> { execSpec.setExecutable(pythonInterpreter.getAbsolutePath()); execSpec.setArgs(Collections.singletonList("--version")); execSpec.setStandardOutput(outputStream); execSpec.setErrorOutput(outputStream); execSpec.setIgnoreExitValue(true); }); String output = outputStream.toString(); if (execResult.getExitValue() != 0) { throw new GradleException(output); } String versionString = output.trim().split(" ")[1]; return new PythonVersion(versionString); }
Example 8
Source File: ForkingGradleHandle.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
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 9
Source File: GitUtils.java From gradle-plugins with MIT License | 6 votes |
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 10
Source File: GitUtils.java From gradle-plugins with MIT License | 6 votes |
@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 11
Source File: GitUtils.java From gradle-plugins with MIT License | 6 votes |
@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 12
Source File: ForkingGradleHandle.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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 13
Source File: GccVersionDeterminer.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public String transform(File gccBinary) { ExecAction exec = execActionFactory.newExecAction(); exec.executable(gccBinary.getAbsolutePath()); exec.setWorkingDir(gccBinary.getParentFile()); exec.args("-dM", "-E", "-"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); exec.setStandardOutput(baos); exec.setIgnoreExitValue(true); ExecResult result = exec.execute(); int exitValue = result.getExitValue(); if (exitValue == 0) { return new String(baos.toByteArray()); } else { return null; } }
Example 14
Source File: ForkingGradleHandle.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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 15
Source File: CommandLineJavaCompiler.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void executeCompiler(ExecHandle handle) { handle.start(); ExecResult result = handle.waitForFinish(); if (result.getExitValue() != 0) { throw new CompilationFailedException(result.getExitValue()); } }
Example 16
Source File: CommandLineJavaCompiler.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void executeCompiler(ExecHandle handle) { handle.start(); ExecResult result = handle.waitForFinish(); if (result.getExitValue() != 0) { throw new CompilationFailedException(result.getExitValue()); } }
Example 17
Source File: PipInstallAction.java From pygradle with Apache License 2.0 | 4 votes |
@Override void doPipOperation(PackageInfo packageInfo, List<String> extraArgs) { throwIfPythonVersionIsNotSupported(packageInfo); String pyVersion = pythonDetails.getPythonVersion().getPythonMajorMinor(); String sanitizedName = packageInfo.getName().replace('-', '_'); // See: https://www.python.org/dev/peps/pep-0376/ File egg = sitePackagesPath.resolve(sanitizedName + "-" + packageInfo.getVersion() + "-py" + pyVersion + ".egg-info").toFile(); File dist = sitePackagesPath.resolve(sanitizedName + "-" + packageInfo.getVersion() + ".dist-info").toFile(); if (!packageSettings.requiresSourceBuild(packageInfo) && (project.file(egg).exists() || project.file(dist).exists())) { if (PythonHelpers.isPlainOrVerbose(project)) { logger.lifecycle("Skipping {} - Installed", packageInfo.toShortHand()); } wheelBuilder.updateWheelReadiness(packageInfo); return; } Map<String, String> mergedEnv = environmentMerger.mergeEnvironments( Arrays.asList(baseEnvironment, packageSettings.getEnvironment(packageInfo))); List<String> commandLine = makeCommandLine(packageInfo, extraArgs); if (PythonHelpers.isPlainOrVerbose(project)) { logger.lifecycle("Installing {}", packageInfo.toShortHand()); } OutputStream stream = new ByteArrayOutputStream(); ExecResult installResult = execCommand(mergedEnv, commandLine, stream); String message = stream.toString().trim(); if (installResult.getExitValue() != 0) { /* * TODO: maintain a list of packages that failed to install, and report a failure * report at the end. We can leverage our domain expertise here to provide very * meaningful errors. E.g., we see lxml failed to install, do you have libxml2 * installed? E.g., we see pyOpenSSL>0.15 failed to install, do you have libffi * installed? */ logger.error("Error installing package using `{}`", commandLine); logger.error(message); throw PipExecutionException.failedInstall(packageInfo, message); } else { logger.info(message); } }
Example 18
Source File: CreateVirtualEnvAction.java From pygradle with Apache License 2.0 | 4 votes |
public void buildVenv(@Nullable Consumer<File> customize) { PipConfFile pipConfFile = new PipConfFile(project, pythonDetails); File packageDir = makeTempDir().toFile(); getPyGradleBootstrap(project).getFiles().forEach(file -> { project.copy(copySpec -> { copySpec.from(project.tarTree(file.getPath())); copySpec.into(packageDir); copySpec.eachFile(it -> { // Remove the virtualenv-<version> from the file. Path pathInsideTar = Paths.get(it.getPath()); if (pathInsideTar.getNameCount() > 1) { it.setPath(pathInsideTar.subpath(1, pathInsideTar.getNameCount()).toString()); } }); }); }); if (null != customize) { customize.accept(packageDir); } // In virtualenv-16.1.0 the install script was relocated and will be in 17+. Path installScriptPath = Paths.get(packageDir.toString(), "virtualenv.py"); if (!Files.exists(installScriptPath)) { installScriptPath = Paths.get(packageDir.toString(), "src", "virtualenv.py"); } final File installScript = installScriptPath.toFile(); OutputStream outputStream = new ByteArrayOutputStream(); ExecResult execResult = project.exec(execSpec -> { container.setOutputs(execSpec); execSpec.commandLine( pythonDetails.getSystemPythonInterpreter(), installScript, "--never-download", "--python", pythonDetails.getSystemPythonInterpreter(), "--prompt", pythonDetails.getVirtualEnvPrompt(), pythonDetails.getVirtualEnv() ); execSpec.setErrorOutput(outputStream); execSpec.setStandardOutput(outputStream); execSpec.setIgnoreExitValue(true); }); if (log.isInfoEnabled()) { log.info(outputStream.toString()); } else if (execResult.getExitValue() != 0) { log.lifecycle(outputStream.toString()); } execResult.assertNormalExitValue(); ProbeVenvInfoAction.probeVenv(project, pythonDetails, editablePythonAbiContainer); project.delete(packageDir); try { pipConfFile.buildPipConfFile(); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example 19
Source File: PexExecOutputParser.java From pygradle with Apache License 2.0 | 4 votes |
PexExecOutputParser(PexExecSpecAction pexExecSpecAction, ExecResult execResult) { this(pexExecSpecAction.getOutputStream().toString().trim(), execResult.getExitValue()); }
Example 20
Source File: ExecCommandFactory.java From shipkit with MIT License | 4 votes |
static void ensureSucceeded(ExecResult result, String prefix) { if (result.getExitValue() != 0) { throw new GradleException("External process failed with exit code " + result.getExitValue() + "\n" + "Please inspect the command output prefixed with '" + prefix.trim() + "' the build log."); } }