Search in sources :

Example 1 with LazyExternalIdDependencyGraphBuilder

use of com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder in project hub-detect by blackducksoftware.

the class PodlockParser method extractDependencyGraph.

public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
    final LazyExternalIdDependencyGraphBuilder lazyBuilder = new LazyExternalIdDependencyGraphBuilder();
    final YAMLMapper mapper = new YAMLMapper();
    final PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
    final Map<DependencyId, Forge> forgeOverrides = createForgeOverrideMap(podfileLock);
    for (final Pod pod : podfileLock.pods) {
        logger.trace(String.format("Processing pod %s", pod.name));
        processPod(pod, forgeOverrides, lazyBuilder);
    }
    for (final Pod dependency : podfileLock.dependencies) {
        logger.trace(String.format("Processing pod dependency from pod lock file %s", dependency.name));
        final String podText = dependency.name;
        final Optional<DependencyId> dependencyId = parseDependencyId(podText);
        if (dependencyId.isPresent()) {
            lazyBuilder.addChildToRoot(dependencyId.get());
        }
    }
    logger.trace("Attempting to build the dependency graph.");
    final DependencyGraph dependencyGraph = lazyBuilder.build();
    logger.trace("Completed the dependency graph.");
    return dependencyGraph;
}
Also used : DependencyId(com.synopsys.integration.bdio.model.dependencyid.DependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Example 2 with LazyExternalIdDependencyGraphBuilder

use of com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder 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.synopsys.integration.bdio.model.dependencyid.NameVersionDependencyId) DependencyId(com.synopsys.integration.bdio.model.dependencyid.DependencyId) NameVersionDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameVersionDependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId)

Example 3 with LazyExternalIdDependencyGraphBuilder

use of com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder in project hub-detect by blackducksoftware.

the class GraphParserTransformer method transform.

public DependencyGraph transform(final GraphParser graphParser, final String targetArchitecture) {
    final Map<String, GraphNode> nodes = graphParser.getNodes();
    final Map<String, GraphEdge> edges = graphParser.getEdges();
    final LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder();
    for (final GraphNode graphNode : nodes.values()) {
        final String name = getNameFromNode(graphNode);
        final DependencyId dependencyId = new NameDependencyId(name);
        final Optional<String> version = getVersionFromNode(graphNode);
        if (version.isPresent()) {
            final ExternalId externalId = new ExternalId(Forge.YOCTO);
            externalId.name = name;
            externalId.version = version.get();
            externalId.architecture = targetArchitecture;
            graphBuilder.setDependencyInfo(dependencyId, name, version.get(), externalId);
        }
        graphBuilder.addChildToRoot(dependencyId);
    }
    for (final GraphEdge graphEdge : edges.values()) {
        final DependencyId node1 = new NameDependencyId(getNameFromNode(graphEdge.getNode1()));
        final DependencyId node2 = new NameDependencyId(getNameFromNode(graphEdge.getNode2()));
        graphBuilder.addParentWithChild(node1, node2);
    }
    return graphBuilder.build();
}
Also used : DependencyId(com.synopsys.integration.bdio.model.dependencyid.DependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) GraphNode(com.paypal.digraph.parser.GraphNode) GraphEdge(com.paypal.digraph.parser.GraphEdge)

Example 4 with LazyExternalIdDependencyGraphBuilder

use of com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder in project hub-detect by blackducksoftware.

the class PackagistParser method getDependencyGraphFromProject.

public PackagistParseResult getDependencyGraphFromProject(final String sourcePath, final String composerJsonText, final String composerLockText) {
    final LazyExternalIdDependencyGraphBuilder builder = new LazyExternalIdDependencyGraphBuilder();
    final JsonObject composerJsonObject = new JsonParser().parse(composerJsonText).getAsJsonObject();
    final NameVersion projectNameVersion = parseNameVersionFromJson(composerJsonObject);
    final JsonObject composerLockObject = new JsonParser().parse(composerLockText).getAsJsonObject();
    final List<PackagistPackage> models = convertJsonToModel(composerLockObject, detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PACKAGIST_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None));
    final List<NameVersion> rootPackages = parseDependencies(composerJsonObject, detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PACKAGIST_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None));
    models.forEach(it -> {
        final ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, it.getNameVersion().getName(), it.getNameVersion().getVersion());
        final NameDependencyId dependencyId = new NameDependencyId(it.getNameVersion().getName());
        builder.setDependencyInfo(dependencyId, it.getNameVersion().getName(), it.getNameVersion().getVersion(), id);
        if (isRootPackage(it.getNameVersion(), rootPackages)) {
            builder.addChildToRoot(dependencyId);
        }
        it.getDependencies().forEach(child -> {
            if (existsInPackages(child, models)) {
                final NameDependencyId childId = new NameDependencyId(child.getName());
                builder.addChildWithParent(childId, dependencyId);
            } else {
                logger.warn("Dependency was not found in packages list but found a require that used it: " + child.getName());
            }
        });
    });
    ExternalId projectExternalId;
    if (projectNameVersion.getName() == null || projectNameVersion.getVersion() == null) {
        projectExternalId = externalIdFactory.createPathExternalId(Forge.PACKAGIST, sourcePath);
    } else {
        projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, projectNameVersion.getName(), projectNameVersion.getVersion());
    }
    final DependencyGraph graph = builder.build();
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PACKAGIST, sourcePath, projectExternalId, graph).build();
    return new PackagistParseResult(projectNameVersion.getName(), projectNameVersion.getVersion(), codeLocation);
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) JsonObject(com.google.gson.JsonObject) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) JsonParser(com.google.gson.JsonParser)

