use of com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult in project synopsys-detect by blackducksoftware.
the class Rebar3TreeParser method parseRebarTreeOutput.
public RebarParseResult parseRebarTreeOutput(List<String> dependencyTreeOutput) {
DependencyGraph graph = new BasicDependencyGraph();
DependencyHistory history = new DependencyHistory();
Dependency project = null;
for (String line : dependencyTreeOutput) {
if (!line.contains(HORIZONTAL_SEPARATOR_CHARACTER)) {
continue;
}
Dependency currentDependency = createDependencyFromLine(line);
int lineLevel = getDependencyLevelFromLine(line);
try {
history.clearDependenciesDeeperThan(lineLevel);
} catch (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) {
CodeLocation codeLocation = new CodeLocation(graph);
return new RebarParseResult(codeLocation);
} else {
CodeLocation codeLocation = new CodeLocation(graph, project.getExternalId());
return new RebarParseResult(new NameVersion(project.getName(), project.getVersion()), codeLocation);
}
}
use of com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult in project synopsys-detect by blackducksoftware.
the class RebarExtractor method extract.
public Extraction extract(File directory, ExecutableTarget rebarExe) {
try {
toolVersionLogger.log(directory, rebarExe);
List<CodeLocation> codeLocations = new ArrayList<>();
Map<String, String> envVars = new HashMap<>();
envVars.put("REBAR_COLOR", "none");
List<String> arguments = new ArrayList<>();
arguments.add("tree");
Executable rebar3TreeExe = ExecutableUtils.createFromTarget(directory, envVars, rebarExe, arguments);
List<String> output = executableRunner.execute(rebar3TreeExe).getStandardOutputAsList();
RebarParseResult parseResult = rebarTreeParser.parseRebarTreeOutput(output);
codeLocations.add(parseResult.getCodeLocation());
Extraction.Builder builder = new Extraction.Builder().success(codeLocations);
parseResult.getProjectNameVersion().ifPresent(projectNameVersion -> builder.projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()));
return builder.build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations