Search in sources :

Example 41 with Dependency

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

the class AggregateBdioCreator method createAggregateDependencyGraph.

private DependencyGraph createAggregateDependencyGraph(File sourcePath, final List<DetectCodeLocation> codeLocations) {
    final MutableDependencyGraph aggregateDependencyGraph = simpleBdioFactory.createMutableDependencyGraph();
    for (final DetectCodeLocation detectCodeLocation : codeLocations) {
        final Dependency codeLocationDependency = createAggregateDependency(sourcePath, detectCodeLocation);
        aggregateDependencyGraph.addChildrenToRoot(codeLocationDependency);
        aggregateDependencyGraph.addGraphAsChildrenToParent(codeLocationDependency, detectCodeLocation.getDependencyGraph());
    }
    return aggregateDependencyGraph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 42 with Dependency

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

the class PearParser method createPearDependencyGraphFromList.

DependencyGraph createPearDependencyGraphFromList(final List<String> dependencyList, final List<String> dependencyNames) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    if (dependencyList.size() > 3) {
        final List<String> listing = dependencyList.subList(3, dependencyList.size() - 1);
        listing.forEach(line -> {
            final String[] dependencyInfo = splitIgnoringWhitespace(line, " ");
            final String packageName = dependencyInfo[0].trim();
            final String packageVersion = dependencyInfo[1].trim();
            if (dependencyInfo.length > 0 && dependencyNames.contains(packageName)) {
                final Dependency child = new Dependency(packageName, packageVersion, externalIdFactory.createNameVersionExternalId(Forge.PEAR, packageName, packageVersion));
                graph.addChildToRoot(child);
            }
        });
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 43 with Dependency

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

the class YarnListParser method parseDependencyFromLine.

public Dependency parseDependencyFromLine(final String cleanedLine, final Map<String, String> yarnLockVersionMap) {
    final String fuzzyNameVersionString = cleanedLine.trim();
    String cleanedFuzzyNameVersionString = fuzzyNameVersionString;
    if (fuzzyNameVersionString.startsWith("@")) {
        cleanedFuzzyNameVersionString = fuzzyNameVersionString.substring(1);
    }
    final String[] nameVersionArray = cleanedFuzzyNameVersionString.split("@");
    final NameVersion nameVersion = new NameVersion(nameVersionArray[0], nameVersionArray[1]);
    final String resolvedVersion = yarnLockVersionMap.get(fuzzyNameVersionString);
    if (resolvedVersion != null) {
        nameVersion.setVersion(resolvedVersion);
    }
    final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPM, nameVersion.getName(), nameVersion.getVersion());
    return new Dependency(nameVersion.getName(), nameVersion.getVersion(), externalId);
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 44 with Dependency

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

the class YarnListParser method parseYarnList.

public DependencyGraph parseYarnList(final List<String> yarnLockText, final List<String> yarnListAsList) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final DependencyHistory history = new DependencyHistory();
    final Map<String, String> yarnLockVersionMap = yarnLockParser.getYarnLockResolvedVersionMap(yarnLockText);
    for (final String line : yarnListAsList) {
        final String lowerCaseLine = line.toLowerCase().trim();
        final String cleanedLine = line.replaceAll(NTH_DEPENDENCY_PREFIX, "").replaceAll(INNER_LEVEL_CHARACTER, "").replaceAll(LAST_DEPENDENCY_PREFIX, "");
        if (!cleanedLine.contains("@") || lowerCaseLine.startsWith("yarn list") || lowerCaseLine.startsWith("done in") || lowerCaseLine.startsWith("warning")) {
            continue;
        }
        final Dependency dependency = parseDependencyFromLine(cleanedLine, yarnLockVersionMap);
        final int lineLevel = getLineLevel(cleanedLine);
        try {
            history.clearDependenciesDeeperThan(lineLevel);
        } catch (final IllegalStateException e) {
            logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
        }
        if (history.isEmpty()) {
            graph.addChildToRoot(dependency);
        } else {
            graph.addChildWithParents(dependency, history.getLastDependency());
        }
        history.add(dependency);
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) DependencyHistory(com.blackducksoftware.integration.hub.detect.util.DependencyHistory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 45 with Dependency

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

the class SbtDependencyResolver method resolveReport.

public SbtDependencyModule resolveReport(final SbtReport report) {
    final ExternalId rootId = externalIdFactory.createMavenExternalId(report.getOrganisation(), report.getModule(), report.getRevision());
    logger.debug("Created external id: " + rootId.toString());
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    logger.debug("Dependencies found: " + report.getDependencies().size());
    report.getDependencies().forEach(module -> {
        logger.debug("Revisions found: " + module.getRevisions().size());
        module.getRevisions().forEach(revision -> {
            logger.debug("Callers found: " + revision.getCallers().size());
            final ExternalId id = externalIdFactory.createMavenExternalId(module.getOrganisation(), module.getName(), revision.getName());
            final Dependency child = new Dependency(module.getName(), revision.getName(), id);
            revision.getCallers().forEach(caller -> {
                final ExternalId parentId = externalIdFactory.createMavenExternalId(caller.getOrganisation(), caller.getName(), caller.getRevision());
                final Dependency parent = new Dependency(caller.getName(), caller.getRevision(), parentId);
                logger.debug("Caller id: " + parentId.toString());
                if (rootId.equals(parentId)) {
                    graph.addChildToRoot(child);
                } else {
                    graph.addParentWithChild(parent, child);
                }
            });
        });
    });
    final SbtDependencyModule module = new SbtDependencyModule();
    module.name = report.getModule();
    module.version = report.getRevision();
    module.org = report.getOrganisation();
    module.graph = graph;
    module.configuration = report.getConfiguration();
    return module;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Aggregations

Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)46 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)23 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)12 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)11 Test (org.junit.Test)11 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)10 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)9 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 File (java.io.File)5 DependencyHistory (com.blackducksoftware.integration.hub.detect.util.DependencyHistory)4 ArrayList (java.util.ArrayList)3 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)2 Gson (com.google.gson.Gson)2 Forge (com.synopsys.integration.bdio.model.Forge)2 NpmDependency (com.blackducksoftware.integration.hub.detect.detector.npm.model.NpmDependency)1 PackageLockDependency (com.blackducksoftware.integration.hub.detect.detector.npm.model.PackageLockDependency)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 DetectCodeLocationType (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocationType)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1