Search in sources :

Example 31 with BasicDependencyGraph

use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.

the class Rebar3TreeParser method parseRebarTreeOutput.

public RebarParseResult parseRebarTreeOutput(List<String> dependencyTreeOutput) {
    DependencyGraph graph = new BasicDependencyGraph();
    DependencyHistory history = new DependencyHistory();
    Dependency project = null;
    for (String line : dependencyTreeOutput) {
        if (!line.contains(HORIZONTAL_SEPARATOR_CHARACTER)) {
            continue;
        }
        Dependency currentDependency = createDependencyFromLine(line);
        int lineLevel = getDependencyLevelFromLine(line);
        try {
            history.clearDependenciesDeeperThan(lineLevel);
        } catch (IllegalStateException e) {
            logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
        }
        if (history.isEmpty() && isProject(line)) {
            project = currentDependency;
        } else if (history.getLastDependency().equals(project)) {
            graph.addChildToRoot(currentDependency);
        } else if (history.isEmpty()) {
            graph.addChildToRoot(currentDependency);
        } else {
            graph.addChildWithParents(currentDependency, history.getLastDependency());
        }
        history.add(currentDependency);
    }
    if (project == null) {
        CodeLocation codeLocation = new CodeLocation(graph);
        return new RebarParseResult(codeLocation);
    } else {
        CodeLocation codeLocation = new CodeLocation(graph, project.getExternalId());
        return new RebarParseResult(new NameVersion(project.getName(), project.getVersion()), codeLocation);
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) RebarParseResult(com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult) 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)

Example 32 with BasicDependencyGraph

use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.

the class NugetDependencyNodeBuilder method createDependencyGraph.

public DependencyGraph createDependencyGraph(List<NugetPackageId> packageDependencies) {
    DependencyGraph graph = new BasicDependencyGraph();
    for (NugetPackageSet packageSet : packageSets) {
        if (packageSet.dependencies != null) {
            for (NugetPackageId id : packageSet.dependencies) {
                if (packageSet.packageId != null) {
                    graph.addParentWithChild(convertPackageId(packageSet.packageId), convertPackageId(id));
                }
            }
        }
    }
    packageDependencies.stream().map(this::convertPackageId).forEach(graph::addChildToRoot);
    return graph;
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) NugetPackageSet(com.synopsys.integration.detectable.detectables.nuget.model.NugetPackageSet) NugetPackageId(com.synopsys.integration.detectable.detectables.nuget.model.NugetPackageId)

Example 33 with BasicDependencyGraph

use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.

the class PnpmYamlTransformer method generateCodeLocation.

public CodeLocation generateCodeLocation(File sourcePath, PnpmProjectPackage projectPackage, @Nullable String reportingProjectPackagePath, @Nullable NameVersion projectNameVersion, @Nullable Map<String, PnpmPackageInfo> packageMap, PnpmLinkedPackageResolver linkedPackageResolver) throws IntegrationException {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    List<String> rootPackageIds = extractRootPackageIds(projectPackage, reportingProjectPackagePath, linkedPackageResolver);
    buildGraph(dependencyGraph, rootPackageIds, packageMap, linkedPackageResolver, reportingProjectPackagePath);
    if (projectNameVersion != null) {
        return new CodeLocation(dependencyGraph, ExternalId.FACTORY.createNameVersionExternalId(Forge.NPMJS, projectNameVersion.getName(), projectNameVersion.getVersion()), sourcePath);
    }
    return new CodeLocation(dependencyGraph, sourcePath);
}
Also used : 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)

Example 34 with BasicDependencyGraph

use of com.synopsys.integration.bdio.graph.BasicDependencyGraph 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 35 with BasicDependencyGraph

use of com.synopsys.integration.bdio.graph.BasicDependencyGraph 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)

Aggregations

BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)43 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)38 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)26 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)16 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)10 List (java.util.List)7 Forge (com.synopsys.integration.bdio.model.Forge)6 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)5 ArrayList (java.util.ArrayList)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 File (java.io.File)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Gson (com.google.gson.Gson)3 NotNull (org.jetbrains.annotations.NotNull)3 GraphEdge (com.paypal.digraph.parser.GraphEdge)2 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)2 DependencyHistory (com.synopsys.integration.detectable.detectable.util.DependencyHistory)2 Extraction (com.synopsys.integration.detectable.extraction.Extraction)2