Search in sources :

Example 1 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.model.PipenvGraph) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) PipFreeze(com.synopsys.integration.detectable.detectables.pipenv.model.PipFreeze)

Example 2 with ExecutableOutput

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

the class NugetInspectorExtractor method executeTarget.

private NugetTargetResult executeTarget(NugetInspector inspector, File targetFile, File outputDirectory, NugetInspectorOptions nugetInspectorOptions) throws ExecutableRunnerException, IOException, DetectableException {
    if (!outputDirectory.exists() && !outputDirectory.mkdirs()) {
        throw new DetectableException(String.format("Executing the nuget inspector failed, could not create output directory: %s", outputDirectory));
    }
    ExecutableOutput executableOutput = inspector.execute(outputDirectory, targetFile, outputDirectory, nugetInspectorOptions);
    if (executableOutput.getReturnCode() != 0) {
        throw new DetectableException(String.format("Executing the nuget inspector failed: %s", executableOutput.getReturnCode()));
    }
    List<File> dependencyNodeFiles = fileFinder.findFiles(outputDirectory, INSPECTOR_OUTPUT_PATTERN);
    List<NugetParseResult> parseResults = new ArrayList<>();
    if (dependencyNodeFiles != null) {
        for (File dependencyNodeFile : dependencyNodeFiles) {
            String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
            NugetParseResult result = nugetInspectorParser.createCodeLocation(text);
            parseResults.add(result);
        }
    }
    NugetTargetResult targetResult = new NugetTargetResult();
    targetResult.codeLocations = parseResults.stream().flatMap(it -> it.getCodeLocations().stream()).collect(Collectors.toList());
    targetResult.nameVersion = parseResults.stream().filter(it -> StringUtils.isNotBlank(it.getProjectName())).map(it -> new NameVersion(it.getProjectName(), it.getProjectVersion())).findFirst().orElse(null);
    return targetResult;
}
Also used : Extraction(com.synopsys.integration.detectable.extraction.Extraction) MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) ArrayList(java.util.ArrayList) NameVersion(com.synopsys.integration.util.NameVersion) NugetInspectorOptions(com.synopsys.integration.detectable.detectable.inspector.nuget.NugetInspectorOptions) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Map(java.util.Map) NugetInspector(com.synopsys.integration.detectable.detectable.inspector.nuget.NugetInspector) Logger(org.slf4j.Logger) NugetInspectorParser(com.synopsys.integration.detectable.detectables.nuget.parse.NugetInspectorParser) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) DependencyGraphCombiner(com.synopsys.integration.bdio.graph.DependencyGraphCombiner) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Optional(java.util.Optional) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) NameVersion(com.synopsys.integration.util.NameVersion) ArrayList(java.util.ArrayList) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) File(java.io.File) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 3 with ExecutableOutput

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

the class BazelCommandExecutor method executeToString.

public Optional<String> executeToString(List<String> args) throws ExecutableFailedException {
    ExecutableOutput targetDependenciesQueryResults = executableRunner.executeSuccessfully(ExecutableUtils.createFromTarget(workspaceDir, bazelExe, args));
    String cmdStdErr = targetDependenciesQueryResults.getErrorOutput();
    if (cmdStdErr != null && cmdStdErr.contains("ERROR")) {
        logger.warn("Bazel error: {}", cmdStdErr.trim());
    }
    String cmdStdOut = targetDependenciesQueryResults.getStandardOutput();
    if ((StringUtils.isBlank(cmdStdOut))) {
        logger.debug("bazel command produced no output");
        return Optional.empty();
    }
    return Optional.of(cmdStdOut);
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput)

Example 4 with ExecutableOutput

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

the class CpanCliExtractor method extract.

public Extraction extract(ExecutableTarget cpanExe, ExecutableTarget cpanmExe, File workingDirectory) throws ExecutableRunnerException {
    toolVersionLogger.log(workingDirectory, cpanExe);
    // TODO: Consider command runner to reduce cognitive load.
    ExecutableOutput cpanListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, cpanExe, "-l"));
    List<String> listText = cpanListOutput.getStandardOutputAsList();
    ExecutableOutput showdepsOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, cpanmExe, "--showdeps", "."));
    List<String> showdeps = showdepsOutput.getStandardOutputAsList();
    DependencyGraph dependencyGraph = cpanListParser.parse(listText, showdeps);
    CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph);
    return new Extraction.Builder().success(detectCodeLocation).build();
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Example 5 with ExecutableOutput

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

the class CondaCliExtractor method extract.

public Extraction extract(File directory, ExecutableTarget condaExe, File workingDirectory, String condaEnvironmentName) {
    try {
        toolVersionLogger.log(workingDirectory, condaExe);
        List<String> condaListOptions = new ArrayList<>();
        condaListOptions.add("list");
        if (StringUtils.isNotBlank(condaEnvironmentName)) {
            condaListOptions.add("-n");
            condaListOptions.add(condaEnvironmentName);
        }
        condaListOptions.add("--json");
        ExecutableOutput condaListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, condaExe, condaListOptions));
        String listJsonText = condaListOutput.getStandardOutput();
        ExecutableOutput condaInfoOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, condaExe, "info", "--json"));
        String infoJsonText = condaInfoOutput.getStandardOutput();
        DependencyGraph dependencyGraph = condaListParser.parse(listJsonText, infoJsonText);
        CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph);
        return new Extraction.Builder().success(detectCodeLocation).build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

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