Search in sources :

Example 6 with MutableMapDependencyGraph

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

the class GopkgLockParser method parseDepLock.

public DependencyGraph parseDepLock(final String depLockContents) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final GopkgLock gopkgLock = new Toml().read(depLockContents).to(GopkgLock.class);
    for (final Project project : gopkgLock.getProjects()) {
        if (project != null) {
            final NameVersion projectNameVersion = createProjectNameVersion(project);
            project.getPackages().stream().map(packageName -> createDependencyName(projectNameVersion.getName(), packageName)).map(dependencyName -> createGoDependency(dependencyName, projectNameVersion.getVersion())).forEach(graph::addChildToRoot);
        }
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) NameVersion(com.synopsys.integration.util.NameVersion) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Forge(com.synopsys.integration.bdio.model.Forge) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) Toml(com.moandjiezana.toml.Toml) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) StringUtils(org.apache.commons.lang3.StringUtils) NameVersion(com.synopsys.integration.util.NameVersion) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Toml(com.moandjiezana.toml.Toml)

Example 7 with MutableMapDependencyGraph

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

the class CondaListParser method parse.

public DependencyGraph parse(final String listJsonText, final String infoJsonText) {
    final Type listType = new TypeToken<ArrayList<CondaListElement>>() {
    }.getType();
    final List<CondaListElement> condaList = gson.fromJson(listJsonText, listType);
    final CondaInfo condaInfo = gson.fromJson(infoJsonText, CondaInfo.class);
    final String platform = condaInfo.platform;
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (final CondaListElement condaListElement : condaList) {
        graph.addChildToRoot(condaListElementToDependency(platform, condaListElement));
    }
    return graph;
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)

Example 8 with MutableMapDependencyGraph

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

the class RebarParserTest method testParseRebarTreeOutput.

@Test
public void testParseRebarTreeOutput() {
    final MutableMapDependencyGraph expectedGraph = new MutableMapDependencyGraph();
    final Dependency gitInnerParentDependency = buildDependency("git_inner_parent_dependency", "0.0.2");
    final Dependency hexInnerChildDependency = buildDependency("hex_inner_child_dependency", "0.3.0");
    final Dependency hexGrandchildDependency = buildDependency("hex_grandchild_dependency", "4.0.0");
    final Dependency gitInnerChildDependency = buildDependency("git_inner_child_dependency", "0.5.0");
    final Dependency gitGrandchildDependency = buildDependency("git_grandchild_dependency", "6.0.0");
    final Dependency gitOuterParentDependency = buildDependency("git_outer_parent_dependency", "0.0.7");
    final Dependency gitOuterChildDependency = buildDependency("git_outer_child_dependency", "0.8.0");
    expectedGraph.addChildrenToRoot(gitInnerParentDependency, gitOuterParentDependency);
    expectedGraph.addChildWithParent(hexInnerChildDependency, gitInnerParentDependency);
    expectedGraph.addChildWithParents(hexGrandchildDependency, hexInnerChildDependency);
    expectedGraph.addChildWithParent(gitInnerChildDependency, gitInnerParentDependency);
    expectedGraph.addChildWithParents(gitGrandchildDependency, gitInnerChildDependency);
    expectedGraph.addChildWithParents(gitOuterChildDependency, gitOuterParentDependency);
    final DetectCodeLocation codeLocation = build("/hex/dependencyTree.txt");
    final DependencyGraph actualGraph = codeLocation.getDependencyGraph();
    assertGraph(expectedGraph, actualGraph);
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Test(org.junit.Test)

Example 9 with MutableMapDependencyGraph

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

the class NpmCliParser method convertNpmJsonFileToCodeLocation.

NpmParseResult convertNpmJsonFileToCodeLocation(final String sourcePath, final String npmLsOutput) {
    final JsonObject npmJson = new JsonParser().parse(npmLsOutput).getAsJsonObject();
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME);
    final JsonElement projectVersionElement = npmJson.getAsJsonPrimitive(JSON_VERSION);
    String projectName = null;
    String projectVersion = null;
    if (projectNameElement != null) {
        projectName = projectNameElement.getAsString();
    }
    if (projectVersionElement != null) {
        projectVersion = projectVersionElement.getAsString();
    }
    populateChildren(graph, null, npmJson.getAsJsonObject(JSON_DEPENDENCIES), true);
    final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPM, projectName, projectVersion);
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NPM, sourcePath, externalId, graph).build();
    return new NpmParseResult(projectName, projectVersion, codeLocation);
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) JsonElement(com.google.gson.JsonElement) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) JsonObject(com.google.gson.JsonObject) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) JsonParser(com.google.gson.JsonParser)

Example 10 with MutableMapDependencyGraph

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

the class NpmLockfileParser method parse.

public NpmParseResult parse(final String sourcePath, final Optional<String> packageJsonText, final String lockFileText, final boolean includeDevDependencies) {
    final MutableDependencyGraph dependencyGraph = new MutableMapDependencyGraph();
    logger.info("Parsing lock file text: ");
    logger.debug(lockFileText);
    Optional<PackageJson> packageJson = Optional.empty();
    if (packageJsonText.isPresent()) {
        logger.debug(packageJsonText.get());
        packageJson = Optional.of(gson.fromJson(packageJsonText.get(), PackageJson.class));
    }
    final PackageLock packageLock = gson.fromJson(lockFileText, PackageLock.class);
    logger.debug(lockFileText);
    logger.info("Processing project.");
    if (packageLock.dependencies != null) {
        logger.info(String.format("Found %d dependencies.", packageLock.dependencies.size()));
        // Convert to our custom format
        NpmDependencyConverter dependencyConverter = new NpmDependencyConverter(externalIdFactory);
        NpmDependency rootDependency = dependencyConverter.convertLockFile(packageLock, packageJson);
        traverse(rootDependency, dependencyGraph, true, includeDevDependencies);
    } else {
        logger.info("Lock file did not have a 'dependencies' section.");
    }
    logger.info("Finished processing.");
    final ExternalId projectId = externalIdFactory.createNameVersionExternalId(Forge.NPM, packageLock.name, packageLock.version);
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NPM, sourcePath, projectId, dependencyGraph).build();
    return new NpmParseResult(packageLock.name, packageLock.version, codeLocation);
}
Also used : MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) PackageLock(com.blackducksoftware.integration.hub.detect.detector.npm.model.PackageLock) NpmDependency(com.blackducksoftware.integration.hub.detect.detector.npm.model.NpmDependency) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) MutableMapDependencyGraph(com.synopsys.integration.bdio.graph.MutableMapDependencyGraph) PackageJson(com.blackducksoftware.integration.hub.detect.detector.npm.model.PackageJson)

Aggregations

MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)21 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)17 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)12 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)11 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)8 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)5 DependencyHistory (com.blackducksoftware.integration.hub.detect.util.DependencyHistory)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 DependencyGraphCombiner (com.synopsys.integration.bdio.graph.DependencyGraphCombiner)2 Forge (com.synopsys.integration.bdio.model.Forge)2 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 NameVersion (com.synopsys.integration.util.NameVersion)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2