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();
}
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());
}
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());
}
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;
}
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.");
}
Aggregations