Search in sources :

Example 1 with NodeMetadata

use of com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata in project hub-detect by blackducksoftware.

the class CocoapodsPackager method extractDependencyGraph.

public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
    YAMLMapper mapper = new YAMLMapper();
    PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
    NameVersionNode root = new NameVersionNode();
    root.setName(String.format("detectRootNode - %s", UUID.randomUUID()));
    final SubcomponentNodeBuilder builder = new SubcomponentNodeBuilder(root);
    for (Pod pod : podfileLock.getPods()) {
        buildNameVersionNode(builder, pod);
    }
    ;
    for (Pod dependency : podfileLock.getDependencies()) {
        NameVersionNode child = new NameVersionNode();
        child.setName(cleanPodName(dependency.getName()));
        builder.addChildNodeToParent(child, root);
    }
    ;
    if (null != podfileLock.getExternalSources() && !podfileLock.getExternalSources().getSources().isEmpty()) {
        for (PodSource podSource : podfileLock.getExternalSources().getSources()) {
            NodeMetadata nodeMetadata = createMetadata(builder, podSource.getName());
            if (null != podSource.getGit() && podSource.getGit().contains("github")) {
                // Change the forge to GitHub when there is better KB support
                nodeMetadata.setForge(Forge.COCOAPODS);
            } else if (null != podSource.getPath() && podSource.getPath().contains("node_modules")) {
                nodeMetadata.setForge(Forge.NPM);
            }
        }
    }
    MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (NameVersionNode nameVersionNode : builder.build().getChildren()) {
        Dependency childDependency = nameVersionNodeTransformer.addNameVersionNodeToDependencyGraph(graph, Forge.COCOAPODS, nameVersionNode);
        graph.addChildToRoot(childDependency);
    }
    return graph;
}
Also used : NodeMetadata(com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata) MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) SubcomponentNodeBuilder(com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder) NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Aggregations

MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)1 MutableMapDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph)1 Dependency (com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)1 NameVersionNode (com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode)1 NodeMetadata (com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata)1 SubcomponentNodeBuilder (com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1