use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.
the class GopkgLockParser method parseDepLock.
public DependencyGraph parseDepLock(final String depLockContents) {
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final GopkgLock gopkgLock = new Toml().read(depLockContents).to(GopkgLock.class);
for (final Project project : gopkgLock.getProjects()) {
if (project != null) {
final NameVersion projectNameVersion = createProjectNameVersion(project);
project.getPackages().stream().map(packageName -> createDependencyName(projectNameVersion.getName(), packageName)).map(dependencyName -> createGoDependency(dependencyName, projectNameVersion.getVersion())).forEach(graph::addChildToRoot);
}
}
return graph;
}
use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.
the class CondaListParser method parse.
public DependencyGraph parse(final String listJsonText, final 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.platform;
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
for (final CondaListElement condaListElement : condaList) {
graph.addChildToRoot(condaListElementToDependency(platform, condaListElement));
}
return graph;
}
use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.
the class RebarParserTest method testParseRebarTreeOutput.
@Test
public void testParseRebarTreeOutput() {
final MutableMapDependencyGraph expectedGraph = new MutableMapDependencyGraph();
final Dependency gitInnerParentDependency = buildDependency("git_inner_parent_dependency", "0.0.2");
final Dependency hexInnerChildDependency = buildDependency("hex_inner_child_dependency", "0.3.0");
final Dependency hexGrandchildDependency = buildDependency("hex_grandchild_dependency", "4.0.0");
final Dependency gitInnerChildDependency = buildDependency("git_inner_child_dependency", "0.5.0");
final Dependency gitGrandchildDependency = buildDependency("git_grandchild_dependency", "6.0.0");
final Dependency gitOuterParentDependency = buildDependency("git_outer_parent_dependency", "0.0.7");
final Dependency gitOuterChildDependency = buildDependency("git_outer_child_dependency", "0.8.0");
expectedGraph.addChildrenToRoot(gitInnerParentDependency, gitOuterParentDependency);
expectedGraph.addChildWithParent(hexInnerChildDependency, gitInnerParentDependency);
expectedGraph.addChildWithParents(hexGrandchildDependency, hexInnerChildDependency);
expectedGraph.addChildWithParent(gitInnerChildDependency, gitInnerParentDependency);
expectedGraph.addChildWithParents(gitGrandchildDependency, gitInnerChildDependency);
expectedGraph.addChildWithParents(gitOuterChildDependency, gitOuterParentDependency);
final DetectCodeLocation codeLocation = build("/hex/dependencyTree.txt");
final DependencyGraph actualGraph = codeLocation.getDependencyGraph();
assertGraph(expectedGraph, actualGraph);
}
use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.
the class NpmCliParser method convertNpmJsonFileToCodeLocation.
NpmParseResult convertNpmJsonFileToCodeLocation(final String sourcePath, final String npmLsOutput) {
final JsonObject npmJson = new JsonParser().parse(npmLsOutput).getAsJsonObject();
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME);
final JsonElement projectVersionElement = npmJson.getAsJsonPrimitive(JSON_VERSION);
String projectName = null;
String projectVersion = null;
if (projectNameElement != null) {
projectName = projectNameElement.getAsString();
}
if (projectVersionElement != null) {
projectVersion = projectVersionElement.getAsString();
}
populateChildren(graph, null, npmJson.getAsJsonObject(JSON_DEPENDENCIES), true);
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPM, projectName, projectVersion);
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NPM, sourcePath, externalId, graph).build();
return new NpmParseResult(projectName, projectVersion, codeLocation);
}
use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.
the class NpmLockfileParser method parse.
public NpmParseResult parse(final String sourcePath, final Optional<String> packageJsonText, final String lockFileText, final boolean includeDevDependencies) {
final MutableDependencyGraph dependencyGraph = new MutableMapDependencyGraph();
logger.info("Parsing lock file text: ");
logger.debug(lockFileText);
Optional<PackageJson> packageJson = Optional.empty();
if (packageJsonText.isPresent()) {
logger.debug(packageJsonText.get());
packageJson = Optional.of(gson.fromJson(packageJsonText.get(), PackageJson.class));
}
final PackageLock packageLock = gson.fromJson(lockFileText, PackageLock.class);
logger.debug(lockFileText);
logger.info("Processing project.");
if (packageLock.dependencies != null) {
logger.info(String.format("Found %d dependencies.", packageLock.dependencies.size()));
// Convert to our custom format
NpmDependencyConverter dependencyConverter = new NpmDependencyConverter(externalIdFactory);
NpmDependency rootDependency = dependencyConverter.convertLockFile(packageLock, packageJson);
traverse(rootDependency, dependencyGraph, true, includeDevDependencies);
} else {
logger.info("Lock file did not have a 'dependencies' section.");
}
logger.info("Finished processing.");
final ExternalId projectId = externalIdFactory.createNameVersionExternalId(Forge.NPM, packageLock.name, packageLock.version);
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.NPM, sourcePath, projectId, dependencyGraph).build();
return new NpmParseResult(packageLock.name, packageLock.version, codeLocation);
}
Aggregations