Search in sources :

Example 11 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 12 with ModuleVersionIdentifier

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

the class RejectedModuleMessageBuilder method pathTo.

private static Collection<String> pathTo(EdgeState edge) {
    List<List<EdgeState>> acc = Lists.newArrayListWithExpectedSize(1);
    pathTo(edge, Lists.<EdgeState>newArrayList(), acc, Sets.<NodeState>newHashSet());
    List<String> result = Lists.newArrayListWithCapacity(acc.size());
    for (List<EdgeState> path : acc) {
        EdgeState target = Iterators.getLast(path.iterator());
        StringBuilder sb = new StringBuilder();
        if (target.getSelector().getDependencyMetadata().isPending()) {
            sb.append("Constraint path ");
        } else {
            sb.append("Dependency path ");
        }
        for (EdgeState e : path) {
            ModuleVersionIdentifier id = e.getFrom().getResolvedConfigurationId().getId();
            sb.append('\'').append(id).append('\'');
            sb.append(" --> ");
        }
        ModuleIdentifier moduleId = edge.getTargetComponent().getModule().getId();
        sb.append('\'').append(moduleId.getGroup()).append(':').append(moduleId.getName()).append('\'');
        result.add(sb.toString());
    }
    return result;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) List(java.util.List) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 13 with ModuleVersionIdentifier

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

the class DefaultRootComponentMetadataBuilder method toRootComponentMetaData.

@Override
public ComponentResolveMetadata toRootComponentMetaData() {
    Module module = metaDataProvider.getModule();
    ComponentIdentifier componentIdentifier = componentIdentifierFactory.createComponentIdentifier(module);
    DefaultLocalComponentMetadata metaData = holder.tryCached(componentIdentifier);
    if (metaData != null) {
        return metaData;
    }
    ModuleVersionIdentifier moduleVersionIdentifier = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getName(), module.getVersion());
    ProjectInternal project = projectFinder.findProject(module.getProjectPath());
    AttributesSchemaInternal schema = project == null ? null : (AttributesSchemaInternal) project.getDependencies().getAttributesSchema();
    metaData = new DefaultLocalComponentMetadata(moduleVersionIdentifier, componentIdentifier, module.getStatus(), schema);
    localComponentMetadataBuilder.addConfigurations(metaData, configurationsProvider.getAll());
    holder.cachedValue = metaData;
    return metaData;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultLocalComponentMetadata(org.gradle.internal.component.local.model.DefaultLocalComponentMetadata) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) Module(org.gradle.api.internal.artifacts.Module) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal)

Example 14 with ModuleVersionIdentifier

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

the class DefaultComponentSelectorConverter method getSelector.

@Override
public ModuleVersionSelector getSelector(ComponentSelector selector) {
    if (selector instanceof ModuleComponentSelector) {
        return DefaultModuleVersionSelector.newSelector((ModuleComponentSelector) selector);
    }
    if (selector instanceof ProjectComponentSelector) {
        ProjectComponentSelector projectSelector = (ProjectComponentSelector) selector;
        ProjectComponentIdentifier projectId = componentIdentifierFactory.createProjectComponentIdentifier(projectSelector);
        LocalComponentMetadata projectComponent = localComponentRegistry.getComponent(projectId);
        if (projectComponent != null) {
            ModuleVersionIdentifier moduleVersionId = projectComponent.getModuleVersionId();
            return DefaultModuleVersionSelector.newSelector(moduleVersionId.getGroup(), moduleVersionId.getName(), moduleVersionId.getVersion());
        }
    }
    if (selector instanceof LibraryComponentSelector) {
        LibraryComponentSelector libraryComponentSelector = (LibraryComponentSelector) selector;
        String libraryName = GUtil.elvis(libraryComponentSelector.getLibraryName(), "");
        return DefaultModuleVersionSelector.newSelector(libraryComponentSelector.getProjectPath(), libraryName, "undefined");
    }
    return UNKNOWN_MODULE_VERSION_SELECTOR;
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) LibraryComponentSelector(org.gradle.api.artifacts.component.LibraryComponentSelector)

Example 15 with ModuleVersionIdentifier

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

the class ShortCircuitEmptyConfigurationResolver method emptyGraph.

private void emptyGraph(ConfigurationInternal configuration, ResolverResults results) {
    Module module = configuration.getModule();
    ModuleVersionIdentifier id = moduleIdentifierFactory.moduleWithVersion(module);
    ComponentIdentifier componentIdentifier = componentIdentifierFactory.createComponentIdentifier(module);
    ResolutionResult emptyResult = DefaultResolutionResultBuilder.empty(id, componentIdentifier);
    ResolvedLocalComponentsResult emptyProjectResult = new ResolvedLocalComponentsResultGraphVisitor(thisBuild.getCurrentBuild());
    results.graphResolved(emptyResult, emptyProjectResult, new EmptyResults());
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ResolutionResult(org.gradle.api.artifacts.result.ResolutionResult) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) Module(org.gradle.api.internal.artifacts.Module) ResolvedLocalComponentsResult(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedLocalComponentsResult) ResolvedLocalComponentsResultGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedLocalComponentsResultGraphVisitor)

Aggregations

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