use of com.blackducksoftware.integration.hub.detect.util.DependencyHistory 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.blackducksoftware.integration.hub.detect.util.DependencyHistory in project hub-detect by blackducksoftware.
the class GradleReportParser method parseDependencies.
public Optional<DetectCodeLocation> parseDependencies(final File codeLocationFile) {
DetectCodeLocation codeLocation = null;
String projectSourcePath = "";
String projectGroup = "";
String projectName = "";
String projectVersionName = "";
boolean processingMetaData = false;
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final DependencyHistory history = new DependencyHistory();
try (FileInputStream dependenciesInputStream = new FileInputStream(codeLocationFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(dependenciesInputStream, StandardCharsets.UTF_8))) {
while (reader.ready()) {
final String line = reader.readLine();
/**
* The meta data section will be at the end of the file after all of the "gradle dependencies" output
*/
if (line.startsWith(DETECT_META_DATA_HEADER)) {
processingMetaData = true;
continue;
}
if (line.startsWith(DETECT_META_DATA_FOOTER)) {
processingMetaData = false;
continue;
}
if (processingMetaData) {
if (line.startsWith(PROJECT_PATH_PREFIX)) {
projectSourcePath = line.substring(PROJECT_PATH_PREFIX.length()).trim();
} else if (line.startsWith(PROJECT_GROUP_PREFIX)) {
projectGroup = line.substring(PROJECT_GROUP_PREFIX.length()).trim();
} else if (line.startsWith(PROJECT_NAME_PREFIX)) {
projectName = line.substring(PROJECT_NAME_PREFIX.length()).trim();
} else if (line.startsWith(PROJECT_VERSION_PREFIX)) {
projectVersionName = line.substring(PROJECT_VERSION_PREFIX.length()).trim();
}
continue;
}
if (StringUtils.isBlank(line)) {
history.clear();
gradleReportConfigurationParser = new GradleReportConfigurationParser();
continue;
}
final Dependency dependency = gradleReportConfigurationParser.parseDependency(externalIdFactory, line);
if (dependency == null) {
continue;
}
final int lineTreeLevel = gradleReportConfigurationParser.getTreeLevel();
try {
history.clearDependenciesDeeperThan(lineTreeLevel);
} catch (final IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (history.isEmpty()) {
graph.addChildToRoot(dependency);
} else {
graph.addChildWithParents(dependency, history.getLastDependency());
}
history.add(dependency);
}
final ExternalId id = externalIdFactory.createMavenExternalId(projectGroup, projectName, projectVersionName);
codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GRADLE, projectSourcePath, id, graph).build();
} catch (final IOException e) {
codeLocation = null;
}
return Optional.ofNullable(codeLocation);
}
use of com.blackducksoftware.integration.hub.detect.util.DependencyHistory in project hub-detect by blackducksoftware.
the class Rebar3TreeParser method parseRebarTreeOutput.
public RebarParseResult parseRebarTreeOutput(final List<String> dependencyTreeOutput, final String sourcePath) {
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final DependencyHistory history = new DependencyHistory();
Dependency project = null;
for (final String line : dependencyTreeOutput) {
if (!line.contains(HORIZONTAL_SEPARATOR_CHARACTER)) {
continue;
}
final Dependency currentDependency = createDependencyFromLine(line);
final int lineLevel = getDependencyLevelFromLine(line);
try {
history.clearDependenciesDeeperThan(lineLevel);
} catch (final IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (history.isEmpty() && isProject(line)) {
project = currentDependency;
} else if (history.getLastDependency().equals(project)) {
graph.addChildToRoot(currentDependency);
} else if (history.isEmpty()) {
graph.addChildToRoot(currentDependency);
} else {
graph.addChildWithParents(currentDependency, history.getLastDependency());
}
history.add(currentDependency);
}
if (project == null) {
final ExternalId projectExternalId = externalIdFactory.createPathExternalId(Forge.HEX, sourcePath);
project = new Dependency("", "", projectExternalId);
}
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.HEX, project.name, project.version);
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.HEX, sourcePath, externalId, graph).build();
return new RebarParseResult(project.name, project.version, codeLocation);
}
use of com.blackducksoftware.integration.hub.detect.util.DependencyHistory in project hub-detect by blackducksoftware.
the class YarnListParser method parseYarnList.
public DependencyGraph parseYarnList(final List<String> yarnLockText, final List<String> yarnListAsList) {
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final DependencyHistory history = new DependencyHistory();
final Map<String, String> yarnLockVersionMap = yarnLockParser.getYarnLockResolvedVersionMap(yarnLockText);
for (final String line : yarnListAsList) {
final String lowerCaseLine = line.toLowerCase().trim();
final String cleanedLine = line.replaceAll(NTH_DEPENDENCY_PREFIX, "").replaceAll(INNER_LEVEL_CHARACTER, "").replaceAll(LAST_DEPENDENCY_PREFIX, "");
if (!cleanedLine.contains("@") || lowerCaseLine.startsWith("yarn list") || lowerCaseLine.startsWith("done in") || lowerCaseLine.startsWith("warning")) {
continue;
}
final Dependency dependency = parseDependencyFromLine(cleanedLine, yarnLockVersionMap);
final int lineLevel = getLineLevel(cleanedLine);
try {
history.clearDependenciesDeeperThan(lineLevel);
} catch (final IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (history.isEmpty()) {
graph.addChildToRoot(dependency);
} else {
graph.addChildWithParents(dependency, history.getLastDependency());
}
history.add(dependency);
}
return graph;
}
Aggregations