Search in sources :

Example 1 with DependencyInsightReporter

use of org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter in project gradle by gradle.

the class JsonProjectDependencyRenderer method createInsight.

private List createInsight(ModuleIdentifier module, final Configuration configuration) {
    final Spec<DependencyResult> dependencySpec = new StrictDependencyResultSpec(module);
    ResolutionResult result = configuration.getIncoming().getResolutionResult();
    final Set<DependencyResult> selectedDependencies = new LinkedHashSet<DependencyResult>();
    result.allDependencies(new Action<DependencyResult>() {

        @Override
        public void execute(DependencyResult it) {
            if (dependencySpec.isSatisfiedBy(it)) {
                selectedDependencies.add(it);
            }
        }
    });
    Collection<RenderableDependency> sortedDeps = new DependencyInsightReporter().prepare(selectedDependencies, versionSelectorScheme, versionComparator);
    return CollectionUtils.collect(sortedDeps, new Transformer<Object, RenderableDependency>() {

        @Override
        public Object transform(RenderableDependency dependency) {
            String name = replaceArrow(dependency.getName());
            LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(5);
            map.put("name", replaceArrow(dependency.getName()));
            map.put("description", dependency.getDescription());
            map.put("resolvable", dependency.getResolutionState());
            map.put("hasConflict", !name.equals(dependency.getName()));
            map.put("children", createInsightDependencyChildren(dependency, new HashSet<Object>(), configuration));
            return map;
        }
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) LinkedHashMap(java.util.LinkedHashMap) DependencyInsightReporter(org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter)

Example 2 with DependencyInsightReporter

use of org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter in project gradle by gradle.

the class DependencyInsightReportTask method report.

@TaskAction
public void report() {
    final Configuration configuration = getConfiguration();
    if (configuration == null) {
        throw new InvalidUserDataException("Dependency insight report cannot be generated because the input configuration was not specified. " + "\nIt can be specified from the command line, e.g: '" + getPath() + " --configuration someConf --dependency someDep'");
    }
    if (dependencySpec == null) {
        throw new InvalidUserDataException("Dependency insight report cannot be generated because the dependency to show was not specified." + "\nIt can be specified from the command line, e.g: '" + getPath() + " --dependency someDep'");
    }
    StyledTextOutput output = getTextOutputFactory().create(getClass());
    GraphRenderer renderer = new GraphRenderer(output);
    ResolutionResult result = configuration.getIncoming().getResolutionResult();
    final Set<DependencyResult> selectedDependencies = new LinkedHashSet<DependencyResult>();
    result.allDependencies(new Action<DependencyResult>() {

        @Override
        public void execute(DependencyResult dependencyResult) {
            if (dependencySpec.isSatisfiedBy(dependencyResult)) {
                selectedDependencies.add(dependencyResult);
            }
        }
    });
    if (selectedDependencies.isEmpty()) {
        output.println("No dependencies matching given input were found in " + String.valueOf(configuration));
        return;
    }
    Collection<RenderableDependency> sortedDeps = new DependencyInsightReporter().prepare(selectedDependencies, getVersionSelectorScheme(), getVersionComparator());
    NodeRenderer nodeRenderer = new NodeRenderer() {

        public void renderNode(StyledTextOutput target, RenderableDependency node, boolean alreadyRendered) {
            boolean leaf = node.getChildren().isEmpty();
            target.text(leaf ? configuration.getName() : node.getName());
            if (alreadyRendered && !leaf) {
                target.withStyle(Info).text(" (*)");
            }
        }
    };
    LegendRenderer legendRenderer = new LegendRenderer(output);
    DependencyGraphRenderer dependencyGraphRenderer = new DependencyGraphRenderer(renderer, nodeRenderer, legendRenderer);
    int i = 1;
    for (final RenderableDependency dependency : sortedDeps) {
        renderer.visit(new Action<StyledTextOutput>() {

            public void execute(StyledTextOutput out) {
                out.withStyle(Identifier).text(dependency.getName());
                if (StringUtils.isNotEmpty(dependency.getDescription())) {
                    out.withStyle(Description).text(" (" + dependency.getDescription() + ")");
                }
                switch(dependency.getResolutionState()) {
                    case FAILED:
                        out.withStyle(Failure).text(" FAILED");
                        break;
                    case RESOLVED:
                        break;
                    case UNRESOLVED:
                        out.withStyle(Failure).text(" (n)");
                        break;
                }
            }
        }, true);
        dependencyGraphRenderer.render(dependency);
        boolean last = i++ == sortedDeps.size();
        if (!last) {
            output.println();
        }
    }
    legendRenderer.printLegend();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) Configuration(org.gradle.api.artifacts.Configuration) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) DependencyGraphRenderer(org.gradle.api.tasks.diagnostics.internal.graph.DependencyGraphRenderer) NodeRenderer(org.gradle.api.tasks.diagnostics.internal.graph.NodeRenderer) DependencyInsightReporter(org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter) LegendRenderer(org.gradle.api.tasks.diagnostics.internal.graph.LegendRenderer) GraphRenderer(org.gradle.internal.graph.GraphRenderer) DependencyGraphRenderer(org.gradle.api.tasks.diagnostics.internal.graph.DependencyGraphRenderer) InvalidUserDataException(org.gradle.api.InvalidUserDataException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)2 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)2 ResolutionResult (org.gradle.api.artifacts.result.ResolutionResult)2 RenderableDependency (org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency)2 DependencyInsightReporter (org.gradle.api.tasks.diagnostics.internal.insight.DependencyInsightReporter)2 LinkedHashMap (java.util.LinkedHashMap)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Configuration (org.gradle.api.artifacts.Configuration)1 TaskAction (org.gradle.api.tasks.TaskAction)1 DependencyGraphRenderer (org.gradle.api.tasks.diagnostics.internal.graph.DependencyGraphRenderer)1 LegendRenderer (org.gradle.api.tasks.diagnostics.internal.graph.LegendRenderer)1 NodeRenderer (org.gradle.api.tasks.diagnostics.internal.graph.NodeRenderer)1 GraphRenderer (org.gradle.internal.graph.GraphRenderer)1 StyledTextOutput (org.gradle.internal.logging.text.StyledTextOutput)1