use of com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata in project hub-detect by blackducksoftware.
the class CocoapodsPackager method extractDependencyGraph.
public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
YAMLMapper mapper = new YAMLMapper();
PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
NameVersionNode root = new NameVersionNode();
root.setName(String.format("detectRootNode - %s", UUID.randomUUID()));
final SubcomponentNodeBuilder builder = new SubcomponentNodeBuilder(root);
for (Pod pod : podfileLock.getPods()) {
buildNameVersionNode(builder, pod);
}
;
for (Pod dependency : podfileLock.getDependencies()) {
NameVersionNode child = new NameVersionNode();
child.setName(cleanPodName(dependency.getName()));
builder.addChildNodeToParent(child, root);
}
;
if (null != podfileLock.getExternalSources() && !podfileLock.getExternalSources().getSources().isEmpty()) {
for (PodSource podSource : podfileLock.getExternalSources().getSources()) {
NodeMetadata nodeMetadata = createMetadata(builder, podSource.getName());
if (null != podSource.getGit() && podSource.getGit().contains("github")) {
// Change the forge to GitHub when there is better KB support
nodeMetadata.setForge(Forge.COCOAPODS);
} else if (null != podSource.getPath() && podSource.getPath().contains("node_modules")) {
nodeMetadata.setForge(Forge.NPM);
}
}
}
MutableDependencyGraph graph = new MutableMapDependencyGraph();
for (NameVersionNode nameVersionNode : builder.build().getChildren()) {
Dependency childDependency = nameVersionNodeTransformer.addNameVersionNodeToDependencyGraph(graph, Forge.COCOAPODS, nameVersionNode);
graph.addChildToRoot(childDependency);
}
return graph;
}
Aggregations