Search in sources :

Example 26 with ExecutableOutput

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

the class SbtPluginFinder method listPlugins.

private List<String> listPlugins(File directory, ExecutableTarget sbt, @Nullable String sbtCommandAdditionalArguments) throws DetectableException {
    try {
        List<String> args = sbtCommandArgumentGenerator.generateSbtCmdArgs(sbtCommandAdditionalArguments, "plugins");
        ExecutableOutput output = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(directory, sbt, args));
        return output.getStandardOutputAsList();
    } catch (ExecutableFailedException e) {
        throw new DetectableException("Unable to list installed sbt plugins, detect requires a suitable sbt plugin is available to find dependency graphs.", e);
    }
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 27 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput 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 28 with ExecutableOutput

use of com.synopsys.integration.executable.ExecutableOutput 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 29 with ExecutableOutput

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

the class PearCliExtractor method extract.

public Extraction extract(ExecutableTarget pearExe, File packageXmlFile, File workingDirectory) {
    try {
        ExecutableOutput pearListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "list"));
        ExecutableOutput packageDependenciesOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME));
        assertValidExecutableOutput(pearListOutput, packageDependenciesOutput);
        Map<String, String> dependencyNameVersionMap = pearListParser.parse(pearListOutput.getStandardOutputAsList());
        List<PackageDependency> packageDependencies = pearPackageDependenciesParser.parse(packageDependenciesOutput.getStandardOutputAsList());
        DependencyGraph dependencyGraph = pearDependencyGraphTransformer.buildDependencyGraph(dependencyNameVersionMap, packageDependencies);
        try (InputStream packageXmlInputStream = new FileInputStream(packageXmlFile)) {
            NameVersion projectNameVersion = pearPackageXmlParser.parse(packageXmlInputStream);
            ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PEAR, projectNameVersion.getName(), projectNameVersion.getVersion());
            CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, externalId);
            return new Extraction.Builder().success(detectCodeLocation).projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()).build();
        }
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) FileInputStream(java.io.FileInputStream) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 30 with ExecutableOutput

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

the class PipenvExtractor method extract.

public Extraction extract(File directory, ExecutableTarget pythonExe, ExecutableTarget pipenvExe, File setupFile, String providedProjectName, String providedProjectVersionName, boolean includeOnlyProjectTree) {
    Extraction extraction;
    try {
        String projectName = resolveProjectName(directory, pythonExe, setupFile, providedProjectName);
        String projectVersionName = resolveProjectVersionName(directory, pythonExe, setupFile, providedProjectVersionName);
        ExecutableOutput pipFreezeOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("run", "pip", "freeze")));
        ExecutableOutput graphOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pipenvExe, Arrays.asList("graph", "--bare", "--json-tree")));
        PipFreeze pipFreeze = pipenvFreezeParser.parse(pipFreezeOutput.getStandardOutputAsList());
        PipenvGraph pipenvGraph = pipEnvJsonGraphParser.parse(graphOutput.getStandardOutput());
        CodeLocation codeLocation = pipenvTransformer.transform(projectName, projectVersionName, pipFreeze, pipenvGraph, includeOnlyProjectTree);
        return new Extraction.Builder().projectName(projectName).projectVersion(projectVersionName).success(codeLocation).build();
    } catch (Exception e) {
        extraction = new Extraction.Builder().exception(e).build();
    }
    return extraction;
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PipenvGraph(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraph) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) PipFreeze(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipFreeze)

Aggregations

ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)53 File (java.io.File)18 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)14 ArrayList (java.util.ArrayList)14 Extraction (com.synopsys.integration.detectable.extraction.Extraction)13 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)13 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)10 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)9 Executable (com.synopsys.integration.executable.Executable)9 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)8 Test (org.junit.jupiter.api.Test)7 NameVersion (com.synopsys.integration.util.NameVersion)6 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 HashMap (java.util.HashMap)5 List (java.util.List)5 StringUtils (org.apache.commons.lang3.StringUtils)5 ExecutableUtils (com.synopsys.integration.detectable.ExecutableUtils)4 IOException (java.io.IOException)4 Optional (java.util.Optional)4 Gson (com.google.gson.Gson)3