Search in sources :

Example 1 with DependencyId

use of com.blackducksoftware.integration.hub.bdio.model.dependencyid.DependencyId in project hub-detect by blackducksoftware.

the class PackRatNodeParser method parseProjectDependencies.

DependencyGraph parseProjectDependencies(final List<String> packratLockContents) {
    final LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder();
    DependencyId currentParent = null;
    String name = null;
    String version = null;
    for (final String line : packratLockContents) {
        if (line.startsWith("PackratFormat:") || line.startsWith("PackratVersion:") || line.startsWith("RVersion:")) {
            continue;
        }
        if (line.contains("Package: ")) {
            name = line.replace("Package: ", "").trim();
            currentParent = new NameDependencyId(name);
            graphBuilder.setDependencyName(currentParent, name);
            graphBuilder.addChildToRoot(currentParent);
            version = null;
            continue;
        }
        if (line.contains("Version: ")) {
            version = line.replace("Version: ", "").trim();
            graphBuilder.setDependencyVersion(currentParent, version);
            final DependencyId realId = new NameVersionDependencyId(name, version);
            final ExternalId externalId = this.externalIdFactory.createNameVersionExternalId(Forge.CRAN, name, version);
            graphBuilder.setDependencyAsAlias(realId, currentParent);
            graphBuilder.setDependencyInfo(realId, name, version, externalId);
            currentParent = realId;
        }
        if (line.contains("Requires: ")) {
            final String[] parts = line.replace("Requires: ", "").split(",");
            for (int i = 0; i < parts.length; i++) {
                final String childName = parts[i].trim();
                graphBuilder.addParentWithChild(currentParent, new NameDependencyId(childName));
            }
        }
    }
    return graphBuilder.build();
}
Also used : NameVersionDependencyId(com.blackducksoftware.integration.hub.bdio.model.dependencyid.NameVersionDependencyId) DependencyId(com.blackducksoftware.integration.hub.bdio.model.dependencyid.DependencyId) NameVersionDependencyId(com.blackducksoftware.integration.hub.bdio.model.dependencyid.NameVersionDependencyId) NameDependencyId(com.blackducksoftware.integration.hub.bdio.model.dependencyid.NameDependencyId) NameDependencyId(com.blackducksoftware.integration.hub.bdio.model.dependencyid.NameDependencyId) LazyExternalIdDependencyGraphBuilder(com.blackducksoftware.integration.hub.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) ExternalId(com.blackducksoftware.integration.hub.bdio.model.externalid.ExternalId)

Aggregations

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