Search in sources :

Example 16 with BasicDependencyGraph

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

the class ConanCodeLocationGenerator method generateCodeLocationFromNodeMap.

@NotNull
public ConanDetectableResult generateCodeLocationFromNodeMap(ExternalIdFactory externalIdFactory, Map<String, ConanNode<String>> nodes) throws DetectableException {
    logger.debug("Generating code location from {} dependencies", nodes.keySet().size());
    Optional<ConanNode<String>> rootNode = getRoot(nodes.values());
    if (!rootNode.isPresent()) {
        throw new DetectableException("No root node found");
    }
    ConanGraphNode rootGraphNode = new ConanGraphNode(rootNode.get());
    populateGraphUnderNode(rootGraphNode, nodes);
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    CodeLocation codeLocation = generateCodeLocationFromConanGraph(externalIdFactory, dependencyGraph, rootGraphNode);
    return new ConanDetectableResult(rootGraphNode.getConanNode().getName().orElse(null), rootGraphNode.getConanNode().getVersion().orElse(null), codeLocation);
}
Also used : ConanGraphNode(com.synopsys.integration.detectable.detectables.conan.graph.ConanGraphNode) ConanNode(com.synopsys.integration.detectable.detectables.conan.graph.ConanNode) 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) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with BasicDependencyGraph

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

the class GemspecParser method parse.

public DependencyGraph parse(InputStream inputStream) throws IOException {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            if (!gemspecLineParser.shouldParseLine(line)) {
                continue;
            }
            Optional<GemspecDependency> gemspecDependencyOptional = gemspecLineParser.parseLine(line);
            if (!gemspecDependencyOptional.isPresent()) {
                continue;
            }
            GemspecDependency gemspecDependency = gemspecDependencyOptional.get();
            if (dependencyTypeFilter.shouldExclude(com.synopsys.integration.detectable.detectables.rubygems.GemspecDependencyType.RUNTIME) && gemspecDependency.getGemspecDependencyType() == GemspecDependencyType.RUNTIME) {
                logger.debug(String.format("Excluding component '%s' from graph because it is a runtime dependency", gemspecDependency.getName()));
                continue;
            } else if (dependencyTypeFilter.shouldExclude(com.synopsys.integration.detectable.detectables.rubygems.GemspecDependencyType.DEV) && gemspecDependency.getGemspecDependencyType() == GemspecDependencyType.DEVELOPMENT) {
                logger.debug(String.format("Excluding component '%s' from graph because it is a development dependency", gemspecDependency.getName()));
                continue;
            }
            String name = gemspecDependency.getName();
            String version = gemspecDependency.getVersion().orElse("No version");
            Dependency dependency = Dependency.FACTORY.createNameVersionDependency(Forge.RUBYGEMS, name, version);
            dependencyGraph.addChildrenToRoot(dependency);
        }
    }
    return dependencyGraph;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 18 with BasicDependencyGraph

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

the class ProjectInspectorParser method codeLocationFromModule.

