Search in sources :

Example 1 with ProcessBuilderRunner

use of com.synopsys.integration.executable.ProcessBuilderRunner in project synopsys-detect by blackducksoftware.

the class BatteryDetectRunner method executeDetectScript.

private DetectOutput executeDetectScript(List<String> detectArguments) throws ExecutableRunnerException {
    List<String> shellArguments = new ArrayList<>();
    String target = "";
    if (SystemUtils.IS_OS_WINDOWS) {
        target = "powershell";
        shellArguments.add("\"[Net.ServicePointManager]::SecurityProtocol = 'tls12'; irm https://detect.synopsys.com/detect.ps1?$(Get-Random) | iex; detect\"");
    } else {
        File scriptTarget = new File(scriptDirectory, "detect.sh");
        if (scriptTarget.exists()) {
            Assertions.assertTrue(scriptTarget.delete(), "Failed to cleanup an existing detect shell script. This file is cleaned up to ensure latest script is always used.");
        }
        ExecutableOutput downloadOutput = downloadDetectBash(scriptTarget);
        Assertions.assertTrue(downloadOutput.getReturnCode() == 0 && scriptTarget.exists(), "Something went wrong downloading the detect script.");
        Assertions.assertTrue(scriptTarget.setExecutable(true), "Failed to change script permissions to execute. The downloaded detect script must be executable.");
        target = scriptTarget.toString();
    }
    shellArguments.addAll(detectArguments);
    Map<String, String> environmentVariables = new HashMap<>();
    if (StringUtils.isNotBlank(detectVersion)) {
        environmentVariables.put("DETECT_LATEST_RELEASE_VERSION", detectVersion);
    }
    Executable executable = Executable.create(outputDirectory, environmentVariables, target, shellArguments);
    ProcessBuilderRunner executableRunner = new ProcessBuilderRunner(new Slf4jIntLogger(logger));
    ExecutableOutput result = executableRunner.execute(executable);
    Assertions.assertEquals(0, result.getReturnCode(), "Detect returned a non-zero exit code:" + result.getReturnCode());
    List<String> lines = result.getStandardOutputAsList();
    Assertions.assertTrue(lines.size() > 0, "Detect wrote nothing to standard out.");
    return new DetectOutput(result.getStandardOutputAsList());
}
Also used : ProcessBuilderRunner(com.synopsys.integration.executable.ProcessBuilderRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Executable(com.synopsys.integration.executable.Executable) File(java.io.File)

Example 2 with ProcessBuilderRunner

use of com.synopsys.integration.executable.ProcessBuilderRunner in project synopsys-detect by blackducksoftware.

the class BatteryDetectRunner method downloadDetectBash.

private ExecutableOutput downloadDetectBash(File target) throws ExecutableRunnerException {
    List<String> shellArguments = new ArrayList<>();
    shellArguments.add("-s");
    shellArguments.add("-L");
    shellArguments.add("https://detect.synopsys.com/detect.sh");
    shellArguments.add("-o");
    shellArguments.add(target.toString());
    Executable executable = Executable.create(outputDirectory, new HashMap<>(), "curl", shellArguments);
    ProcessBuilderRunner executableRunner = new ProcessBuilderRunner(new Slf4jIntLogger(logger));
    return executableRunner.execute(executable);
}
Also used : ProcessBuilderRunner(com.synopsys.integration.executable.ProcessBuilderRunner) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) ArrayList(java.util.ArrayList) Executable(com.synopsys.integration.executable.Executable)

Example 3 with ProcessBuilderRunner

use of com.synopsys.integration.executable.ProcessBuilderRunner in project synopsys-detect by blackducksoftware.

the class BatteryDetectRunner method executeDetectJar.

private DetectOutput executeDetectJar(DetectJar detectJar, List<String> detectArguments) throws ExecutableRunnerException {
    List<String> javaArguments = new ArrayList<>();
    javaArguments.add("-jar");
    javaArguments.add(detectJar.getJar());
    javaArguments.addAll(detectArguments);
    ProcessBuilderRunner executableRunner = new ProcessBuilderRunner(new Slf4jIntLogger(logger));
    ExecutableOutput result = executableRunner.execute(Executable.create(outputDirectory, detectJar.getJava(), javaArguments));
    Assertions.assertEquals(0, result.getReturnCode(), "Detect returned a non-zero exit code:" + result.getReturnCode());
    List<String> lines = result.getStandardOutputAsList();
    Assertions.assertTrue(lines.size() > 0, "Detect wrote nothing to standard out.");
    return new DetectOutput(result.getStandardOutputAsList());
}
Also used : ProcessBuilderRunner(com.synopsys.integration.executable.ProcessBuilderRunner) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) ArrayList(java.util.ArrayList)

Example 4 with ProcessBuilderRunner

use of com.synopsys.integration.executable.ProcessBuilderRunner in project blackduck-docker-inspector by blackducksoftware.

the class UpdateArtifactoryPropertiesTask method curlResponse.

public ExecutableOutput curlResponse(final List<String> curlArgs) throws ExecutableRunnerException {
    final File workingDirectory = new File(System.getProperty("user.dir"));
    final List<String> command = new ArrayList<>(Collections.singletonList("curl"));
    command.addAll(curlArgs);
    final Executable executable = new Executable(workingDirectory, new HashMap<>(), command);
    final ProcessBuilderRunner processBuilderRunner = new ProcessBuilderRunner(logger);
    return processBuilderRunner.execute(executable);
}
Also used : ProcessBuilderRunner(com.synopsys.integration.executable.ProcessBuilderRunner) ArrayList(java.util.ArrayList) Executable(com.synopsys.integration.executable.Executable) File(java.io.File)

Aggregations

ProcessBuilderRunner (com.synopsys.integration.executable.ProcessBuilderRunner)4 ArrayList (java.util.ArrayList)4 Executable (com.synopsys.integration.executable.Executable)3 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)3 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)2 File (java.io.File)2 HashMap (java.util.HashMap)1