Search in sources :

Example 1 with Dependency

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

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

the class NameVersionNodeTransformer method createDependencyGraph.

public DependencyGraph createDependencyGraph(final Forge defaultForge, final NameVersionNode nameVersionNode, final Boolean rootIsRealRoot) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final Dependency root = addNameVersionNodeToDependencyGraph(graph, defaultForge, nameVersionNode);
    if (rootIsRealRoot) {
        graph.addChildToRoot(root);
    } else {
        graph.addChildrenToRoot(graph.getChildrenForParent(root));
    }
    return graph;
}
Also used : MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 3 with Dependency

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

the class GradleReportParser method parseDependencies.

public DetectCodeLocation parseDependencies(final DetectProject detectProject, final InputStream dependenciesInputStream) {
    clearState();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(dependenciesInputStream, StandardCharsets.UTF_8))) {
        while (reader.ready()) {
            final String line = reader.readLine();
            /**
             * The meta data section will be at the end of the file after all of the "gradle dependencies" output
             */
            if (line.startsWith("DETECT META DATA START")) {
                processingMetaData = true;
                continue;
            }
            if (line.startsWith("DETECT META DATA END")) {
                processingMetaData = false;
                continue;
            }
            if (processingMetaData) {
                processMetaDataLine(line);
                continue;
            }
            if (StringUtils.isBlank(line)) {
                clearConfigurationState();
                continue;
            }
            final Dependency nextDependency = gradleReportConfigurationParser.parseDependency(externalIdFactory, line);
            if (nextDependency == null) {
                continue;
            }
            final int lineTreeLevel = gradleReportConfigurationParser.getTreeLevel();
            if (lineTreeLevel == previousTreeLevel + 1) {
                nodeStack.push(previousNode);
            } else if (lineTreeLevel < previousTreeLevel) {
                for (int times = 0; times < (previousTreeLevel - lineTreeLevel); times++) {
                    nodeStack.pop();
                }
            } else if (lineTreeLevel != previousTreeLevel) {
                logger.error(String.format("The tree level (%s) and this line (%s) with count %s can't be reconciled.", previousTreeLevel, line, lineTreeLevel));
            }
            if (nodeStack.size() == 0) {
                graph.addChildToRoot(nextDependency);
            } else {
                graph.addChildWithParents(nextDependency, nodeStack.peek());
            }
            previousNode = nextDependency;
            previousTreeLevel = lineTreeLevel;
        }
    } catch (final Exception e) {
        logger.error("Exception parsing gradle output: " + e.getMessage());
    }
    detectProject.setProjectNameIfNotSet(rootProjectName);
    detectProject.setProjectVersionNameIfNotSet(rootProjectVersionName);
    final ExternalId id = externalIdFactory.createMavenExternalId(projectGroup, projectName, projectVersionName);
    final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(BomToolType.GRADLE, projectSourcePath, id, graph).bomToolProjectName(projectName).bomToolProjectVersionName(projectVersionName).build();
    return detectCodeLocation;
}
Also used : InputStreamReader(java.io.InputStreamReader) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation) ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId) BufferedReader(java.io.BufferedReader) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 4 with Dependency

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

the class DependencyGraphAssertions method assertParentHasChildMavenGav.

public static void assertParentHasChildMavenGav(final String parentGav, final DependencyGraph dependencyGraph, final String targetGavChild) {
    final ExternalId parentId = mavenGavToExternalId(parentGav);
    final ExternalId childId = mavenGavToExternalId(targetGavChild);
    final Dependency dep = dependencyGraph.getDependency(parentId);
    assertNotNull("Graph does not have gav '" + parentGav + "'", dep);
    final Set<ExternalId> children = dependencyGraph.getChildrenExternalIdsForParent(dep);
    assertTrue("Parent gav '" + parentGav + "' does not have child gav '" + targetGavChild + "'", children.contains(childId));
}
Also used : ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 5 with Dependency

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

the class DependencyGraphAssertions method assertHasRootMavenGav.

public static void assertHasRootMavenGav(final DependencyGraph dependencyGraph, final String targetGav) {
    final ExternalId targetId = mavenGavToExternalId(targetGav);
    final Dependency dep = dependencyGraph.getDependency(targetId);
    assertNotNull(dep);
}
Also used : 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