Search in sources :

Example 1 with RebarParseResult

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);
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) RebarParseResult(com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) DependencyHistory(com.synopsys.integration.detectable.detectable.util.DependencyHistory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 2 with RebarParseResult

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();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) HashMap(java.util.HashMap) RebarParseResult(com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult) ArrayList(java.util.ArrayList) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 RebarParseResult (com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult)2 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 DependencyHistory (com.synopsys.integration.detectable.detectable.util.DependencyHistory)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 Executable (com.synopsys.integration.executable.Executable)1 NameVersion (com.synopsys.integration.util.NameVersion)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1