Search in sources :

Example 16 with DependencyResult

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

the class DependencyInsightReportTask method report.

@TaskAction
public void report() {
    assertValidTaskConfiguration();
    ResolvedComponentResult rootComponent = getRootComponentProperty().get();
    StyledTextOutput output = getTextOutputFactory().create(getClass());
    Set<DependencyResult> selectedDependencies = selectDependencies(rootComponent);
    if (selectedDependencies.isEmpty()) {
        output.println("No dependencies matching given input were found in " + configurationDescription);
        return;
    }
    errorHandler.renderErrors(output);
    renderSelectedDependencies(output, selectedDependencies);
    renderBuildScanHint(output);
}
Also used : DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) TaskAction(org.gradle.api.tasks.TaskAction)

Example 17 with DependencyResult

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

the class AtlasDepTreeParser method parseDependencyTree.

public AtlasDependencyTree parseDependencyTree(@NonNull VariantDependencies variantDeps) {
    // 
    String name = variantDeps.getName().toLowerCase();
    if (!name.endsWith("debug") && !name.endsWith("release")) {
        return new AtlasDependencyTree(new ArrayList<>());
    }
    if (!name.equals("debug") && name.endsWith("debug")) {
        flavorName = variantDeps.getName().substring(0, name.length() - 5);
    }
    if (!name.equals("release") && name.endsWith("release")) {
        flavorName = variantDeps.getName().substring(0, name.length() - 6);
    }
    Configuration compileClasspath = variantDeps.getCompileClasspath();
    Configuration runtimeClasspath = variantDeps.getRuntimeClasspath();
    Configuration apiClasspath = variantDeps.getApiElements();
    Configuration configuration = variantDeps.getAnnotationProcessorConfiguration();
    Configuration bundleClasspath = project.getConfigurations().maybeCreate(AtlasPlugin.BUNDLE_COMPILE);
    ensureConfigured(compileClasspath, project);
    ensureConfigured(runtimeClasspath, project);
    ensureConfigured(bundleClasspath, project);
    ensureConfigured(apiClasspath, project);
    ensureConfigured(configuration, project);
    Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts = Maps.newHashMap();
    collectArtifacts(compileClasspath, artifacts);
    collectArtifacts(runtimeClasspath, artifacts);
    collectArtifacts(apiClasspath, artifacts);
    collectArtifacts(bundleClasspath, artifacts);
    collectArtifacts(configuration, artifacts);
    unEnsureConfigured(compileClasspath);
    unEnsureConfigured(runtimeClasspath);
    unEnsureConfigured(bundleClasspath);
    unEnsureConfigured(apiClasspath);
    unEnsureConfigured(configuration);
    // Rely on the group
    DependencyGroup dependencyGroup = new DependencyGroup(compileClasspath, bundleClasspath, artifacts, awbs);
    DependencyResolver dependencyResolver = new DependencyResolver(project, variantDeps, artifacts, dependencyGroup.bundleProvidedMap, dependencyGroup.bundleCompileMap);
    mResolvedDependencies.addAll(dependencyResolver.resolve(dependencyGroup.compileDependencies, true));
    for (DependencyResult dependencyResult : dependencyGroup.bundleDependencies) {
        mResolvedDependencies.addAll(dependencyResolver.resolve(Arrays.asList(dependencyResult), false));
    }
    AtlasDependencyTree atlasDependencyTree = toAtlasDependencyTree();
    check(atlasDependencyTree);
    return atlasDependencyTree;
}
Also used : DependencyResult(org.gradle.api.artifacts.result.DependencyResult) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) DependencyGroup(com.taobao.android.builder.dependency.parser.helper.DependencyGroup) DependencyResolver(com.taobao.android.builder.dependency.parser.helper.DependencyResolver)

Example 18 with DependencyResult

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

the class DependencyResolver method resolve.

public List<ResolvedDependencyInfo> resolve(List<DependencyResult> dependencyResults, boolean mainBundle) {
    Multimap<String, ResolvedDependencyInfo> dependenciesMap = LinkedHashMultimap.create();
    // Instead of using the official flat dependency treatment, you can use your own tree dependence; For application dependencies, we only take compile dependencies
    Set<ModuleVersionIdentifier> directDependencies = new HashSet<ModuleVersionIdentifier>();
    Set<String> resolveSets = new HashSet<>();
    for (DependencyResult dependencyResult : dependencyResults) {
        if (dependencyResult instanceof ResolvedDependencyResult) {
            ModuleVersionIdentifier moduleVersion = ((ResolvedDependencyResult) dependencyResult).getSelected().getModuleVersion();
            CircleDependencyCheck circleDependencyCheck = new CircleDependencyCheck(moduleVersion);
            if (!directDependencies.contains(moduleVersion)) {
                directDependencies.add(moduleVersion);
                resolveDependency(null, ((ResolvedDependencyResult) dependencyResult).getSelected(), artifacts, variantDeps, 0, circleDependencyCheck, circleDependencyCheck.getRootDependencyNode(), dependenciesMap, resolveSets, mainBundle);
            }
        }
    }
    List<ResolvedDependencyInfo> mainResolvdInfo = resolveAllDependencies(dependenciesMap);
    if (mainBundle) {
        for (ResolvedDependencyInfo resolvedDependencyInfo : mainResolvdInfo) {
            addMainDependencyInfo(resolvedDependencyInfo);
        }
    }
    return mainResolvdInfo;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) CircleDependencyCheck(com.taobao.android.builder.dependency.parser.CircleDependencyCheck) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult)

Example 19 with DependencyResult

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

the class DependencyResolver method resolveDependency.