public CodeLocation codeLocationFromModule(ProjectInspectorModule module) {
    Map<String, Dependency> lookup = new HashMap<>();
    // build the map of all external ids
    module.dependencies.forEach(dependency -> lookup.computeIfAbsent(dependency.id, (missingId) -> convertProjectInspectorDependency(dependency)));
    // and add them to the graph
    DependencyGraph mutableDependencyGraph = new BasicDependencyGraph();
    module.dependencies.forEach(moduleDependency -> {
        Dependency dependency = lookup.get(moduleDependency.id);
        moduleDependency.includedBy.forEach(parent -> {
            if ("DIRECT".equals(parent)) {
                mutableDependencyGraph.addChildToRoot(dependency);
            } else if (lookup.containsKey(parent)) {
                mutableDependencyGraph.addChildWithParent(dependency, lookup.get(parent));
            } else {
                // Theoretically should not happen according to PI devs. -jp
                throw new RuntimeException("An error occurred reading the project inspector output." + " An unknown parent dependency was encountered '" + parent + "' while including dependency '" + moduleDependency.name + "'.");
            }
        });
    });
    return new CodeLocation(mutableDependencyGraph, new File(module.moduleFile));
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) ProjectInspectorOutput(com.synopsys.integration.detectable.detectables.projectinspector.model.ProjectInspectorOutput) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) HashMap(java.util.HashMap) ProjectInspectorModule(com.synopsys.integration.detectable.detectables.projectinspector.model.ProjectInspectorModule) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Gson(com.google.gson.Gson) Map(java.util.Map) ProjectInspectorDependency(com.synopsys.integration.detectable.detectables.projectinspector.model.ProjectInspectorDependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) ProjectInspectorMavenCoordinate(com.synopsys.integration.detectable.detectables.projectinspector.model.ProjectInspectorMavenCoordinate) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) HashMap(java.util.HashMap) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectInspectorDependency(com.synopsys.integration.detectable.detectables.projectinspector.model.ProjectInspectorDependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) File(java.io.File)

Example 19 with BasicDependencyGraph

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

the class PoetryLockParser method parseDependencies.

private DependencyGraph parseDependencies(TomlArray lockPackages) {
    DependencyGraph graph = new BasicDependencyGraph();
    Set<String> rootPackages = determineRootPackages(lockPackages);
    for (String rootPackage : rootPackages) {
        graph.addChildToRoot(packageMap.get(rootPackage));
    }
    for (int i = 0; i < lockPackages.size(); i++) {
        TomlTable lockPackage = lockPackages.getTable(i);
        List<String> dependencies = extractFromDependencyList(lockPackage.getTable(DEPENDENCIES_KEY));
        if (dependencies.isEmpty()) {
            continue;
        }
        for (String dependency : dependencies) {
            Dependency child = packageMap.get(dependency);
            Dependency parent = packageMap.get(lockPackage.getString(NAME_KEY));
            if (child != null && parent != null) {
                graph.addChildWithParent(child, parent);
            }
        }
    }
    return graph;
}
Also used : TomlTable(org.tomlj.TomlTable) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 20 with BasicDependencyGraph

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

the class SbtDependencyResolver method resolveReport.

public SbtDependencyModule resolveReport(SbtReport report) {
    ExternalId rootId = externalIdFactory.createMavenExternalId(report.getOrganisation(), report.getModule(), report.getRevision());
    logger.debug("Created external id: {}", rootId);
    BasicDependencyGraph graph = new BasicDependencyGraph();
    logger.debug("Dependencies found: " + report.getDependencies().size());
    report.getDependencies().forEach(module -> {
        logger.debug("Revisions found: " + module.getRevisions().size());
        module.getRevisions().forEach(revision -> {
            logger.debug("Callers found: " + revision.getCallers().size());
            ExternalId id = externalIdFactory.createMavenExternalId(module.getOrganisation(), module.getName(), revision.getName());
            Dependency child = new Dependency(module.getName(), revision.getName(), id);
            revision.getCallers().forEach(caller -> {
                ExternalId parentId = externalIdFactory.createMavenExternalId(caller.getOrganisation(), caller.getName(), caller.getRevision());
                Dependency parent = new Dependency(caller.getName(), caller.getRevision(), parentId);
                logger.debug("Caller id: " + parentId.toString());
                if (rootId.equals(parentId)) {
                    graph.addChildToRoot(child);
                } else {
                    graph.addParentWithChild(parent, child);
                }
            });
        });
    });
    SbtDependencyModule module = new SbtDependencyModule();
    module.setName(report.getModule());
    module.setVersion(report.getRevision());
    module.setOrg(report.getOrganisation());
    module.setGraph(graph);
    module.setConfiguration(report.getConfiguration());
    return module;
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) SbtDependencyModule(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) 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