Search in sources :

Example 41 with BasicDependencyGraph

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

the class GoGradleLockParser method parse.

public DependencyGraph parse(File goGradleLockFile) throws IOException, IntegrationException {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    YAMLMapper mapper = new YAMLMapper();
    JsonNode rootNode = mapper.readTree(goGradleLockFile);
    JsonNode buildNode = rootNode.findPath("build");
    if (buildNode == null) {
        throw new IntegrationException(String.format("Failed to find build node in %s", GoGradleDetectable.GO_GRADLE_LOCK));
    }
    for (JsonNode dependencyNode : buildNode) {
        Optional<String> name = Optional.ofNullable(dependencyNode.get("name")).map(JsonNode::textValue);
        Optional<String> commit = Optional.ofNullable(dependencyNode.get("commit")).map(JsonNode::textValue);
        if (name.isPresent() && commit.isPresent()) {
            String dependencyName = name.get();
            if (dependencyName.startsWith("golang.org/x/")) {
                dependencyName = dependencyName.replace("golang.org/x/", "");
            }
            ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.GOLANG, dependencyName, commit.get());
            Dependency dependency = new Dependency(externalId);
            dependencyGraph.addChildToRoot(dependency);
        }
    }
    return dependencyGraph;
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) JsonNode(com.fasterxml.jackson.databind.JsonNode) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 42 with BasicDependencyGraph

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

the class ClangPackageDetailsTransformer method toCodeLocation.

public CodeLocation toCodeLocation(List<Forge> dependencyForges, Set<PackageDetails> packages) {
    List<Dependency> dependencies = packages.parallelStream().flatMap(pkg -> toDependency(dependencyForges, pkg).stream()).collect(Collectors.toList());
    logger.trace("Generated : {} dependencies.", dependencies.size());
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    dependencyGraph.addChildrenToRoot(dependencies);
    return new CodeLocation(dependencyGraph);
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) PackageDetails(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetails) 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 43 with BasicDependencyGraph

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

the class FinalStepTransformJsonProtoHaskellCabalLibrariesToHackageTest method testStep.

@Test
public void testStep() throws IntegrationException, IOException {
    File jsonProtoFile = new File("src/test/resources/detectables/functional/bazel/jsonProtoForHaskellCabalLibraries.txt");
    String jsonProtoHaskellCabalLibrary = FileUtils.readFileToString(jsonProtoFile, StandardCharsets.UTF_8);
    FinalStepTransformJsonProtoHaskellCabalLibrariesToHackage step = new FinalStepTransformJsonProtoHaskellCabalLibrariesToHackage(new HaskellCabalLibraryJsonProtoParser(new Gson()), new ExternalIdFactory());
    List<String> input = new ArrayList<>(1);
    input.add(jsonProtoHaskellCabalLibrary);
    List<Dependency> dependencies = step.finish(input);
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    for (Dependency dependency : dependencies) {
        dependencyGraph.addChildToRoot(dependency);
    }
    Forge hackageForge = new Forge("/", "hackage");
    GraphAssert graphAssert = new GraphAssert(hackageForge, dependencyGraph);
    graphAssert.hasRootSize(1);
    ExternalId expectedExternalId = new ExternalIdFactory().createNameVersionExternalId(hackageForge, "colour", "2.3.5");
    graphAssert.hasRootDependency(expectedExternalId);
}
Also used : GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) HaskellCabalLibraryJsonProtoParser(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.HaskellCabalLibraryJsonProtoParser) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) FinalStepTransformJsonProtoHaskellCabalLibrariesToHackage(com.synopsys.integration.detectable.detectables.bazel.pipeline.step.FinalStepTransformJsonProtoHaskellCabalLibrariesToHackage) File(java.io.File) Test(org.junit.jupiter.api.Test)

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