use of com.synopsys.integration.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.
the class PipInspectorTreeParser method parse.
public Optional<PipParseResult> parse(final List<String> pipInspectorOutputAsList, final String sourcePath) {
PipParseResult parseResult = null;
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final DependencyHistory history = new DependencyHistory();
Dependency project = null;
for (final String line : pipInspectorOutputAsList) {
final String trimmedLine = StringUtils.trimToEmpty(line);
if (StringUtils.isEmpty(trimmedLine) || !trimmedLine.contains(SEPARATOR) || trimmedLine.startsWith(UNKNOWN_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNPARSEABLE_REQUIREMENTS_PREFIX) || trimmedLine.startsWith(UNKNOWN_PACKAGE_PREFIX)) {
parseErrorsFromLine(trimmedLine);
continue;
}
final Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
final int lineLevel = getLineLevel(trimmedLine);
try {
history.clearDependenciesDeeperThan(lineLevel);
} catch (final IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (project == null) {
project = currentDependency;
} else if (project.equals(history.getLastDependency())) {
graph.addChildToRoot(currentDependency);
} else if (history.isEmpty()) {
graph.addChildToRoot(currentDependency);
} else {
graph.addChildWithParents(currentDependency, history.getLastDependency());
}
history.add(currentDependency);
}
if (project != null) {
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, project.externalId, graph).build();
parseResult = new PipParseResult(project.name, project.version, codeLocation);
}
return Optional.ofNullable(parseResult);
}
use of com.synopsys.integration.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.
the class BdioCodeLocationCreator method transformDetectCodeLocationsIntoBdioCodeLocations.
private List<BdioCodeLocation> transformDetectCodeLocationsIntoBdioCodeLocations(final List<DetectCodeLocation> codeLocations, final String codeLocationName, final boolean combineCodeLocations) {
final List<BdioCodeLocation> bdioCodeLocations;
final IntegrationEscapeUtil integrationEscapeUtil = new IntegrationEscapeUtil();
if (codeLocations.size() > 1) {
// we must either combine or create a unique name.
if (combineCodeLocations) {
final DependencyGraphCombiner combiner = new DependencyGraphCombiner();
logger.info("Combining duplicate code locations with name: " + codeLocationName);
final MutableDependencyGraph combinedGraph = new MutableMapDependencyGraph();
final DetectCodeLocation finalCodeLocation = copyCodeLocation(codeLocations.get(0), combinedGraph);
codeLocations.stream().filter(codeLocation -> shouldCombine(logger, finalCodeLocation, codeLocation)).forEach(codeLocation -> combiner.addGraphAsChildrenToRoot(combinedGraph, codeLocation.getDependencyGraph()));
final BdioCodeLocation bdioCodeLocation = new BdioCodeLocation(finalCodeLocation, codeLocationName, createBdioName(codeLocationName, integrationEscapeUtil));
bdioCodeLocations = Arrays.asList(bdioCodeLocation);
} else {
bdioCodeLocations = new ArrayList<>();
for (int i = 0; i < codeLocations.size(); i++) {
final DetectCodeLocation codeLocation = codeLocations.get(i);
final String newCodeLocationName = String.format("%s %s", codeLocationName, Integer.toString(i));
final BdioCodeLocation bdioCodeLocation = new BdioCodeLocation(codeLocation, newCodeLocationName, createBdioName(newCodeLocationName, integrationEscapeUtil));
bdioCodeLocations.add(bdioCodeLocation);
}
}
} else if (codeLocations.size() == 1) {
final DetectCodeLocation codeLocation = codeLocations.get(0);
final BdioCodeLocation bdioCodeLocation = new BdioCodeLocation(codeLocation, codeLocationName, createBdioName(codeLocationName, integrationEscapeUtil));
bdioCodeLocations = Arrays.asList(bdioCodeLocation);
} else {
logger.error("Created a code location name but no code locations.");
bdioCodeLocations = new ArrayList<>();
}
return bdioCodeLocations;
}
use of com.synopsys.integration.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.
the class GoVendorJsonParser method parseVendorJson.
public DependencyGraph parseVendorJson(final Gson gson, final String vendorJsonContents) {
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
GoVendorJsonData vendorJsonData = gson.fromJson(vendorJsonContents, GoVendorJsonData.class);
logger.trace(String.format("vendorJsonData: %s", vendorJsonData));
for (GoVendorJsonPackageData pkg : vendorJsonData.getPackages()) {
if (StringUtils.isNotBlank(pkg.getPath()) && StringUtils.isNotBlank(pkg.getRevision())) {
final ExternalId dependencyExternalId = externalIdFactory.createNameVersionExternalId(Forge.GOLANG, pkg.getPath(), pkg.getRevision());
final Dependency dependency = new Dependency(pkg.getPath(), pkg.getRevision(), dependencyExternalId);
logger.trace(String.format("dependency: %s", dependency.externalId.toString()));
graph.addChildToRoot(dependency);
} else {
logger.debug(String.format("Omitting package path:'%s', revision:'%s' (one or both of path, revision is/are missing)", pkg.getPath(), pkg.getRevision()));
}
}
return graph;
}
use of com.synopsys.integration.bdio.graph.MutableDependencyGraph 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.MutableDependencyGraph 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;
}
Aggregations