Search in sources :

Example 81 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class PipInspectorTreeParser method parse.

public Optional<NameVersionCodeLocation> parse(List<String> pipInspectorOutputAsList, String sourcePath) {
    NameVersionCodeLocation parseResult = null;
    DependencyGraph graph = new BasicDependencyGraph();
    DependencyHistory history = new DependencyHistory();
    Dependency project = null;
    int unResolvedPackageCount = 0;
    for (String line : pipInspectorOutputAsList) {
        String trimmedLine = StringUtils.trimToEmpty(line);
        if (StringUtils.isEmpty(trimmedLine) || !trimmedLine.contains(SEPARATOR) || trimmedLine.startsWith(UNKNOWN_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNPARSEABLE_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNKNOWN_PACKAGE_PREFIX)) {
            boolean wasUnresolved = parseErrorsFromLine(trimmedLine);
            if (wasUnresolved) {
                unResolvedPackageCount++;
            }
            continue;
        }
        Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
        adjustForIndentLevel(history, line);
        project = addDependencyToGraph(graph, history, project, currentDependency);
        history.add(currentDependency);
    }
    adviseIfUnresolvedPackages(unResolvedPackageCount);
    if (project != null) {
        CodeLocation codeLocation = new CodeLocation(graph, project.getExternalId());
        parseResult = new NameVersionCodeLocation(project.getName(), project.getVersion(), codeLocation);
    }
    return Optional.ofNullable(parseResult);
}
Also used : NameVersionCodeLocation(com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) DependencyHistory(com.synopsys.integration.detectable.detectable.util.DependencyHistory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) NameVersionCodeLocation(com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation)

Example 82 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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)

Example 83 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class PipenvTransformer method transform.

public CodeLocation transform(String projectName, String projectVersionName, PipFreeze pipFreeze, PipenvGraph pipenvGraph, boolean includeOnlyProjectTree) {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    for (PipenvGraphEntry entry : pipenvGraph.getEntries()) {
        Dependency entryDependency = nameVersionToDependency(entry.getName(), entry.getVersion(), pipFreeze);
        List<Dependency> children = addDependenciesToGraph(entry.getChildren(), dependencyGraph, pipFreeze);
        if (matchesProject(entryDependency, projectName, projectVersionName)) {
            // The project appears as an entry, we don't want the project to be a dependency of itself.
            dependencyGraph.addChildrenToRoot(children);
        } else if (!includeOnlyProjectTree) {
            // Only add non-project matches if we are not project tree only.
            dependencyGraph.addChildToRoot(entryDependency);
            dependencyGraph.addParentWithChildren(entryDependency, children);
        }
    }
    ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName);
    return new CodeLocation(dependencyGraph, projectExternalId);
}
Also used : PipenvGraphEntry(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphEntry) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) PipenvGraphDependency(com.synopsys.integration.detectable.detectables.pipenv.build.model.PipenvGraphDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 84 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class RebarExtractor method extract.

public Extraction extract(File directory, ExecutableTarget rebarExe) {
    try {
        toolVersionLogger.log(directory, rebarExe);
        List<CodeLocation> codeLocations = new ArrayList<>();
        Map<String, String> envVars = new HashMap<>();
        envVars.put("REBAR_COLOR", "none");
        List<String> arguments = new ArrayList<>();
        arguments.add("tree");
        Executable rebar3TreeExe = ExecutableUtils.createFromTarget(directory, envVars, rebarExe, arguments);
        List<String> output = executableRunner.execute(rebar3TreeExe).getStandardOutputAsList();
        RebarParseResult parseResult = rebarTreeParser.parseRebarTreeOutput(output);
        codeLocations.add(parseResult.getCodeLocation());
        Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
        parseResult.getProjectNameVersion().ifPresent(projectNameVersion -> builder.projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()));
        return builder.build();
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) HashMap(java.util.HashMap) RebarParseResult(com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult) ArrayList(java.util.ArrayList) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable)

Example 85 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class CodeLocationConverter method toDetectCodeLocation.

public Map<CodeLocation, DetectCodeLocation> toDetectCodeLocation(File detectSourcePath, DetectorEvaluation evaluation) {
    Map<CodeLocation, DetectCodeLocation> detectCodeLocations = new HashMap<>();
    if (evaluation.wasExtractionSuccessful()) {
        Extraction extraction = evaluation.getExtraction();
        String name = evaluation.getDetectorType().toString();
        return toDetectCodeLocation(detectSourcePath, extraction, evaluation.getDetectableEnvironment().getDirectory(), name);
    }
    return detectCodeLocations;
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) HashMap(java.util.HashMap) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)104 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)60 Extraction (com.synopsys.integration.detectable.extraction.Extraction)41 File (java.io.File)24 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)22 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)21 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)20 NameVersion (com.synopsys.integration.util.NameVersion)19 IOException (java.io.IOException)19 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)16 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)16 List (java.util.List)14 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)13 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10