Search in sources :

Example 6 with DependencyResult

use of org.gradle.api.artifacts.result.DependencyResult 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 7 with DependencyResult

use of org.gradle.api.artifacts.result.DependencyResult 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)

Example 8 with DependencyResult

use of org.gradle.api.artifacts.result.DependencyResult in project gradle by gradle.

the class DependencyInsightReporter method prepare.

public Collection<RenderableDependency> prepare(Collection<DependencyResult> input, VersionSelectorScheme versionSelectorScheme, VersionComparator versionComparator) {
    LinkedList<RenderableDependency> out = new LinkedList<RenderableDependency>();
    List<DependencyEdge> dependencies = CollectionUtils.collect(input, new Transformer<DependencyEdge, DependencyResult>() {

        @Override
        public DependencyEdge transform(DependencyResult result) {
            if (result instanceof UnresolvedDependencyResult) {
                return new UnresolvedDependencyEdge((UnresolvedDependencyResult) result);
            } else {
                return new ResolvedDependencyEdge((ResolvedDependencyResult) result);
            }
        }
    });
    Collection<DependencyEdge> sorted = DependencyResultSorter.sort(dependencies, versionSelectorScheme, versionComparator);
    //remember if module id was annotated
    HashSet<ComponentIdentifier> annotated = new HashSet<ComponentIdentifier>();
    RequestedVersion current = null;
    for (DependencyEdge dependency : sorted) {
        //add description only to the first module
        if (annotated.add(dependency.getActual())) {
            //add a heading dependency with the annotation if the dependency does not exist in the graph
            if (!dependency.getRequested().matchesStrictly(dependency.getActual())) {
                out.add(new DependencyReportHeader(dependency));
                current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null);
                out.add(current);
            } else {
                current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), getReasonDescription(dependency.getReason()));
                out.add(current);
            }
        } else if (!current.getRequested().equals(dependency.getRequested())) {
            current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null);
            out.add(current);
        }
        current.addChild(dependency);
    }
    return out;
}
Also used : UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) RenderableDependency(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency) UnresolvedDependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvedDependencyEdge) RequestedVersion(org.gradle.api.tasks.diagnostics.internal.graph.nodes.RequestedVersion) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) LinkedList(java.util.LinkedList) ResolvedDependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.ResolvedDependencyEdge) DependencyReportHeader(org.gradle.api.tasks.diagnostics.internal.graph.nodes.DependencyReportHeader) DependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.DependencyEdge) ResolvedDependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.ResolvedDependencyEdge) UnresolvedDependencyEdge(org.gradle.api.tasks.diagnostics.internal.graph.nodes.UnresolvedDependencyEdge) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) HashSet(java.util.HashSet)

Example 9 with DependencyResult

use of org.gradle.api.artifacts.result.DependencyResult in project atlas by alibaba.

the class TDependencyManager method resolveDependency.

/**
     * 解析依赖
     *
     * @param resolvedDependencyContainer
     * @param parent
     * @param resolvedComponentResult
     * @param artifacts
     * @param configDependencies
     * @param indent
     */
