use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.
the class CondaListParser method parse.
public DependencyGraph parse(String listJsonText, String infoJsonText) {
final Type listType = new TypeToken<ArrayList<CondaListElement>>() {
}.getType();
final List<CondaListElement> condaList = gson.fromJson(listJsonText, listType);
final CondaInfo condaInfo = gson.fromJson(infoJsonText, CondaInfo.class);
final String platform = condaInfo.getPlatform();
MutableDependencyGraph graph = new MutableMapDependencyGraph();
for (CondaListElement condaListElement : condaList) {
graph.addChildToRoot(condaListElementToDependency(platform, condaListElement));
}
return graph;
}
use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph 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.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.
the class NameVersionNodeTransformer method createDependencyGraph.
public DependencyGraph createDependencyGraph(final Forge defaultForge, final NameVersionNode nameVersionNode, final Boolean rootIsRealRoot) {
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final Dependency root = addNameVersionNodeToDependencyGraph(graph, defaultForge, nameVersionNode);
if (rootIsRealRoot) {
graph.addChildToRoot(root);
} else {
graph.addChildrenToRoot(graph.getChildrenForParent(root));
}
return graph;
}
use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.
the class DetectProjectManager method createBdioFiles.
public List<File> createBdioFiles(final DetectProject detectProject) throws DetectUserFriendlyException {
final List<File> bdioFiles = new ArrayList<>();
final MutableDependencyGraph aggregateDependencyGraph = simpleBdioFactory.createMutableDependencyGraph();
if (StringUtils.isBlank(detectConfiguration.getAggregateBomName())) {
for (final String codeLocationNameString : detectProject.getCodeLocationNameStrings()) {
final DetectCodeLocation detectCodeLocation = detectProject.getDetectCodeLocation(codeLocationNameString);
final String bdioFileName = detectProject.getBdioFilename(codeLocationNameString);
final SimpleBdioDocument simpleBdioDocument = createSimpleBdioDocument(codeLocationNameString, detectProject.getProjectName(), detectProject.getProjectVersionName(), detectCodeLocation);
final File outputFile = new File(detectConfiguration.getBdioOutputDirectoryPath(), bdioFileName);
if (outputFile.exists()) {
final boolean deleteSuccess = outputFile.delete();
logger.debug(String.format("%s deleted: %b", outputFile.getAbsolutePath(), deleteSuccess));
}
writeBdioFile(outputFile, simpleBdioDocument);
bdioFiles.add(outputFile);
}
} else {
for (final DetectCodeLocation detectCodeLocation : detectProject.getDetectCodeLocations()) {
if (detectCodeLocation.getDependencyGraph() == null) {
logger.warn(String.format("Dependency graph is null for code location %s", detectCodeLocation.getSourcePath()));
continue;
}
if (detectCodeLocation.getDependencyGraph().getRootDependencies().size() <= 0) {
logger.warn(String.format("Could not find any dependencies for code location %s", detectCodeLocation.getSourcePath()));
}
aggregateDependencyGraph.addGraphAsChildrenToRoot(detectCodeLocation.getDependencyGraph());
}
final SimpleBdioDocument aggregateBdioDocument = createAggregateSimpleBdioDocument(detectProject.getProjectName(), detectProject.getProjectVersionName(), aggregateDependencyGraph);
final String filename = String.format("%s.jsonld", integrationEscapeUtil.escapeForUri(detectConfiguration.getAggregateBomName()));
final File aggregateBdioFile = new File(detectConfiguration.getOutputDirectory(), filename);
if (aggregateBdioFile.exists()) {
final boolean deleteSuccess = aggregateBdioFile.delete();
logger.debug(String.format("%s deleted: %b", aggregateBdioFile.getAbsolutePath(), deleteSuccess));
}
writeBdioFile(aggregateBdioFile, aggregateBdioDocument);
}
return bdioFiles;
}
use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph 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