Search in sources :

Example 1 with GoListModule

use of com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule in project synopsys-detect by blackducksoftware.

the class GoModGraphGenerator method generateGraph.

public CodeLocation generateGraph(GoListModule projectModule, GoRelationshipManager goRelationshipManager, GoModDependencyManager goModDependencyManager) {
    DependencyGraph graph = new BasicDependencyGraph();
    String moduleName = projectModule.getPath();
    if (goRelationshipManager.hasRelationshipsFor(moduleName)) {
        goRelationshipManager.getRelationshipsFor(moduleName).stream().map(relationship -> relationship.getChild().getName()).forEach(childName -> addModuleToGraph(childName, null, graph, goRelationshipManager, goModDependencyManager));
    }
    return new CodeLocation(graph, externalIdFactory.createNameVersionExternalId(Forge.GOLANG, projectModule.getPath(), projectModule.getVersion()));
}
Also used : DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) LoggerFactory(org.slf4j.LoggerFactory) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Set(java.util.Set) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 2 with GoListModule

use of com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule in project synopsys-detect by blackducksoftware.

the class GoModCliExtractor method extract.

public Extraction extract(File directory, ExecutableTarget goExe) throws ExecutableFailedException, JsonSyntaxException, DetectableException {
    List<GoListModule> goListModules = listModules(directory, goExe);
    List<GoListAllData> goListAllModules = listAllModules(directory, goExe);
    List<GoGraphRelationship> goGraphRelationships = listGraphRelationships(directory, goExe);
    Set<String> excludedModules = listExcludedModules(directory, goExe);
    GoRelationshipManager goRelationshipManager = new GoRelationshipManager(goGraphRelationships, excludedModules);
    GoModDependencyManager goModDependencyManager = new GoModDependencyManager(goListAllModules, externalIdFactory);
    List<CodeLocation> codeLocations = goListModules.stream().map(goListModule -> goModGraphGenerator.generateGraph(goListModule, goRelationshipManager, goModDependencyManager)).collect(Collectors.toList());
    // No project info - hoping git can help with that.
    return new Extraction.Builder().success(codeLocations).build();
}
Also used : GoListParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoListParser) JsonSyntaxException(com.google.gson.JsonSyntaxException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) Set(java.util.Set) GoModGraphGenerator(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModGraphGenerator) Collectors(java.util.stream.Collectors) GoVersionParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoVersionParser) GoRelationshipManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoRelationshipManager) File(java.io.File) GoModDependencyManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModDependencyManager) List(java.util.List) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) GoGraphParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoGraphParser) Collections(java.util.Collections) GoModWhyParser(com.synopsys.integration.detectable.detectables.go.gomod.parse.GoModWhyParser) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) GoRelationshipManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoRelationshipManager) GoModDependencyManager(com.synopsys.integration.detectable.detectables.go.gomod.process.GoModDependencyManager) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)

Example 3 with GoListModule

use of com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule in project synopsys-detect by blackducksoftware.

the class GoListParserTest method goListHappyPathTest.

@Test
void goListHappyPathTest() throws DetectableException {
    List<String> goListOutput = Arrays.asList("{\n", "\t\"Path\": \"github.com/synopsys/moduleA\"\n", "}\n", "{\n", "\t\"Path\": \"github.com/synopsys/moduleB\",\n", "\t\"Version\": \"1.0.0\"\n", "}\n");
    List<GoListModule> goListModules = goListParser.parseGoListModuleJsonOutput(goListOutput);
    assertEquals(2, goListModules.size());
    GoListModule moduleA = goListModules.get(0);
    assertEquals("github.com/synopsys/moduleA", moduleA.getPath());
    assertNull(moduleA.getVersion());
    GoListModule moduleB = goListModules.get(1);
    assertEquals("github.com/synopsys/moduleB", moduleB.getPath());
    assertEquals("1.0.0", moduleB.getVersion());
}
Also used : GoListModule(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule) Test(org.junit.jupiter.api.Test)

Aggregations

GoListModule (com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule)3 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)2 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 GoGraphRelationship (com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship)2 List (java.util.List)2 Set (java.util.Set)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 Forge (com.synopsys.integration.bdio.model.Forge)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)1 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)1 GoListAllData (com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)1 GoGraphParser (com.synopsys.integration.detectable.detectables.go.gomod.parse.GoGraphParser)1 GoListParser (com.synopsys.integration.detectable.detectables.go.gomod.parse.GoListParser)1 GoModWhyParser (com.synopsys.integration.detectable.detectables.go.gomod.parse.GoModWhyParser)1 GoVersionParser (com.synopsys.integration.detectable.detectables.go.gomod.parse.GoVersionParser)1 GoModDependencyManager (com.synopsys.integration.detectable.detectables.go.gomod.process.GoModDependencyManager)1