use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class PipInspectorTreeParser method parseDependencyFromLine.
private Dependency parseDependencyFromLine(final String line, final String sourcePath) {
final String[] segments = line.split(SEPARATOR);
String name = segments[0].trim();
String version = segments[1].trim();
ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, name, version);
if (name.equals(UNKNOWN_PROJECT_NAME) || version.equals(UNKNOWN_PROJECT_VERSION)) {
externalId = externalIdFactory.createPathExternalId(Forge.PYPI, sourcePath);
}
name = name.equals(UNKNOWN_PROJECT_NAME) ? "" : name;
version = version.equals(UNKNOWN_PROJECT_VERSION) ? "" : version;
return new Dependency(name, version, externalId);
}
use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class PipenvGraphParser method getDependencyFromLine.
Optional<Dependency> getDependencyFromLine(final Map<String, String[]> pipFreezeMap, final String line) {
Dependency dependency = null;
String name = null;
String version = null;
final String trimmedLine = line.trim();
if (line.contains(DEPENDENCY_NAME_PREFIX) && line.contains(DEPENDENCY_NAME_SUFFIX) && line.contains(DEPENDENCY_VERSION_PREFIX) && line.contains(DEPENDENCY_VERSION_SUFFIX)) {
name = trimmedLine.substring(trimmedLine.indexOf(DEPENDENCY_NAME_PREFIX) + DEPENDENCY_NAME_PREFIX.length(), trimmedLine.indexOf(DEPENDENCY_NAME_SUFFIX));
version = trimmedLine.substring(trimmedLine.indexOf(DEPENDENCY_VERSION_PREFIX) + DEPENDENCY_VERSION_PREFIX.length(), trimmedLine.indexOf(DEPENDENCY_VERSION_SUFFIX));
} else if (trimmedLine.contains(TOP_LEVEL_SEPARATOR)) {
final String[] splitLine = trimmedLine.split(TOP_LEVEL_SEPARATOR);
name = splitLine[0];
version = splitLine[1];
}
if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(version)) {
final String[] pipFreezeResult = pipFreezeMap.get(name.toLowerCase());
if (pipFreezeResult != null) {
name = pipFreezeResult[0].trim();
version = pipFreezeResult[1].trim();
}
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, name, version);
dependency = new Dependency(name, version, externalId);
}
return Optional.ofNullable(dependency);
}
use of com.synopsys.integration.bdio.model.dependency.Dependency 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.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class Rebar3TreeParser method createDependencyFromLine.
protected Dependency createDependencyFromLine(final String line) {
final String nameVersionLine = reduceLineToNameVersion(line);
final String name = nameVersionLine.substring(0, nameVersionLine.lastIndexOf(HORIZONTAL_SEPARATOR_CHARACTER));
final String version = nameVersionLine.substring(nameVersionLine.lastIndexOf(HORIZONTAL_SEPARATOR_CHARACTER) + 1);
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.HEX, name, version);
return new Dependency(name, version, externalId);
}
use of com.synopsys.integration.bdio.model.dependency.Dependency 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);
}
Aggregations