use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.
the class PearParser method parsePearDependencyList.
public DependencyGraph parsePearDependencyList(final ExecutableOutput pearListing, final ExecutableOutput pearDependencies) {
DependencyGraph graph = new MutableMapDependencyGraph();
if (StringUtils.isNotBlank(pearDependencies.getErrorOutput()) || StringUtils.isNotBlank(pearListing.getErrorOutput())) {
logger.error("There was an error during execution.");
if (StringUtils.isNotBlank(pearListing.getErrorOutput())) {
logger.error("Pear list error: ");
logger.error(pearListing.getErrorOutput());
}
if (StringUtils.isNotBlank(pearDependencies.getErrorOutput())) {
logger.error("Pear package-dependencies error: ");
logger.error(pearDependencies.getErrorOutput());
}
} else if (!(pearDependencies.getStandardOutputAsList().size() > 0) || !(pearListing.getStandardOutputAsList().size() > 0)) {
logger.error("No information retrieved from running pear commands");
} else {
final List<String> nameList = findDependencyNames(pearDependencies.getStandardOutputAsList());
graph = createPearDependencyGraphFromList(pearListing.getStandardOutputAsList(), nameList);
}
return graph;
}
use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph in project hub-detect by blackducksoftware.
the class PipenvGraphParser method parse.
public PipParseResult parse(final String projectName, final String projectVersionName, final List<String> pipFreezeOutput, final List<String> pipenvGraphOutput, final String sourcePath) {
final MutableMapDependencyGraph dependencyGraph = new MutableMapDependencyGraph();
final Stack<Dependency> dependencyStack = new Stack<>();
final Map<String, String[]> pipFreezeMap = pipFreezeOutput.stream().map(line -> line.split(TOP_LEVEL_SEPARATOR)).filter(splitLine -> splitLine.length == 2).collect(Collectors.toMap(splitLine -> splitLine[0].trim().toLowerCase(), splitLine -> splitLine));
int lastLevel = -1;
for (final String line : pipenvGraphOutput) {
final int currentLevel = getLevel(line);
final Optional<Dependency> parsedDependency = getDependencyFromLine(pipFreezeMap, line);
if (!parsedDependency.isPresent()) {
continue;
}
final Dependency dependency = parsedDependency.get();
if (currentLevel == lastLevel) {
dependencyStack.pop();
} else {
for (; lastLevel >= currentLevel; lastLevel--) {
dependencyStack.pop();
}
}
if (dependencyStack.size() > 0) {
dependencyGraph.addChildWithParent(dependency, dependencyStack.peek());
} else {
dependencyGraph.addChildrenToRoot(dependency);
}
lastLevel = currentLevel;
dependencyStack.push(dependency);
}
if (!dependencyGraph.getRootDependencyExternalIds().isEmpty()) {
final ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName);
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, projectExternalId, dependencyGraph).build();
return new PipParseResult(projectName, projectVersionName, codeLocation);
} else {
return null;
}
}
use of com.synopsys.integration.bdio.graph.MutableMapDependencyGraph 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.MutableMapDependencyGraph 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.MutableMapDependencyGraph 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;
}
Aggregations