Search in sources :

Example 1 with ExternalId

use of com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId in project hub-detect by blackducksoftware.

the class DetectProjectManager method createAggregateSimpleBdioDocument.

private SimpleBdioDocument createAggregateSimpleBdioDocument(final String projectName, final String projectVersionName, final DependencyGraph dependencyGraph) {
    final String codeLocationName = "";
    final ExternalId projectExternalId = simpleBdioFactory.createNameVersionExternalId(new Forge("/", "/", ""), projectName, projectVersionName);
    return createSimpleBdioDocument(codeLocationName, projectName, projectVersionName, projectExternalId, dependencyGraph);
}
Also used : ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId) Forge(com.blackducksoftware.integration.hub.bdio.model.Forge)

Example 2 with ExternalId

use of com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId 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 3 with ExternalId

use of com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId 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 4 with ExternalId

use of com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId 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)

Example 5 with ExternalId

use of com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId in project hub-detect by blackducksoftware.

the class DetectProjectManager method createSimpleBdioDocument.

private SimpleBdioDocument createSimpleBdioDocument(final String codeLocationName, final String projectName, final String projectVersionName, final DetectCodeLocation detectCodeLocation) {
    final ExternalId projectExternalId = detectCodeLocation.getBomToolProjectExternalId();
    final DependencyGraph dependencyGraph = detectCodeLocation.getDependencyGraph();
    return createSimpleBdioDocument(codeLocationName, projectName, projectVersionName, projectExternalId, dependencyGraph);
}
Also used : ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId) MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) DependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.DependencyGraph)

Aggregations

ExternalId (com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId)9 Dependency (com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)6 Forge (com.blackducksoftware.integration.hub.bdio.model.Forge)2 DependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.DependencyGraph)1 MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)1 LazyExternalIdDependencyGraphBuilder (com.blackducksoftware.integration.hub.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder)1 DependencyId (com.blackducksoftware.integration.hub.bdio.model.dependencyid.DependencyId)1 NameDependencyId (com.blackducksoftware.integration.hub.bdio.model.dependencyid.NameDependencyId)1 NameVersionDependencyId (com.blackducksoftware.integration.hub.bdio.model.dependencyid.NameVersionDependencyId)1 ExternalIdFactory (com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalIdFactory)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1