Search in sources :

Example 6 with NameVersionNode

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

the class LinkedNameVersionNodeBuilder method resolveLinks.

private NameVersionNode resolveLinks(final Set<String> cyclicalNames, final Stack<String> cyclicalStack, final NameVersionNode nameVersionNode) {
    if (nameVersionNode == null) {
        return null;
    }
    final String name = nameVersionNode.getName();
    if (cyclicalStack.contains(name)) {
        cyclicalNames.add(name);
        return null;
    }
    cyclicalStack.push(name);
    NameVersionNode resolvedNode = nameVersionNode;
    final LinkMetadata linkMetadata = getLinkMetadata(nameVersionNode);
    if (linkMetadata != null && linkMetadata.getLinkNode() != null) {
        resolvedNode = resolveLinks(cyclicalNames, cyclicalStack, linkMetadata.getLinkNode());
    }
    if (resolvedNode != null) {
        final List<NameVersionNode> resolvedChildren = new ArrayList<>();
        for (final NameVersionNode child : resolvedNode.getChildren()) {
            final NameVersionNode resolvedChild = resolveLinks(cyclicalNames, cyclicalStack, child);
            if (resolvedChild != null) {
                resolvedChildren.add(resolvedChild);
            }
        }
        resolvedNode.setChildren(resolvedChildren);
    }
    cyclicalStack.pop();
    return resolvedNode;
}
Also used : NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) LinkMetadata(com.blackducksoftware.integration.hub.detect.nameversion.metadata.LinkMetadata) ArrayList(java.util.ArrayList)

Aggregations

NameVersionNode (com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode)6 MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)2 MutableMapDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph)2 Dependency (com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)2 NodeMetadata (com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata)1 SubcomponentNodeBuilder (com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder)1 LinkMetadata (com.blackducksoftware.integration.hub.detect.nameversion.metadata.LinkMetadata)1 SubcomponentMetadata (com.blackducksoftware.integration.hub.detect.nameversion.metadata.SubcomponentMetadata)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1