Search in sources :

Example 1 with NameVersionNode

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

the class CpanPackager method makeDependencyGraph.

public DependencyGraph makeDependencyGraph(List<String> cpanListText, List<String> directDependenciesText) {
    Map<String, NameVersionNode> allModules = cpanListParser.parse(cpanListText);
    List<String> directModuleNames = getDirectModuleNames(directDependenciesText);
    MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (String moduleName : directModuleNames) {
        NameVersionNode nameVersionNode = allModules.get(moduleName);
        if (null != nameVersionNode) {
            nameVersionNode.setName(nameVersionNode.getName().replace("::", "-"));
            Dependency module = nameVersionNodeTransformer.addNameVersionNodeToDependencyGraph(graph, Forge.CPAN, nameVersionNode);
            graph.addChildToRoot(module);
        } else {
            logger.warn(String.format("Could node find resolved version for module: %s", moduleName));
        }
    }
    return graph;
}
Also used : MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 2 with NameVersionNode

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

the class LinkedNameVersionNodeBuilder method build.

@Override
public NameVersionNode build() {
    final Stack<String> cyclicalStack = new Stack<>();
    final Set<String> cyclicalNames = new HashSet<>();
    final NameVersionNode resolved = resolveLinks(cyclicalNames, cyclicalStack, root);
    for (final String cyclicalName : cyclicalNames) {
        logger.debug(String.format("Cyclical depdency detected: %s", cyclicalName));
    }
    return resolved;
}
Also used : NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) Stack(java.util.Stack) HashSet(java.util.HashSet)

Example 3 with NameVersionNode

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

the class CocoapodsPackager method buildNameVersionNode.

private NameVersionNode buildNameVersionNode(SubcomponentNodeBuilder builder, Pod pod) {
    NameVersionNode nameVersionNode = new NameVersionNode();
    nameVersionNode.setName(cleanPodName(pod.getName()));
    pod.setCleanName(nameVersionNode.getName());
    String[] segments = pod.getName().split(" ");
    if (segments.length > 1) {
        String version = segments[1];
        version = version.replace("(", "").replace(")", "").trim();
        if (!isVersionFuzzy(version)) {
            nameVersionNode.setVersion(version);
        }
    }
    for (String dependency : pod.getDependencies()) {
        builder.addChildNodeToParent(buildNameVersionNode(builder, new Pod(dependency)), nameVersionNode);
    }
    if (pod.getDependencies().isEmpty()) {
        builder.addToCache(nameVersionNode);
    }
    if (nameVersionNode.getName().contains("/")) {
        String superNodeName = nameVersionNode.getName().split("/")[0].trim();
        NameVersionNode superNode = new NameVersionNode();
        superNode.setName(superNodeName);
        superNode = builder.addToCache(superNode);
        SubcomponentMetadata superNodeMetadata = createMetadata(builder, superNode.getName());
        superNodeMetadata.getSubcomponents().add(nameVersionNode);
        SubcomponentMetadata subcomponentMetadata = createMetadata(builder, nameVersionNode.getName());
        subcomponentMetadata.setLinkNode(superNode);
        builder.getSuperComponents().add(superNode);
    }
    return nameVersionNode;
}
Also used : SubcomponentMetadata(com.blackducksoftware.integration.hub.detect.nameversion.metadata.SubcomponentMetadata) NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode)

Example 4 with NameVersionNode

use of com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode 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)

Example 5 with NameVersionNode

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

the class CpanListParser method parse.

public Map<String, NameVersionNode> parse(List<String> listText) {
    Map<String, NameVersionNode> moduleMap = new HashMap<>();
    for (String line : listText) {
        if (StringUtils.isBlank(line)) {
            continue;
        }
        if (StringUtils.countMatches(line, "\t") != 1 || line.trim().contains(" ")) {
            continue;
        }
        try {
            String[] module = line.trim().split("\t");
            NameVersionNode nameVersionNode = new NameVersionNode();
            nameVersionNode.setName(module[0].trim());
            nameVersionNode.setVersion(module[1].trim());
            moduleMap.put(nameVersionNode.getName(), nameVersionNode);
        } catch (IndexOutOfBoundsException indexOutOfBoundsException) {
            logger.debug(String.format("Failed to handle the following line:%s", line));
        }
    }
    return moduleMap;
}
Also used : NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) HashMap(java.util.HashMap)

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