Search in sources :

Example 6 with Dependency

use of com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency 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 7 with Dependency

use of com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class CondaListParser method condaListElementToDependency.

public Dependency condaListElementToDependency(String platform, CondaListElement element) {
    String name = element.getName();
    String version = String.format("%s-%s-%s", element.getVersion(), element.getBuildString(), platform);
    ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.ANACONDA, name, version);
    return new Dependency(name, version, externalId);
}
Also used : ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 8 with Dependency

use of com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class GradleReportLine method createDependencyNode.

public Dependency createDependencyNode(final ExternalIdFactory externalIdFactory) {
    if (!originalLine.contains(COMPONENT_PREFIX)) {
        return null;
    }
    String cleanedOutput = StringUtils.trimToEmpty(originalLine);
    cleanedOutput = cleanedOutput.substring(cleanedOutput.indexOf(COMPONENT_PREFIX) + COMPONENT_PREFIX.length());
    if (cleanedOutput.endsWith(SEEN_ELSEWHERE_SUFFIX)) {
        final int lastSeenElsewhereIndex = cleanedOutput.lastIndexOf(SEEN_ELSEWHERE_SUFFIX);
        cleanedOutput = cleanedOutput.substring(0, lastSeenElsewhereIndex);
    }
    // we might need to modify the returned list, so it needs to be an actual ArrayList
    List<String> gavPieces = new ArrayList<>(Arrays.asList(cleanedOutput.split(":")));
    if (cleanedOutput.contains(WINNING_INDICATOR)) {
        // WINNING_INDICATOR can point to an entire GAV not just a version
        final String winningSection = cleanedOutput.substring(cleanedOutput.indexOf(WINNING_INDICATOR) + WINNING_INDICATOR.length());
        if (winningSection.contains(":")) {
            gavPieces = Arrays.asList(winningSection.split(":"));
        } else {
            // the WINNING_INDICATOR is not always preceded by a : so if isn't, we need to clean up from the original split
            if (gavPieces.get(1).contains(WINNING_INDICATOR)) {
                final String withoutWinningIndicator = gavPieces.get(1).substring(0, gavPieces.get(1).indexOf(WINNING_INDICATOR));
                gavPieces.set(1, withoutWinningIndicator);
                // since there was no : we don't have a gav piece for version yet
                gavPieces.add("");
            }
            gavPieces.set(2, winningSection);
        }
    }
    if (gavPieces.size() != 3) {
        logger.error(String.format("The line can not be reasonably split in to the neccessary parts: %s", originalLine));
        return null;
    }
    final String group = gavPieces.get(0);
    final String artifact = gavPieces.get(1);
    final String version = gavPieces.get(2);
    final Dependency dependency = new Dependency(artifact, version, externalIdFactory.createMavenExternalId(group, artifact, version));
    return dependency;
}
Also used : ArrayList(java.util.ArrayList) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 9 with Dependency

use of com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class NameVersionNodeTransformer method addNameVersionNodeToDependencyGraph.

public Dependency addNameVersionNodeToDependencyGraph(final MutableDependencyGraph graph, final Forge defaultForge, final NameVersionNode nameVersionNode) {
    Forge forge = defaultForge;
    if (nameVersionNode.getMetadata() != null && nameVersionNode.getMetadata().getForge() != null) {
        forge = nameVersionNode.getMetadata().getForge();
    }
    final ExternalId externalId = externalIdFactory.createNameVersionExternalId(forge, nameVersionNode.getName(), nameVersionNode.getVersion());
    final Dependency parentDependency = new Dependency(nameVersionNode.getName(), nameVersionNode.getVersion(), externalId);
    for (final NameVersionNode child : nameVersionNode.getChildren()) {
        final Dependency childDependency = addNameVersionNodeToDependencyGraph(graph, defaultForge, child);
        graph.addParentWithChild(parentDependency, childDependency);
    }
    return parentDependency;
}
Also used : ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId) Forge(com.blackducksoftware.integration.hub.bdio.model.Forge) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 10 with Dependency

use of com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.

the class DependencyGraphAssertions method assertHasMavenGav.

public static void assertHasMavenGav(final DependencyGraph dependencyGraph, final String org, final String name, final String version) {
    final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    final ExternalId id = externalIdFactory.createMavenExternalId(org, name, version);
    final Dependency dep = dependencyGraph.getDependency(id);
    assertNotNull("Expected dependency '" + org + ":" + name + ":" + version + "' to exist in graph but it was null.", dep);
}
Also used : ExternalIdFactory(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalIdFactory) ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Aggregations

Dependency (com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)11 ExternalId (com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId)6 MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)3 MutableMapDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph)3 NameVersionNode (com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode)2 Forge (com.blackducksoftware.integration.hub.bdio.model.Forge)1 ExternalIdFactory (com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalIdFactory)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation)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 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1