/**
 * Analytical dependence
 *  @param parent
 * @param resolvedComponentResult
 * @param artifacts
 * @param configDependencies
 * @param indent
 * @param mainBundle
 */
private void resolveDependency(ResolvedDependencyInfo parent, ResolvedComponentResult resolvedComponentResult, Map<ModuleVersionIdentifier, List<ResolvedArtifact>> artifacts, VariantDependencies configDependencies, int indent, CircleDependencyCheck circleDependencyCheck, CircleDependencyCheck.DependencyNode node, Multimap<String, ResolvedDependencyInfo> dependenciesMap, Set<String> resolvedDependencies, boolean mainBundle) {
    ModuleVersionIdentifier moduleVersion = resolvedComponentResult.getModuleVersion();
    // }
    if (!ids.contains(moduleVersion.getGroup() + ":" + moduleVersion.getName())) {
        artifacts.put(moduleVersion, Lists.newArrayList((DependencyGroup.bundleCompileId.get(moduleVersion))));
    }
    // now loop on all the artifact for this modules.
    List<ResolvedArtifact> moduleArtifacts = artifacts.get(moduleVersion);
    ComponentIdentifier id = resolvedComponentResult.getId();
    String gradlePath = (id instanceof ProjectComponentIdentifier) ? ((ProjectComponentIdentifier) id).getProjectPath() : null;
    // If you can find multiple dependencies at the same time, you can't judge for the time being that it's really useful
    if (null != moduleArtifacts) {
        for (ResolvedArtifact resolvedArtifact : moduleArtifacts) {
            String key = moduleVersion.getGroup() + ":" + moduleVersion.getName();
            // remove android.jar
            if (key.equals("com.google.android:android")) {
                continue;
            }
            if (mainDependencies.contains(key)) {
                continue;
            }
            if (resolvedDependencies.contains(key)) {
                continue;
            }
            // 
            resolvedDependencies.add(key);
            boolean isAwbBundle = bundleProvidedMap.containsKey(key);
            Set<String> providedDirectDep = bundleProvidedMap.get(key);
            ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(moduleVersion.getVersion(), moduleVersion.getGroup(), moduleVersion.getName(), !mainBundle ? "awb" : resolvedArtifact.getType(), resolvedArtifact.getClassifier());
            resolvedDependencyInfo.setIndent(indent);
            resolvedDependencyInfo.setGradlePath(gradlePath);
            resolvedDependencyInfo.setResolvedArtifact(resolvedArtifact);
            String path = AtlasDepHelper.computeArtifactPath(moduleVersion, resolvedArtifact);
            String name = AtlasDepHelper.computeArtifactName(moduleVersion, resolvedArtifact);
            MavenCoordinates mavenCoordinates = DependencyConvertUtils.convert(resolvedArtifact, !mainBundle ? DependencyConvertUtils.Type.AWB : DependencyConvertUtils.Type.AAR);
            File explodedDir = DependencyLocationManager.getExploreDir(project, mavenCoordinates, resolvedArtifact.getFile(), !mainBundle ? "awb" : resolvedArtifact.getType().toLowerCase(), path);
            resolvedDependencyInfo.setExplodedDir(explodedDir);
            resolvedDependencyInfo.setDependencyName(name);
            if (null == parent) {
                parent = resolvedDependencyInfo;
            } else {
                resolvedDependencyInfo.setParent(parent);
                parent.getChildren().add(resolvedDependencyInfo);
            }
            Set<DependencyResult> dependencyResults = null;
            Set<? extends DependencyResult> dependencies = (Set<DependencyResult>) resolvedComponentResult.getDependencies();
            if (bundleCompileMap.containsKey(resolvedDependencyInfo.getGroup() + ":" + resolvedDependencyInfo.getName())) {
                dependencyResults = bundleCompileMap.get(parent.getGroup() + ":" + parent.getName());
            }
            Set<DependencyResult> combineDependencies = combine(dependencyResults, dependencies);
            if (null != combineDependencies) {
                for (DependencyResult dep : combineDependencies) {
                    if (dep instanceof ResolvedDependencyResult) {
                        ResolvedComponentResult childResolvedComponentResult = ((ResolvedDependencyResult) dep).getSelected();
                        if (isAwbBundle && providedDirectDep.contains(childResolvedComponentResult.getModuleVersion().getGroup() + ":" + childResolvedComponentResult.getModuleVersion().getName())) {
                            continue;
                        }
                        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(parent, ((ResolvedDependencyResult) dep).getSelected(), artifacts, configDependencies, indent + 1, circleDependencyCheck, childNode, dependenciesMap, resolvedDependencies, true);
                        }
                    }
                }
            }
            addDependencyInfo(resolvedDependencyInfo, null, dependenciesMap);
        }
    }
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) 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) MavenCoordinates(com.android.builder.model.MavenCoordinates) CircleDependencyCheck(com.taobao.android.builder.dependency.parser.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)

Aggregations

DependencyResult (org.gradle.api.artifacts.result.DependencyResult)19 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)16 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)10 HashSet (java.util.HashSet)7 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)7 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)7 File (java.io.File)5 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)5 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)5 List (java.util.List)4 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)4 MavenCoordinates (com.android.builder.model.MavenCoordinates)3 ImmutableList (com.google.common.collect.ImmutableList)3 ArrayList (java.util.ArrayList)3 ResolvedVariantResult (org.gradle.api.artifacts.result.ResolvedVariantResult)3 JarDependency (com.android.builder.dependency.JarDependency)2 LibraryDependency (com.android.builder.dependency.LibraryDependency)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 CircleDependencyCheck (com.taobao.android.builder.dependency.CircleDependencyCheck)2