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 execute(final ExecSpec it) { it.setExecutable(cache.getBashFile()); it.setArgs(Arrays.asList("--login", "-c", "exit 0")); } }).rethrowFailure();
@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); }
private void doPush(File file) { if (file == null || !file.exists() || !file.isFile()) { throw new RuntimeException("Failed to generate nuget package. Nothing to publish."); } LOGGER.quiet("Publishing '{}' to repository '{}'", file.getAbsoluteFile(), _repository); DotnetExtension ext = getExtension(); getProject().exec(execSpec -> { execSpec.setExecutable(ext.getExecutable()); List<String> args = new ArrayList<>(); args.add("nuget"); args.add("push"); args.add(file.getAbsolutePath()); args.add("--source"); args.add(_repository); args.add("--api-key"); args.add(_apiKey); execSpec.setArgs(args); }); }
@Override public void execute(ExecSpec execSpec) { execSpec.setExecutable(ext.getBinPath()); execSpec.setArgs(args); } }
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); } }
@TaskAction void action() { getProject().exec(execSpec -> { execSpec.setExecutable(getZipAlignExe()); execSpec.setArgs(Arrays.asList( "-f", "4", getInputFile().getAbsolutePath(), getOutputFile().getAbsolutePath() )); }); } }
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); } }
@TaskAction void exec() { getProject().exec(execSpec -> { execSpec.setExecutable(getExtension().getExecutable()); execSpec.setArgs(Arrays.asList("--info")); }); } }
private void runTest(File file) { DotnetExtension ext = getExtension(); getProject().exec(execSpec -> { execSpec.setExecutable(ext.getExecutable()); List<String> args = new ArrayList<>(); args.add("test"); args.add(file.getAbsolutePath()); whenHasValue(ext.getConfiguration(), addNamedParameter(args, "--configuration")); whenHasValue(ext.getFramework(), addNamedParameter(args, "--framework")); args.add("--no-restore"); args.add("--no-build"); args.add("--logger"); args.add(String.format(Locale.US, "\"trx;LogFileName=%s.trx\"", file.getName())); args.add("--results-directory"); args.add("../TestResults"); execSpec.setArgs(args); }); }
@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); }); }
@TaskAction void generateCert() { String pathCertFile = this.outputDir + File.separatorChar + this.certFile; String pathKeyFile = this.outputDir + File.separatorChar + this.keyFile; // execute openssl cmd to create public cert getProject().exec(execSpec -> { execSpec.setIgnoreExitValue(true); execSpec.workingDir("."); execSpec.setExecutable("openssl"); List<String> args = Arrays.asList( "req", "-new", "-x509", "-key", pathKeyFile, "-out", pathCertFile, "-passin", "pass:"+this.keyPassword, "-subj", "/C=US" ); execSpec.setArgs(args); }); }
@TaskAction void generateJKS() { String pathJksFile = this.outputDir + File.separatorChar + this.jksFile; String pathPkcs12File = this.outputDir + File.separatorChar + this.pkcs12File; getProject().exec(execSpec -> { execSpec.setIgnoreExitValue(true); execSpec.workingDir("."); execSpec.setExecutable("keytool"); List<String> args = Arrays.asList( "-importkeystore", "-srcstoretype", "PKCS12", "-srckeystore", pathPkcs12File, "-srcstorepass", this.pkcs12Password, "-destkeystore", pathJksFile, "-storepass", this.jksPassword ); execSpec.setArgs(args); }); }
@TaskAction void exec() { getProject().exec(execSpec -> { DotnetExtension ext = getExtension(); execSpec.setExecutable(ext.getExecutable()); List<String> args = new ArrayList<>(); args.add("restore"); whenHasValue(ext.getSolution(), args::add); whenHasValue(ext.getRuntime(), addNamedParameter(args, "--runtime")); execSpec.setArgs(args); }); }
@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); } }
@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); } });
@TaskAction void exec() { getProject().exec(execSpec -> { DotnetExtension ext = getExtension(); execSpec.setExecutable(ext.getExecutable()); List<String> args = new ArrayList<>(); args.add("build"); whenHasValue(ext.getSolution(), args::add); whenHasValue(ext.getConfiguration(), addNamedParameter(args, "--configuration")); whenHasValue(ext.getFramework(), addNamedParameter(args, "--framework")); whenHasValue(ext.getRuntime(), addNamedParameter(args, "--runtime")); args.add("--no-restore"); appendParameters(args); execSpec.setArgs(args); }); }
@TaskAction void exec() { DotnetExtension ext = getExtension(); getProject().exec(execSpec -> { execSpec.setExecutable(ext.getExecutable()); List<String> args = new ArrayList<>(); args.add("clean"); whenHasValue(ext.getSolution(), args::add); whenHasValue(ext.getConfiguration(), addNamedParameter(args, "--configuration")); whenHasValue(ext.getFramework(), addNamedParameter(args, "--framework")); whenHasValue(ext.getRuntime(), addNamedParameter(args, "--runtime")); execSpec.setArgs(args); }); cleanPackages(); getProject().delete(getProject().getProjectDir().toPath().resolve("TestResults")); getProject().delete(getProject().getBuildDir()); }
private void publish(String runtime) { getProject().exec(execSpec -> { DotnetExtension ext = getExtension(); execSpec.setExecutable(ext.getExecutable()); List<String> args = new ArrayList<>(); args.add("publish"); whenHasValue(ext.getSolution(), args::add); whenHasValue(ext.getConfiguration(), addNamedParameter(args, "--configuration")); whenHasValue(ext.getFramework(), addNamedParameter(args, "--framework")); whenHasValue(runtime, addNamedParameter(args, "--runtime")); appendParameters(args); execSpec.setArgs(args); }); }