Search in sources :

Example 1 with GoGraphRelationship

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

the class GoModGraphGenerator method addModuleToGraph.

private void addModuleToGraph(String moduleName, @Nullable Dependency parent, MutableDependencyGraph graph, GoRelationshipManager goRelationshipManager, GoModDependencyManager goModDependencyManager) {
    if (goRelationshipManager.isNotUsedByMainModule(moduleName)) {
        logger.debug("Excluding module '{}' because it is not used by the main module.", moduleName);
        return;
    }
    Dependency dependency = goModDependencyManager.getDependencyForModule(moduleName);
    if (parent != null) {
        graph.addChildWithParent(dependency, parent);
    } else {
        graph.addChildToRoot(dependency);
    }
    if (!fullyGraphedModules.contains(moduleName) && goRelationshipManager.hasRelationshipsFor(moduleName)) {
        fullyGraphedModules.add(moduleName);
        List<GoGraphRelationship> projectRelationships = goRelationshipManager.getRelationshipsFor(moduleName);
        for (GoGraphRelationship projectRelationship : projectRelationships) {
            addModuleToGraph(projectRelationship.getChild().getName(), dependency, graph, goRelationshipManager, goModDependencyManager);
        }
    }
}
Also used : GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 2 with GoGraphRelationship

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

the class GoModGraphGenerator method addModuleToGraph.

private void addModuleToGraph(String moduleName, @Nullable Dependency parent, DependencyGraph graph, GoRelationshipManager goRelationshipManager, GoModDependencyManager goModDependencyManager) {
    if (goRelationshipManager.isNotUsedByMainModule(moduleName)) {
        logger.debug("Excluding module '{}' because it is not used by the main module.", moduleName);
        return;
    }
    Dependency dependency = goModDependencyManager.getDependencyForModule(moduleName);
    if (parent != null) {
        graph.addChildWithParent(dependency, parent);
    } else {
        graph.addChildToRoot(dependency);
    }
    if (!fullyGraphedModules.contains(moduleName) && goRelationshipManager.hasRelationshipsFor(moduleName)) {
        fullyGraphedModules.add(moduleName);
        List<GoGraphRelationship> projectRelationships = goRelationshipManager.getRelationshipsFor(moduleName);
        for (GoGraphRelationship projectRelationship : projectRelationships) {
            addModuleToGraph(projectRelationship.getChild().getName(), dependency, graph, goRelationshipManager, goModDependencyManager);
        }
    }
}
Also used : GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 3 with GoGraphRelationship

use of com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship 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 4 with GoGraphRelationship

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

the class GoGraphParser method parseLine.

private Optional<GoGraphRelationship> parseLine(String line) {
    String[] parts = line.split(" ");
    if (parts.length != 2) {
        logger.warn("Unknown graph line format: {}", line);
        return Optional.empty();
    }
    NameVersion parent = extractNameVersion(parts[0]);
    NameVersion child = extractNameVersion(parts[1]);
    return Optional.of(new GoGraphRelationship(parent, child));
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship)

Example 5 with GoGraphRelationship

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

the class GoRelationshipManagerTest method init.

@BeforeAll
static void init() {
    List<GoGraphRelationship> goGraphRelationships = Arrays.asList(new GoGraphRelationship(parent, child), new GoGraphRelationship(parent, child2), new GoGraphRelationship(child, grandchild));
    Set<String> excludedModules = new HashSet<>();
    excludedModules.add(child2.getName());
    goRelationshipManager = new GoRelationshipManager(goGraphRelationships, excludedModules);
}
Also used : GoGraphRelationship(com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship) HashSet(java.util.HashSet) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

GoGraphRelationship (com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship)7 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)2 Test (org.junit.jupiter.api.Test)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)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 GoListModule (com.synopsys.integration.detectable.detectables.go.gomod.model.GoListModule)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 GoModGraphGenerator (com.synopsys.integration.detectable.detectables.go.gomod.process.GoModGraphGenerator)1 GoRelationshipManager (com.synopsys.integration.detectable.detectables.go.gomod.process.GoRelationshipManager)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 NameVersion (com.synopsys.integration.util.NameVersion)1