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); }); }
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); } }
@Override public void execute(final ExecSpec it) { it.setExecutable(info.getShellExecutable()); if (isWindows()) { it.environment("MSYSTEM", mSystem); it.environment("CHERE_INVOKING", "1"); } it.args(getAllArgs()); if (!workingDir.isDirectory()) { workingDir.mkdirs(); } it.setWorkingDir(workingDir); it.setStandardInput(standardInput); it.setStandardOutput(standardOutput); it.setErrorOutput(errorOutput); } });
public void execute(ExecSpec spec) { spec.setIgnoreExitValue(true); spec.setWorkingDir(workingDir); } };
@Override public void execute(ExecSpec execSpec) { if (_environment != null) { execSpec.environment(_environment); } execSpec.setCommandLine(_commandLine); execSpec.setStandardOutput(byteArrayOutputStream); }
public void setOutputs(ExecSpec execSpec) { execSpec.setStandardOutput(teeStdOut); execSpec.setErrorOutput(teeErrOut); }
@Override public void execute(ExecSpec execSpec) { /* * Gradle doesn't work correctly when there are empty args. */ List<String> args = processInfo.getArgs().stream() .map(a -> a.isEmpty()? "\"\"" : a) .collect(Collectors.toList()); execSpec.setExecutable(processInfo.getExecutable()); execSpec.args(args); execSpec.environment(processInfo.getEnvironment()); execSpec.setStandardOutput(processOutput.getStandardOutput()); execSpec.setErrorOutput(processOutput.getErrorOutput()); // we want the caller to be able to do its own thing. execSpec.setIgnoreExitValue(true); } }
@TaskAction public void executePythonProcess() { preExecution(); 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); }
@TaskAction void generateKey() throws IOException { String pathKeyFile = this.outputDir + File.separatorChar + this.keyFile; // execute openssl cmd to create private key getProject().exec(execSpec -> { execSpec.setIgnoreExitValue(true); execSpec.workingDir("."); execSpec.setExecutable("openssl"); List<String> args = Arrays.asList( "genrsa", "-des3", "-out", pathKeyFile, "-passout", "pass:"+this.keyPassword ); execSpec.setArgs(args); }); }
@Override public void execute(ExecSpec execSpec) { execSpec.setExecutable(ext.getBinPath()); execSpec.setArgs(args); } }
@Override public void execute(ExecSpec execSpec) { if (workingDirectory != null) { execSpec.setWorkingDir(workingDirectory); } execSpec.setCommandLine((Object[])Commandline.translateCommandline(command)); execSpec.setIgnoreExitValue(ignoreExitValue); if (logStandardOutput) { execSpec.setStandardOutput(standardOutputStream); } execSpec.setErrorOutput(errorOutputStream); } });
@Override public void execute(ExecSpec execSpec) { execSpec.setCommandLine(_getCommandLine()); execSpec.setEnvironment( _getEnvironment(execSpec.getEnvironment())); execSpec.setErrorOutput( new TeeOutputStream(byteArrayOutputStream, System.out)); execSpec.setStandardOutput( new TeeOutputStream(byteArrayOutputStream, System.out)); execSpec.setWorkingDir(getWorkingDir()); }
public ParallelWheelGenerationTask() { onlyIf(task -> { ByteArrayOutputStream stdOut = new ByteArrayOutputStream(); getProject().exec(execSpec -> { execSpec.setExecutable(getPythonDetails().getVirtualEnvInterpreter()); execSpec.args(getPythonDetails().getVirtualEnvironment().getPip(), "freeze", "--all"); execSpec.setStandardOutput(stdOut); }); Configuration requiredDependencies = getProject().getConfigurations() .getByName(CONFIGURATION_SETUP_REQS.getValue()); Set<String> setupRequiresDependencies = requiredDependencies.getIncoming().getDependencies().stream() .flatMap(it -> Stream.of(it.getName(), it.getName().replace("-", "_"))) .collect(Collectors.toSet()); Set<String> extraDependencies = Arrays.stream(stdOut.toString().trim().split(System.lineSeparator())) .filter(it -> it.contains("==")).map(it -> it.split("==")[0]) .filter(it -> !setupRequiresDependencies.contains(it)) .collect(Collectors.toSet()); if (!extraDependencies.isEmpty()) { logger.info("Extra dependencies found ({}). Skipping parallel wheel building.", extraDependencies); } return extraDependencies.isEmpty(); }); }
private static String exec(Project project, String executable, String... args) { ByteArrayOutputStream out = new ByteArrayOutputStream(); project.exec(execSpec -> { execSpec.setExecutable(executable); execSpec.setArgs(Arrays.asList(args)); execSpec.setStandardOutput(out); }); return out.toString(); }
@Override public void execute(ExecSpec execSpec) { if (OSDetector.isWindows()) { execSpec.args( "/MIR", "/NDL", "/NFL", "/NJH", "/NJS", "/NP", sourceDir.getAbsolutePath(), targetDir.getAbsolutePath()); execSpec.setExecutable("robocopy"); } else { execSpec.args( "--archive", "--delete", sourceDir.getAbsolutePath() + File.separator, targetDir.getAbsolutePath()); execSpec.setExecutable("rsync"); } execSpec.setIgnoreExitValue(true); }
@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); } final ByteArrayOutputStream stream = new ByteArrayOutputStream(); exec.exec(execSpec -> { execSpec.commandLine(pythonDetails.getSystemPythonInterpreter(), path.resolve(Paths.get("bin", "rebuild-script.py")).toFile()); execSpec.setStandardOutput(stream); execSpec.setErrorOutput(stream); }); log.info("Customized distutils.cfg"); } } }
public Map<String, String> getDependencies() { final PythonExtension settings = ExtensionUtils.getPythonExtension(project); // Setup requirements, build, and test dependencies Set<String> developmentDependencies = configurationToSet(project, StandardTextValues.CONFIGURATION_SETUP_REQS.getValue()); developmentDependencies.addAll(configurationToSet(project, StandardTextValues.CONFIGURATION_BUILD_REQS.getValue())); developmentDependencies.addAll(configurationToSet(project, StandardTextValues.CONFIGURATION_TEST.getValue())); developmentDependencies.removeAll(configurationToSet(project, StandardTextValues.CONFIGURATION_PYTHON.getValue())); final ByteArrayOutputStream requirements = new ByteArrayOutputStream(); /* * NOTE: It is very important to provide "--all" in the list of arguments * to "pip freeze". Otherwise, setuptools, wheel, or pip would not be included * even if required by runtime configuration "python". */ project.exec(execSpec -> { execSpec.environment(settings.getEnvironment()); execSpec.commandLine( settings.getDetails().getVirtualEnvInterpreter(), settings.getDetails().getVirtualEnvironment().getPip(), "freeze", "--all", "--disable-pip-version-check" ); execSpec.setStandardOutput(requirements); }); Map<String, String> dependencies = PipFreezeOutputParser.getDependencies(developmentDependencies, requirements); // Always add project unconditionally. dependencies.put(project.getName(), project.getVersion().toString()); return dependencies; }
String finalCommand = commandLine; project.exec(execSpec -> { execSpec.setIgnoreExitValue(spec.isIgnoreExitValue()); execSpec.setCommandLine(parseCommand(finalCommand)); if (spec.getInput() != null) { execSpec.setStandardInput(new ByteArrayInputStream(spec.getInput().getBytes())); execSpec.setStandardOutput(outputStream);
@Override public void execute(ExecSpec execSpec) { execSpec.executable(getZipAlignExe()); execSpec.args("-f", "4"); execSpec.args(getInputFile()); execSpec.args(getOutputFile()); } });
exec.commandLine(dumpBinLoc, "/NOLOGO", "/EXPORTS", library); exec.setStandardOutput(dumpbinOutput); });