Search in sources :

Example 1 with DependencyHistory

use of com.synopsys.integration.detectable.detectable.util.DependencyHistory in project synopsys-detect by blackducksoftware.

the class GradleReportTransformer method addConfigurationToGraph.

private void addConfigurationToGraph(MutableDependencyGraph graph, GradleConfiguration configuration) {
    DependencyHistory history = new DependencyHistory();
    TreeNodeSkipper treeNodeSkipper = new TreeNodeSkipper();
    for (GradleTreeNode currentNode : configuration.getChildren()) {
        if (treeNodeSkipper.shouldSkip(currentNode)) {
            continue;
        }
        if (currentNode.getNodeType() == GradleTreeNode.NodeType.GAV) {
            history.clearDependenciesDeeperThan(currentNode.getLevel());
            Optional<GradleGav> currentNodeGav = currentNode.getGav();
            if (currentNodeGav.isPresent()) {
                addGavToGraph(currentNodeGav.get(), history, graph);
            } else {
                // We know this is a GradleTreeNode.NodeType.GAV
                // So if its missing data, something is probably wrong.
                logger.debug("Missing expected GAV from known NodeType. {}", currentNode);
            }
        } else {
            treeNodeSkipper.skipUntilLineLevel(currentNode.getLevel());
        }
    }
}
Also used : GradleTreeNode(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleTreeNode) GradleGav(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleGav) DependencyHistory(com.synopsys.integration.detectable.detectable.util.DependencyHistory)

Example 2 with DependencyHistory

use of com.synopsys.integration.detectable.detectable.util.DependencyHistory in project synopsys-detect by blackducksoftware.

the class PubDepsParser method parseLines.

private void parseLines(List<String> lines, Map<String, String> resolvedVersions, DependencyGraph dependencyGraph) {
    DependencyHistory dependencyHistory = new DependencyHistory();
    for (String line : lines) {
        int depthOfLine = calculateDepth(line);
        if (depthOfLine == 0) {
            // non-graph line
            continue;
        }
        int dependencyDepth = depthOfLine - 1;
        dependencyHistory.clearDependenciesDeeperThan(dependencyDepth);
        String nameOfDependency = parseNameFromlLine(line);
        Dependency dependency = createDependency(nameOfDependency, resolvedVersions);
        if (dependencyHistory.isEmpty()) {
            dependencyGraph.addChildToRoot(dependency);
        } else {
            dependencyGraph.addChildWithParent(dependency, dependencyHistory.getLastDependency());
        }
        dependencyHistory.add(dependency);
    }
}
Also used : DependencyHistory(com.synopsys.integration.detectable.detectable.util.DependencyHistory) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 3 with DependencyHistory

use of com.synopsys.integration.detectable.detectable.util.DependencyHistory in project synopsys-detect by blackducksoftware.

the class GradleReportTransformer method addConfigurationToGraph.

private void addConfigurationToGraph(DependencyGraph graph, GradleConfiguration configuration) {
    DependencyHistory history = new DependencyHistory();
    TreeNodeSkipper treeNodeSkipper = new TreeNodeSkipper();
    for (GradleTreeNode currentNode : configuration.getChildren()) {
        if (treeNodeSkipper.shouldSkip(currentNode)) {
            continue;
        }
        if (currentNode.getNodeType() == GradleTreeNode.NodeType.GAV) {
            history.clearDependenciesDeeperThan(currentNode.getLevel());
            Optional<GradleGav> currentNodeGav = currentNode.getGav();
            if (currentNodeGav.isPresent()) {
                addGavToGraph(currentNodeGav.get(), history, graph);
            } else {
                // We know this is a GradleTreeNode.NodeType.GAV
                // So if its missing data, something is probably wrong.
                logger.debug("Missing expected GAV from known NodeType. {}", currentNode);
            }
        } else {
            treeNodeSkipper.skipUntilLineLevel(currentNode.getLevel());
        }
    }
}
Also used : GradleTreeNode(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleTreeNode) GradleGav(com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleGav) DependencyHistory(com.synopsys.integration.detectable.detectable.util.DependencyHistory)

Example 4 with DependencyHistory

use of com.synopsys.integration.detectable.detectable.util.DependencyHistory 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 5 with DependencyHistory

use of com.synopsys.integration.detectable.detectable.util.DependencyHistory in project synopsys-detect by blackducksoftware.

the class PipInspectorTreeParser method parse.

public Optional<NameVersionCodeLocation> parse(List<String> pipInspectorOutputAsList, String sourcePath) {
    NameVersionCodeLocation parseResult = null;
    DependencyGraph graph = new BasicDependencyGraph();
    DependencyHistory history = new DependencyHistory();
    Dependency project = null;
    int unResolvedPackageCount = 0;
    for (String line : pipInspectorOutputAsList) {
        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)) {
            boolean wasUnresolved = parseErrorsFromLine(trimmedLine);
            if (wasUnresolved) {
                unResolvedPackageCount++;
            }
            continue;
        }
        Dependency currentDependency = parseDependencyFromLine(trimmedLine, sourcePath);
        adjustForIndentLevel(history, line);
        project = addDependencyToGraph(graph, history, project, currentDependency);
        history.add(currentDependency);
    }
    adviseIfUnresolvedPackages(unResolvedPackageCount);
    if (project != null) {
        CodeLocation codeLocation = new CodeLocation(graph, project.getExternalId());
        parseResult = new NameVersionCodeLocation(project.getName(), project.getVersion(), codeLocation);
    }
    return Optional.ofNullable(parseResult);
}
Also used : NameVersionCodeLocation(com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) 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) NameVersionCodeLocation(com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation)

Aggregations

DependencyHistory (com.synopsys.integration.detectable.detectable.util.DependencyHistory)6 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)4 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 GradleGav (com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleGav)2 GradleTreeNode (com.synopsys.integration.detectable.detectables.gradle.inspection.model.GradleTreeNode)2 NameVersionCodeLocation (com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation)1 RebarParseResult (com.synopsys.integration.detectable.detectables.rebar.model.RebarParseResult)1 NameVersion (com.synopsys.integration.util.NameVersion)1