Search in sources :

Example 6 with BasicDependencyGraph

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

the class MavenParseExtractor method extract.

public Extraction extract(File pomXmlFile, MavenParseOptions mavenParseOptions) {
    try (InputStream pomXmlInputStream = new FileInputStream(pomXmlFile)) {
        // we have to create a new handler or the state of all handlers would be shared.
        // we could create a handler factory or some other indirection so it could be injected but for now we make a new one.
        PomDependenciesHandler pomDependenciesHandler = new PomDependenciesHandler(mavenParseOptions.isIncludePlugins());
        saxParser.parse(pomXmlInputStream, pomDependenciesHandler);
        List<Dependency> dependencies = pomDependenciesHandler.getDependencies();
        DependencyGraph dependencyGraph = new BasicDependencyGraph();
        dependencyGraph.addChildrenToRoot(dependencies);
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        return Extraction.success(codeLocation);
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) PomDependenciesHandler(com.synopsys.integration.detectable.detectables.maven.parsing.parse.PomDependenciesHandler) FileInputStream(java.io.FileInputStream)

Example 7 with BasicDependencyGraph

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

the class NpmLockfileGraphTransformer method transform.

public DependencyGraph transform(PackageLock packageLock, NpmProject project, List<NameVersion> externalDependencies) {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    logger.debug("Processing project.");
    if (packageLock.dependencies != null) {
        logger.debug(String.format("Found %d dependencies in the lockfile.", packageLock.dependencies.size()));
        // First we will recreate the graph from the resolved npm dependencies
        for (NpmDependency resolved : project.getResolvedDependencies()) {
            transformTreeToGraph(resolved, project, dependencyGraph, externalDependencies);
        }
        // Then we will add relationships between the project (root) and the graph
        boolean atLeastOneRequired = !project.getDeclaredDependencies().isEmpty() || !project.getDeclaredDevDependencies().isEmpty() || !project.getDeclaredPeerDependencies().isEmpty();
        if (atLeastOneRequired) {
            addRootDependencies(project.getResolvedDependencies(), project.getDeclaredDependencies(), dependencyGraph, externalDependencies);
            if (npmDependencyTypeFilter.shouldInclude(NpmDependencyType.DEV)) {
                addRootDependencies(project.getResolvedDependencies(), project.getDeclaredDevDependencies(), dependencyGraph, externalDependencies);
            }
            if (npmDependencyTypeFilter.shouldInclude(NpmDependencyType.PEER)) {
                addRootDependencies(project.getResolvedDependencies(), project.getDeclaredPeerDependencies(), dependencyGraph, externalDependencies);
            }
        } else {
            project.getResolvedDependencies().stream().filter(this::shouldIncludeDependency).forEach(dependencyGraph::addChildToRoot);
        }
        logger.debug(String.format("Found %d root dependencies.", dependencyGraph.getRootDependencies().size()));
    } else {
        logger.debug("Lock file did not have a 'dependencies' section.");
    }
    return dependencyGraph;
}
Also used : NpmDependency(com.synopsys.integration.detectable.detectables.npm.lockfile.model.NpmDependency) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 8 with BasicDependencyGraph

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

the class PackageJsonExtractor method extract.

public Extraction extract(PackageJson packageJson) {
    List<Dependency> dependencies = transformDependencies(packageJson.dependencies);
    npmDependencyTypeFilter.ifShouldInclude(NpmDependencyType.DEV, transformDependencies(packageJson.devDependencies), dependencies::addAll);
    npmDependencyTypeFilter.ifShouldInclude(NpmDependencyType.PEER, transformDependencies(packageJson.peerDependencies), dependencies::addAll);
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    dependencyGraph.addChildrenToRoot(dependencies);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph);
    String projectName = StringUtils.stripToNull(packageJson.name);
    String projectVersion = StringUtils.stripToNull(packageJson.version);
    return new Extraction.Builder().success(codeLocation).projectName(projectName).projectVersion(projectVersion).build();
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 9 with BasicDependencyGraph

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

the class GradleReportTransformer method transform.

public CodeLocation transform(GradleReport gradleReport) {
    DependencyGraph graph = new BasicDependencyGraph();
    for (GradleConfiguration configuration : gradleReport.getConfigurations()) {
        if (configuration.isResolved() || configurationTypeFilter.shouldInclude(GradleConfigurationType.UNRESOLVED)) {
            logger.trace("Adding configuration to the graph: {}", configuration.getName());
            addConfigurationToGraph(graph, configuration);
        } else {
            logger.trace("Excluding unresolved configuration from the graph: {}", configuration.getName());
        }
    }
    ExternalId projectId = ExternalId.FACTORY.createMavenExternalId(gradleReport.getProjectGroup(), gradleReport.getProjectName(), gradleReport.getProjectVersionName());
    if (StringUtils.isNotBlank(gradleReport.getProjectSourcePath())) {
        return new CodeLocation(graph, projectId, new File(gradleReport.getProjectSourcePath()));
    } else {
        return new CodeLocation(graph, projectId);
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) GradleConfiguration(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleConfiguration) File(java.io.File)

Example 10 with BasicDependencyGraph

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

the class NpmCliParser method convertNpmJsonFileToCodeLocation.

public NpmPackagerResult convertNpmJsonFileToCodeLocation(String npmLsOutput, PackageJson packageJson) {
    JsonObject npmJson = JsonParser.parseString(npmLsOutput).getAsJsonObject();
    DependencyGraph graph = new BasicDependencyGraph();
    JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME);
    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, packageJson);
    ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, projectName, projectVersion);
    CodeLocation codeLocation = new CodeLocation(graph, externalId);
    return new NpmPackagerResult(projectName, projectVersion, codeLocation);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) JsonElement(com.google.gson.JsonElement) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) JsonObject(com.google.gson.JsonObject) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) NpmPackagerResult(com.synopsys.integration.detectable.detectables.npm.lockfile.result.NpmPackagerResult)

Aggregations

BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)43 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)38 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)26 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)16 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)10 List (java.util.List)7 Forge (com.synopsys.integration.bdio.model.Forge)6 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)5 ArrayList (java.util.ArrayList)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 File (java.io.File)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Gson (com.google.gson.Gson)3 NotNull (org.jetbrains.annotations.NotNull)3 GraphEdge (com.paypal.digraph.parser.GraphEdge)2 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)2 DependencyHistory (com.synopsys.integration.detectable.detectable.util.DependencyHistory)2 Extraction (com.synopsys.integration.detectable.extraction.Extraction)2