private void resolveDependency(ResolvedDependencyContainer resolvedDependencyContainer, ResolvedDependencyInfo parent, ResolvedComponentResult resolvedComponentResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, VariantDependencies configDependencies, int indent, CircleDependencyCheck circleDependencyCheck, CircleDependencyCheck.DependencyNode node, Set<String> resolvedModules) {
    ModuleVersionIdentifier moduleVersion = resolvedComponentResult.getModuleVersion();
    if (configDependencies.getChecker().checkForExclusion(moduleVersion)) {
        return;
    }
    if (moduleVersion.getName().equals("support-annotations") && moduleVersion.getGroup().equals("com.android.support")) {
        configDependencies.setAnnotationsPresent(true);
    }
    // now loop on all the artifact for this modules.
    List<ResolvedArtifact> moduleArtifacts = artifacts.get(moduleVersion);
    if (null == moduleArtifacts) {
        return;
    }
    ComponentIdentifier id = resolvedComponentResult.getId();
    String gradlePath = (id instanceof ProjectComponentIdentifier) ? ((ProjectComponentIdentifier) id).getProjectPath() : null;
    // 如果同时找到多个依赖,暂时没法判断是那个真正有用
    for (ResolvedArtifact resolvedArtifact : moduleArtifacts) {
        ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(moduleVersion.getVersion(), moduleVersion.getGroup(), moduleVersion.getName(), resolvedArtifact.getType(), resolvedArtifact.getClassifier());
        resolvedDependencyInfo.setIndent(indent);
        resolvedDependencyInfo.setGradlePath(gradlePath);
        resolvedDependencyInfo.setResolvedArtifact(resolvedArtifact);
        //String parentVersionString = parent.getType();
        String moduleVersonString = moduleVersion.toString() + "." + resolvedArtifact.getType() + "." + resolvedArtifact.getClassifier() + "." + indent;
        if (null != parent) {
            if ("awb".equals(parent.getType())) {
                moduleVersonString = parent.toString() + "->" + moduleVersonString;
            }
        }
        if (resolvedModules.contains(moduleVersonString)) {
            logger.info(moduleVersonString);
            continue;
        } else {
            resolvedModules.add(moduleVersonString);
        }
        String path = computeArtifactPath(moduleVersion, resolvedArtifact);
        String name = computeArtifactName(moduleVersion, resolvedArtifact);
        File explodedDir = project.file(project.getBuildDir() + "/" + FD_INTERMEDIATES + "/exploded-" + resolvedArtifact.getType().toLowerCase() + "/" + path);
        resolvedDependencyInfo.setExplodedDir(explodedDir);
        resolvedDependencyInfo.setDependencyName(name);
        if (null == parent) {
            parent = resolvedDependencyInfo;
        } else {
            if (null == resolvedDependencyInfo.getParent()) {
                resolvedDependencyInfo.setParent(parent);
            }
            parent.getChildren().add(resolvedDependencyInfo);
        }
        Set<? extends DependencyResult> dependencies = resolvedComponentResult.getDependencies();
        for (DependencyResult dep : dependencies) {
            if (dep instanceof ResolvedDependencyResult) {
                ResolvedComponentResult childResolvedComponentResult = ((ResolvedDependencyResult) dep).getSelected();
                CircleDependencyCheck.DependencyNode childNode = circleDependencyCheck.addDependency(childResolvedComponentResult.getModuleVersion(), node, indent + 1);
                CircleDependencyCheck.CircleResult circleResult = circleDependencyCheck.checkCircle(logger);
                if (circleResult.hasCircle) {
                    logger.warning("[CircleDependency]" + StringUtils.join(circleResult.detail, ";"));
                } else {
                    resolveDependency(resolvedDependencyContainer, parent, ((ResolvedDependencyResult) dep).getSelected(), artifacts, configDependencies, indent + 1, circleDependencyCheck, childNode, resolvedModules);
                }
            }
        }
        resolvedDependencyContainer.addDependency(resolvedDependencyInfo);
    }
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedDependencyInfo(com.taobao.android.builder.dependency.ResolvedDependencyInfo) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) CircleDependencyCheck(com.taobao.android.builder.dependency.CircleDependencyCheck) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) File(java.io.File) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult)

Example 10 with DependencyResult

use of org.gradle.api.artifacts.result.DependencyResult in project atlas by alibaba.

the class AwoDependency method collectDependens.

private void collectDependens(Set<ResolvedDependencyResult> compileOnlyDependencySet) {
    for (ResolvedDependencyResult resolvedDependencyResult : compileOnlyDependencySet) {
        compileDependencies.add(resolvedDependencyResult.getSelected().getModuleVersion().getGroup() + "-" + resolvedDependencyResult.getSelected().getModuleVersion().getName());
        Set<ResolvedDependencyResult> resolvedDependencyResults = new HashSet<ResolvedDependencyResult>();
        if (null != resolvedDependencyResult.getSelected().getDependencies()) {
            for (DependencyResult sub : resolvedDependencyResult.getSelected().getDependencies()) {
                if (sub instanceof ResolvedDependencyResult) {
                    resolvedDependencyResults.add((ResolvedDependencyResult) sub);
                }
            }
        }
        collectDependens(resolvedDependencyResults);
    }
}
Also used : DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) HashSet(java.util.HashSet)

Aggregations

DependencyResult (org.gradle.api.artifacts.result.DependencyResult)11 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)9 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)7 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)7 HashSet (java.util.HashSet)6 File (java.io.File)4 List (java.util.List)4 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)4 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 Configuration (org.gradle.api.artifacts.Configuration)3 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)3 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)3 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)3 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)3 RenderableDependency (org.gradle.api.tasks.diagnostics.internal.graph.nodes.RenderableDependency)3 JarDependency (com.android.builder.dependency.JarDependency)2 LibraryDependency (com.android.builder.dependency.LibraryDependency)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 MavenCoordinates (com.android.builder.model.MavenCoordinates)2