Search in sources :

Example 1 with LinkMetadata

use of com.blackducksoftware.integration.hub.detect.nameversion.metadata.LinkMetadata 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)1 LinkMetadata (com.blackducksoftware.integration.hub.detect.nameversion.metadata.LinkMetadata)1 ArrayList (java.util.ArrayList)1