Example 5 with LazyExternalIdDependencyGraphBuilder

use of com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder in project hub-detect by blackducksoftware.

the class GemlockParser method parseProjectDependencies.

public DependencyGraph parseProjectDependencies(final List<String> gemfileLockLines) {
    encounteredDependencies = new ArrayList<>();
    resolvedDependencies = new ArrayList<>();
    lazyBuilder = new LazyExternalIdDependencyGraphBuilder();
    currentParent = null;
    for (final String line : gemfileLockLines) {
        final String trimmedLine = StringUtils.trimToEmpty(line);
        if (StringUtils.isBlank(trimmedLine)) {
            currentSection = NONE;
        } else if (SPECS_HEADER.equals(trimmedLine)) {
            currentSection = SPECS;
        } else if (DEPENDENCIES_HEADER.equals(trimmedLine)) {
            currentSection = DEPENDENCIES;
        } else if (BUNDLED_WITH_HEADER.equals(trimmedLine)) {
            currentSection = BUNDLED_WITH;
        } else if (BUNDLED_WITH.equals(currentSection)) {
            addBundlerDependency(trimmedLine);
        } else if (SPECS.equals(currentSection)) {
            parseSpecsSectionLine(line);
        } else if (DEPENDENCIES.equals(currentSection)) {
            parseDependencySectionLine(trimmedLine);
        }
    }
    List<String> missingDependencies = encounteredDependencies.stream().filter(it -> !resolvedDependencies.contains(it)).collect(Collectors.toList());
    for (final String missingName : missingDependencies) {
        String missingVersion = "";
        final DependencyId dependencyId = new NameDependencyId(missingName);
        final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.RUBYGEMS, missingName, missingVersion);
        lazyBuilder.setDependencyInfo(dependencyId, missingName, missingVersion, externalId);
    }
    return lazyBuilder.build();
}
Also used : NONE(com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.NONE) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Logger(org.slf4j.Logger) BUNDLED_WITH(com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.BUNDLED_WITH) Forge(com.synopsys.integration.bdio.model.Forge) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) DependencyId(com.synopsys.integration.bdio.model.dependencyid.DependencyId) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) ArrayList(java.util.ArrayList) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) SPECS(com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.SPECS) Optional(java.util.Optional) DEPENDENCIES(com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.DEPENDENCIES) NameVersionDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameVersionDependencyId) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyId(com.synopsys.integration.bdio.model.dependencyid.DependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) NameVersionDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameVersionDependencyId) NameDependencyId(com.synopsys.integration.bdio.model.dependencyid.NameDependencyId) LazyExternalIdDependencyGraphBuilder(com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId)

Aggregations

LazyExternalIdDependencyGraphBuilder (com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder)5 NameDependencyId (com.synopsys.integration.bdio.model.dependencyid.NameDependencyId)5 DependencyId (com.synopsys.integration.bdio.model.dependencyid.DependencyId)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)4 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)3 Forge (com.synopsys.integration.bdio.model.Forge)2 NameVersionDependencyId (com.synopsys.integration.bdio.model.dependencyid.NameVersionDependencyId)2 NameVersion (com.synopsys.integration.util.NameVersion)2 BUNDLED_WITH (com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.BUNDLED_WITH)1 DEPENDENCIES (com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.DEPENDENCIES)1 NONE (com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.NONE)1 SPECS (com.blackducksoftware.integration.hub.detect.detector.rubygems.GemlockParser.GemfileLockSection.SPECS)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 GraphEdge (com.paypal.digraph.parser.GraphEdge)1 GraphNode (com.paypal.digraph.parser.GraphNode)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 ArrayList (java.util.ArrayList)1