Search in sources :

Example 11 with BasicDependencyGraph

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

the class RootPruningGraphUtilTests method cyclicalGraphPruned.

@Test()
public void cyclicalGraphPruned() {
    Dependency parent = dependencyFactory.createNameVersionDependency(anyForge, "parent", "version");
    Dependency child = dependencyFactory.createNameVersionDependency(anyForge, "child", "version");
    DependencyGraph graph = new BasicDependencyGraph();
    graph.addChildrenToRoot(parent);
    graph.addParentWithChild(parent, child);
    graph.addParentWithChild(child, parent);
    Assertions.assertThrows(CycleDetectedException.class, () -> RootPruningGraphUtil.prune(graph));
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Test(org.junit.jupiter.api.Test)

Example 12 with BasicDependencyGraph

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

the class RootPruningGraphUtilTests method simpleTwoRootIsPruned.

@Test
public void simpleTwoRootIsPruned() throws CycleDetectedException {
    Dependency root1 = dependencyFactory.createNameVersionDependency(anyForge, "root1", "version");
    Dependency root2 = dependencyFactory.createNameVersionDependency(anyForge, "root2", "version");
    Dependency child = dependencyFactory.createNameVersionDependency(anyForge, "child", "version");
    DependencyGraph graph = new BasicDependencyGraph();
    graph.addChildrenToRoot(root1, root2);
    graph.addParentWithChild(root1, child);
    graph.addParentWithChild(child, root2);
    DependencyGraph prunedGraph = RootPruningGraphUtil.prune(graph);
    NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(anyForge, prunedGraph);
    graphAssert.hasRootSize(1);
    graphAssert.hasRootDependency("root1", "version");
    graphAssert.hasParentChildRelationship("root1", "version", "child", "version");
    graphAssert.hasParentChildRelationship("child", "version", "root2", "version");
}
Also used : NameVersionGraphAssert(com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Test(org.junit.jupiter.api.Test)

Example 13 with BasicDependencyGraph

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

the class GraphDeserializer method deserialize.

public static DependencyGraph deserialize(String text) {
    DependencyGraph graph = new BasicDependencyGraph();
    // three sections
    List<String> lines = Arrays.asList(text.split("\n"));
    int currentLineIndex = 0;
    String currentLine = lines.get(0);
    while (!currentLine.startsWith("Root Dependencies")) {
        currentLineIndex++;
        currentLine = lines.get(currentLineIndex);
    }
    while (!currentLine.startsWith("Relationships")) {
        // In Root
        currentLineIndex++;
        currentLine = lines.get(currentLineIndex);
        if (!currentLine.startsWith("Relationships")) {
            graph.addChildToRoot(make(currentLine));
        }
    }
    Dependency parent = null;
    while (currentLineIndex + 1 < lines.size()) {
        // In Relationships
        currentLineIndex++;
        currentLine = lines.get(currentLineIndex);
        if (currentLine.startsWith("\t\t")) {
            graph.addChildWithParent(make(currentLine), parent);
        } else if (currentLine.startsWith("\t")) {
            parent = make(currentLine);
        }
    }
    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) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 14 with BasicDependencyGraph

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

the class CarthageDeclarationTransformer method transform.

public DependencyGraph transform(List<CarthageDeclaration> carthageDeclarations) {
    DependencyGraph graph = new BasicDependencyGraph();
    carthageDeclarations.stream().filter(this::isGitHubOrigin).map(this::createGitHubDependencyFromDeclaration).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)

Example 15 with BasicDependencyGraph

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

the class BitbakeDependencyGraphTransformer method buildGraph.

@NotNull
private DependencyGraph buildGraph(BitbakeGraph bitbakeGraph, Map<String, Dependency> namesToExternalIds) {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    for (BitbakeNode bitbakeNode : bitbakeGraph.getNodes()) {
        String name = bitbakeNode.getName();
        if (namesToExternalIds.containsKey(name)) {
            Dependency dependency = namesToExternalIds.get(bitbakeNode.getName());
            dependencyGraph.addChildToRoot(dependency);
            for (String child : bitbakeNode.getChildren()) {
                if (namesToExternalIds.containsKey(child)) {
                    Dependency childDependency = namesToExternalIds.get(child);
                    dependencyGraph.addParentWithChild(dependency, childDependency);
                }
            }
        }
    }
    return dependencyGraph;
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BitbakeNode(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeNode) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) NotNull(org.jetbrains.annotations.NotNull)

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