use of com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode in project hub-detect by blackducksoftware.
the class CpanPackager method makeDependencyGraph.
public DependencyGraph makeDependencyGraph(List<String> cpanListText, List<String> directDependenciesText) {
Map<String, NameVersionNode> allModules = cpanListParser.parse(cpanListText);
List<String> directModuleNames = getDirectModuleNames(directDependenciesText);
MutableDependencyGraph graph = new MutableMapDependencyGraph();
for (String moduleName : directModuleNames) {
NameVersionNode nameVersionNode = allModules.get(moduleName);
if (null != nameVersionNode) {
nameVersionNode.setName(nameVersionNode.getName().replace("::", "-"));
Dependency module = nameVersionNodeTransformer.addNameVersionNodeToDependencyGraph(graph, Forge.CPAN, nameVersionNode);
graph.addChildToRoot(module);
} else {
logger.warn(String.format("Could node find resolved version for module: %s", moduleName));
}
}
return graph;
}
use of com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode in project hub-detect by blackducksoftware.
the class LinkedNameVersionNodeBuilder method build.
@Override
public NameVersionNode build() {
final Stack<String> cyclicalStack = new Stack<>();
final Set<String> cyclicalNames = new HashSet<>();
final NameVersionNode resolved = resolveLinks(cyclicalNames, cyclicalStack, root);
for (final String cyclicalName : cyclicalNames) {
logger.debug(String.format("Cyclical depdency detected: %s", cyclicalName));
}
return resolved;
}
use of com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode in project hub-detect by blackducksoftware.
the class CocoapodsPackager method buildNameVersionNode.
private NameVersionNode buildNameVersionNode(SubcomponentNodeBuilder builder, Pod pod) {
NameVersionNode nameVersionNode = new NameVersionNode();
nameVersionNode.setName(cleanPodName(pod.getName()));
pod.setCleanName(nameVersionNode.getName());
String[] segments = pod.getName().split(" ");
if (segments.length > 1) {
String version = segments[1];
version = version.replace("(", "").replace(")", "").trim();
if (!isVersionFuzzy(version)) {
nameVersionNode.setVersion(version);
}
}
for (String dependency : pod.getDependencies()) {
builder.addChildNodeToParent(buildNameVersionNode(builder, new Pod(dependency)), nameVersionNode);
}
if (pod.getDependencies().isEmpty()) {
builder.addToCache(nameVersionNode);
}
if (nameVersionNode.getName().contains("/")) {
String superNodeName = nameVersionNode.getName().split("/")[0].trim();
NameVersionNode superNode = new NameVersionNode();
superNode.setName(superNodeName);
superNode = builder.addToCache(superNode);
SubcomponentMetadata superNodeMetadata = createMetadata(builder, superNode.getName());
superNodeMetadata.getSubcomponents().add(nameVersionNode);
SubcomponentMetadata subcomponentMetadata = createMetadata(builder, nameVersionNode.getName());
subcomponentMetadata.setLinkNode(superNode);
builder.getSuperComponents().add(superNode);
}
return nameVersionNode;
}
use of com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode 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;
}
use of com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode in project hub-detect by blackducksoftware.
the class CpanListParser method parse.
public Map<String, NameVersionNode> parse(List<String> listText) {
Map<String, NameVersionNode> moduleMap = new HashMap<>();
for (String line : listText) {
if (StringUtils.isBlank(line)) {
continue;
}
if (StringUtils.countMatches(line, "\t") != 1 || line.trim().contains(" ")) {
continue;
}
try {
String[] module = line.trim().split("\t");
NameVersionNode nameVersionNode = new NameVersionNode();
nameVersionNode.setName(module[0].trim());
nameVersionNode.setVersion(module[1].trim());
moduleMap.put(nameVersionNode.getName(), nameVersionNode);
} catch (IndexOutOfBoundsException indexOutOfBoundsException) {
logger.debug(String.format("Failed to handle the following line:%s", line));
}
}
return moduleMap;
}
Aggregations