Search in sources :

Example 6 with ModuleVersionIdentifier

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

the class DependencyManager 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) {
    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);
    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 path = computeArtifactPath(moduleVersion, resolvedArtifact);
        String name = computeArtifactName(moduleVersion, resolvedArtifact);
        File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-" + resolvedArtifact.getType().toLowerCase() + "/" + path);
        resolvedDependencyInfo.setExplodedDir(explodedDir);
        resolvedDependencyInfo.setDependencyName(name);
        if (null == parent) {
            parent = resolvedDependencyInfo;
        } else {
            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);
                }
            }
        }
        resolvedDependencyContainer.addDependency(resolvedDependencyInfo);
    }
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) DependencyResult(org.gradle.api.artifacts.result.DependencyResult) ResolvedDependencyResult(org.gradle.api.artifacts.result.ResolvedDependencyResult) UnresolvedDependencyResult(org.gradle.api.artifacts.result.UnresolvedDependencyResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) 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 7 with ModuleVersionIdentifier

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

the class ResolvedDependencyContainer method addResolvedDependencyInfo.

/**
     * 通过递归的方式进行依赖的解析
     *
     * @param parentDependency
     * @param resolvedDependenciesMap
     */
private void addResolvedDependencyInfo(ResolvedDependencyInfo parentDependency, Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap) {
    int indent = parentDependency.getIndent();
    ModuleVersionIdentifier identifier = parentDependency.getModuleVersionIdentifier();
    Collection<ResolvedDependencyInfo> childDependencies = resolvedDependenciesMap.get(identifier);
    //TODO here
    for (ResolvedDependencyInfo childDependency : childDependencies) {
        if (childDependency.getIndent() > indent) {
            //                System.out.println(parentDependency + " indent " + indent + "->" + childDependency +  " indent " + childDependency.getIndent());
            parentDependency.getChildren().add(childDependency);
            if (childDependency.getIndent() <= 1) {
                addResolvedDependencyInfo(childDependency, resolvedDependenciesMap);
            }
        }
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier)

Example 8 with ModuleVersionIdentifier

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

the class ResolvedDependencyContainer method reslovedDependencies.

/**
     * 进行依赖仲裁
     */
public synchronized DependencyTree reslovedDependencies() {
    if (inited) {
        return dependencyTree;
    }
    if (!conflictDependencies.isEmpty()) {
        for (String str : conflictDependencies) {
            logger.error(str);
        }
        if (null == forceMap) {
            throw new GradleException("conflict dependencis");
        } else {
            AtlasBuildContext.conflictDependencies = conflictDependencies;
        }
    }
    // 仲裁后的依赖关系.结构为父类-子类
    Multimap<ModuleVersionIdentifier, ResolvedDependencyInfo> resolvedDependenciesMap = LinkedHashMultimap.create();
    Map<ModuleVersionIdentifier, ResolvedDependencyInfo> directDependencies = new HashMap<ModuleVersionIdentifier, ResolvedDependencyInfo>();
    for (String key : dependenciesMap.keySet()) {
        Collection<ResolvedDependencyInfo> dependencyLevels = dependenciesMap.get(key);
        if (dependencyLevels.size() > 0) {
            List<ResolvedDependencyInfo> resolvedDependencyInfos = Lists.newArrayList();
            resolvedDependencyInfos.addAll(dependencyLevels);
            Collections.sort(resolvedDependencyInfos);
            ResolvedDependencyInfo resolvedDependencyInfo = resolvedDependencyInfos.get(0);
            ResolvedDependencyInfo parent = resolvedDependencyInfo.getParent();
            //对于放入resolvedDependenciesMap中的信息不需要加入children
            resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
            if (null != parent) {
                //如果存在的父依赖,就把当前依赖加入到父依赖的子依赖中
                resolvedDependenciesMap.put(parent.getModuleVersionIdentifier(), resolvedDependencyInfo);
            } else {
                //如果没有父依赖,就是一级依赖
                directDependencies.put(resolvedDependencyInfo.getModuleVersionIdentifier(), resolvedDependencyInfo);
            }
        }
    }
    // 开始构建依赖树
    dependencyTree.clear();
    for (ModuleVersionIdentifier key : directDependencies.keySet()) {
        ResolvedDependencyInfo resolvedDependencyInfo = directDependencies.get(key);
        //清空children
        resolvedDependencyInfo.setChildren(Lists.<ResolvedDependencyInfo>newArrayList());
        addResolvedDependencyInfo(resolvedDependencyInfo, resolvedDependenciesMap);
        dependencyTree.addDependency(resolvedDependencyInfo);
    }
    inited = true;
    return dependencyTree;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) HashMap(java.util.HashMap) GradleException(org.gradle.api.GradleException)

Example 9 with ModuleVersionIdentifier

use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.

the class DefaultIdeDependencyResolver method getIdeRepoFileDependencies.

/**
     * Gets IDE repository file dependencies.
     *
     * @param configuration Configuration
     * @return IDE repository file dependencies
     */
public List<IdeExtendedRepoFileDependency> getIdeRepoFileDependencies(Configuration configuration) {
    ResolutionResult result = getIncomingResolutionResult(configuration);
    final Set<ResolvedComponentResult> resolvedRepoFileComponents = CollectionUtils.filter(result.getAllComponents(), new Spec<ResolvedComponentResult>() {

        @Override
        public boolean isSatisfiedBy(ResolvedComponentResult element) {
            return element.getId() instanceof ModuleComponentIdentifier;
        }
    });
    Set<ModuleVersionIdentifier> mappedResolvedDependencies = mapResolvedDependencies(resolvedRepoFileComponents);
    Set<ResolvedArtifact> artifacts = getExternalArtifacts(configuration);
    List<IdeExtendedRepoFileDependency> externalDependencies = new ArrayList<IdeExtendedRepoFileDependency>();
    for (ResolvedArtifact artifact : artifacts) {
        if (mappedResolvedDependencies.contains(artifact.getModuleVersion().getId())) {
            IdeExtendedRepoFileDependency ideRepoFileDependency = new IdeExtendedRepoFileDependency(artifact.getFile());
            ideRepoFileDependency.setId(artifact.getModuleVersion().getId());
            externalDependencies.add(ideRepoFileDependency);
        }
    }
    return externalDependencies;
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ArrayList(java.util.ArrayList) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) IdeExtendedRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult)

Example 10 with ModuleVersionIdentifier

use of org.gradle.api.artifacts.ModuleVersionIdentifier in project gradle by gradle.

the class DefaultIvyPublication method addProjectDependency.

private void addProjectDependency(ProjectDependency dependency, String confMapping) {
    ModuleVersionIdentifier identifier = projectDependencyResolver.resolve(dependency);
    ivyDependencies.add(new DefaultIvyDependency(identifier.getGroup(), identifier.getName(), identifier.getVersion(), confMapping, dependency.isTransitive(), Collections.<DependencyArtifact>emptyList(), dependency.getExcludeRules()));
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultModuleVersionIdentifier(org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier) DefaultIvyDependency(org.gradle.api.publish.ivy.internal.dependency.DefaultIvyDependency) DependencyArtifact(org.gradle.api.artifacts.DependencyArtifact)

Aggregations

ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)27 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)7 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)7 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)7 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)6 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 List (java.util.List)4 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)4 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)4 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)4 ImmutableList (com.google.common.collect.ImmutableList)3 Configuration (org.gradle.api.artifacts.Configuration)3 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)3 DefaultModuleVersionIdentifier (org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier)3 Module (org.gradle.api.internal.artifacts.Module)3 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)3 JarDependency (com.android.builder.dependency.JarDependency)2