use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class ConanCodeLocationGenerator method generateCodeLocationFromNodeMap.
@NotNull
public ConanDetectableResult generateCodeLocationFromNodeMap(ExternalIdFactory externalIdFactory, Map<String, ConanNode<String>> nodes) throws DetectableException {
logger.debug("Generating code location from {} dependencies", nodes.keySet().size());
Optional<ConanNode<String>> rootNode = getRoot(nodes.values());
if (!rootNode.isPresent()) {
throw new DetectableException("No root node found");
}
ConanGraphNode rootGraphNode = new ConanGraphNode(rootNode.get());
populateGraphUnderNode(rootGraphNode, nodes);
DependencyGraph dependencyGraph = new BasicDependencyGraph();
CodeLocation codeLocation = generateCodeLocationFromConanGraph(externalIdFactory, dependencyGraph, rootGraphNode);
return new ConanDetectableResult(rootGraphNode.getConanNode().getName().orElse(null), rootGraphNode.getConanNode().getVersion().orElse(null), codeLocation);
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class GemspecParser method parse.
public DependencyGraph parse(InputStream inputStream) throws IOException {
DependencyGraph dependencyGraph = new BasicDependencyGraph();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
if (!gemspecLineParser.shouldParseLine(line)) {
continue;
}
Optional<GemspecDependency> gemspecDependencyOptional = gemspecLineParser.parseLine(line);
if (!gemspecDependencyOptional.isPresent()) {
continue;
}
GemspecDependency gemspecDependency = gemspecDependencyOptional.get();
if (dependencyTypeFilter.shouldExclude(com.synopsys.integration.detectable.detectables.rubygems.GemspecDependencyType.RUNTIME) && gemspecDependency.getGemspecDependencyType() == GemspecDependencyType.RUNTIME) {
logger.debug(String.format("Excluding component '%s' from graph because it is a runtime dependency", gemspecDependency.getName()));
continue;
} else if (dependencyTypeFilter.shouldExclude(com.synopsys.integration.detectable.detectables.rubygems.GemspecDependencyType.DEV) && gemspecDependency.getGemspecDependencyType() == GemspecDependencyType.DEVELOPMENT) {
logger.debug(String.format("Excluding component '%s' from graph because it is a development dependency", gemspecDependency.getName()));
continue;
}
String name = gemspecDependency.getName();
String version = gemspecDependency.getVersion().orElse("No version");
Dependency dependency = Dependency.FACTORY.createNameVersionDependency(Forge.RUBYGEMS, name, version);
dependencyGraph.addChildrenToRoot(dependency);
}
}
return dependencyGraph;
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class ProjectInspectorParser method codeLocationFromModule.
public CodeLocation codeLocationFromModule(ProjectInspectorModule module) {
Map<String, Dependency> lookup = new HashMap<>();
// build the map of all external ids
module.dependencies.forEach(dependency -> lookup.computeIfAbsent(dependency.id, (missingId) -> convertProjectInspectorDependency(dependency)));
// and add them to the graph
DependencyGraph mutableDependencyGraph = new BasicDependencyGraph();
module.dependencies.forEach(moduleDependency -> {
Dependency dependency = lookup.get(moduleDependency.id);
moduleDependency.includedBy.forEach(parent -> {
if ("DIRECT".equals(parent)) {
mutableDependencyGraph.addChildToRoot(dependency);
} else if (lookup.containsKey(parent)) {
mutableDependencyGraph.addChildWithParent(dependency, lookup.get(parent));
} else {
// Theoretically should not happen according to PI devs. -jp
throw new RuntimeException("An error occurred reading the project inspector output." + " An unknown parent dependency was encountered '" + parent + "' while including dependency '" + moduleDependency.name + "'.");
}
});
});
return new CodeLocation(mutableDependencyGraph, new File(module.moduleFile));
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class PoetryLockParser method parseDependencies.
private DependencyGraph parseDependencies(TomlArray lockPackages) {
DependencyGraph graph = new BasicDependencyGraph();
Set<String> rootPackages = determineRootPackages(lockPackages);
for (String rootPackage : rootPackages) {
graph.addChildToRoot(packageMap.get(rootPackage));
}
for (int i = 0; i < lockPackages.size(); i++) {
TomlTable lockPackage = lockPackages.getTable(i);
List<String> dependencies = extractFromDependencyList(lockPackage.getTable(DEPENDENCIES_KEY));
if (dependencies.isEmpty()) {
continue;
}
for (String dependency : dependencies) {
Dependency child = packageMap.get(dependency);
Dependency parent = packageMap.get(lockPackage.getString(NAME_KEY));
if (child != null && parent != null) {
graph.addChildWithParent(child, parent);
}
}
}
return graph;
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class SbtDependencyResolver method resolveReport.
public SbtDependencyModule resolveReport(SbtReport report) {
ExternalId rootId = externalIdFactory.createMavenExternalId(report.getOrganisation(), report.getModule(), report.getRevision());
logger.debug("Created external id: {}", rootId);
BasicDependencyGraph graph = new BasicDependencyGraph();
logger.debug("Dependencies found: " + report.getDependencies().size());
report.getDependencies().forEach(module -> {
logger.debug("Revisions found: " + module.getRevisions().size());
module.getRevisions().forEach(revision -> {
logger.debug("Callers found: " + revision.getCallers().size());
ExternalId id = externalIdFactory.createMavenExternalId(module.getOrganisation(), module.getName(), revision.getName());
Dependency child = new Dependency(module.getName(), revision.getName(), id);
revision.getCallers().forEach(caller -> {
ExternalId parentId = externalIdFactory.createMavenExternalId(caller.getOrganisation(), caller.getName(), caller.getRevision());
Dependency parent = new Dependency(caller.getName(), caller.getRevision(), parentId);
logger.debug("Caller id: " + parentId.toString());
if (rootId.equals(parentId)) {
graph.addChildToRoot(child);
} else {
graph.addParentWithChild(parent, child);
}
});
});
});
SbtDependencyModule module = new SbtDependencyModule();
module.setName(report.getModule());
module.setVersion(report.getRevision());
module.setOrg(report.getOrganisation());
module.setGraph(graph);
module.setConfiguration(report.getConfiguration());
return module;
}
Aggregations