Search in sources :

Example 1 with GoListAllData

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

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

the class GoListParserTest method goListAllHappyPathTest.

@Test
void goListAllHappyPathTest() throws DetectableException {
    List<String> goListAllOutput = Arrays.asList("{\n", "\t\"Path\": \"github.com/synopsys/moduleA\",\n", "\t\"Version\": \"v1.0.0\"\n", "}\n", "{\n", "\t\"Path\": \"github.com/synopsys/moduleB\",\n", "\t\"Version\": \"v2.0.0\",\n", "\t\"Replace\": {\n", "\t\t\"Path\": \"github.com/synopsys/moduleB\",\n", "\t\t\"Version\": \"v3.0.0\"\n", "\t}\n", "}");
    List<GoListAllData> goListModules = goListParser.parseGoListAllJsonOutput(goListAllOutput);
    assertEquals(2, goListModules.size());
    GoListAllData moduleA = goListModules.get(0);
    assertEquals("github.com/synopsys/moduleA", moduleA.getPath());
    assertEquals("v1.0.0", moduleA.getVersion());
    assertNull(moduleA.getReplace());
    GoListAllData moduleB = goListModules.get(1);
    assertEquals("github.com/synopsys/moduleB", moduleB.getPath());
    assertEquals("v2.0.0", moduleB.getVersion());
    ReplaceData replaceData = moduleB.getReplace();
    assertEquals("github.com/synopsys/moduleB", replaceData.getPath());
    assertEquals("v3.0.0", replaceData.getVersion());
}
Also used : ReplaceData(com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData) Test(org.junit.jupiter.api.Test)

Example 3 with GoListAllData

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

the class GoModDependencyManagerTest method createManagerWithModuleLoadedWith.

private GoModDependencyManager createManagerWithModuleLoadedWith(String modulePath, @Nullable String moduleVersion) {
    GoListAllData module = new GoListAllData();
    module.setPath(modulePath);
    module.setVersion(moduleVersion);
    return new GoModDependencyManager(Collections.singletonList(module), new ExternalIdFactory());
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)

Example 4 with GoListAllData

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

the class GoModDependencyManager method convertModulesToDependencies.

private Map<String, Dependency> convertModulesToDependencies(List<GoListAllData> allModules) {
    Map<String, Dependency> dependencies = new HashMap<>();
    for (GoListAllData module : allModules) {
        String name = Optional.ofNullable(module.getReplace()).map(ReplaceData::getPath).orElse(module.getPath());
        String version = Optional.ofNullable(module.getReplace()).map(ReplaceData::getVersion).orElse(module.getVersion());
        if (version != null) {
            version = handleGitHash(version);
            version = removeIncompatibleSuffix(version);
        }
        dependencies.put(module.getPath(), convertToDependency(name, version));
    }
    return dependencies;
}
Also used : HashMap(java.util.HashMap) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)

Example 5 with GoListAllData

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

the class GoModDependencyManagerTest method moduleReplacementTest.

@Test
void moduleReplacementTest() {
    String resolvedModulePath = "example.io/module/resolved";
    String replacedModulePath = "example.io/module/replaced";
    GoListAllData resolvedModule = new GoListAllData();
    resolvedModule.setPath(resolvedModulePath);
    resolvedModule.setVersion("1.0.0");
    GoListAllData replacedModule = new GoListAllData();
    replacedModule.setPath(replacedModulePath);
    replacedModule.setVersion("2.0.0");
    ReplaceData replaceData = new ReplaceData();
    replaceData.setPath(resolvedModulePath);
    replaceData.setVersion("2.3.4");
    replacedModule.setReplace(replaceData);
    GoModDependencyManager dependencyManager = new GoModDependencyManager(Arrays.asList(resolvedModule, replacedModule), new ExternalIdFactory());
    Dependency resolvedDependency = dependencyManager.getDependencyForModule(resolvedModule.getPath());
    assertEquals(resolvedModule.getPath(), resolvedDependency.getName());
    assertEquals(resolvedModule.getVersion(), resolvedDependency.getVersion());
    Dependency replacedDependency = dependencyManager.getDependencyForModule(replacedModulePath);
    assertEquals(replaceData.getPath(), replacedDependency.getName(), "The dependency name (module path) should have been replaced.");
    assertEquals(replaceData.getVersion(), replacedDependency.getVersion(), "The version should have been replaced.");
}
Also used : ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ReplaceData(com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) GoListAllData(com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData) Test(org.junit.jupiter.api.Test)

Aggregations

GoListAllData (com.synopsys.integration.detectable.detectables.go.gomod.model.GoListAllData)5 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)3 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)2 ReplaceData (com.synopsys.integration.detectable.detectables.go.gomod.model.ReplaceData)2 Test (org.junit.jupiter.api.Test)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)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 GoGraphRelationship (com.synopsys.integration.detectable.detectables.go.gomod.model.GoGraphRelationship)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