Search in sources :

Example 26 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.

the class DefaultConfiguration method toRootComponentMetaData.

public ComponentResolveMetadata toRootComponentMetaData() {
    Module module = getModule();
    ComponentIdentifier componentIdentifier = componentIdentifierFactory.createComponentIdentifier(module);
    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();
    DefaultLocalComponentMetadata metaData = new DefaultLocalComponentMetadata(moduleVersionIdentifier, componentIdentifier, module.getStatus(), schema);
    configurationComponentMetaDataBuilder.addConfigurations(metaData, configurationsProvider.getAll());
    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 27 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.

the class IdeDependenciesExtractor method extractRepoFileDependencies.

public Collection<IdeExtendedRepoFileDependency> extractRepoFileDependencies(DependencyHandler dependencyHandler, Collection<Configuration> plusConfigurations, Collection<Configuration> minusConfigurations, boolean downloadSources, boolean downloadJavadoc) {
    // can have multiple IDE dependencies with same component identifier (see GRADLE-1622)
    Multimap<ComponentIdentifier, IdeExtendedRepoFileDependency> resolvedDependenciesComponentMap = LinkedHashMultimap.create();
    for (IdeExtendedRepoFileDependency dep : resolvedExternalDependencies(plusConfigurations, minusConfigurations)) {
        resolvedDependenciesComponentMap.put(toComponentIdentifier(dep.getId()), dep);
    }
    List<Class<? extends Artifact>> artifactTypes = new ArrayList<Class<? extends Artifact>>(2);
    if (downloadSources) {
        artifactTypes.add(SourcesArtifact.class);
    }
    if (downloadJavadoc) {
        artifactTypes.add(JavadocArtifact.class);
    }
    downloadAuxiliaryArtifacts(dependencyHandler, resolvedDependenciesComponentMap, artifactTypes);
    Collection<UnresolvedIdeRepoFileDependency> unresolvedDependencies = unresolvedExternalDependencies(plusConfigurations, minusConfigurations);
    Collection<IdeExtendedRepoFileDependency> resolvedDependencies = resolvedDependenciesComponentMap.values();
    Collection<IdeExtendedRepoFileDependency> resolvedAndUnresolved = new ArrayList<IdeExtendedRepoFileDependency>(unresolvedDependencies.size() + resolvedDependencies.size());
    resolvedAndUnresolved.addAll(resolvedDependencies);
    resolvedAndUnresolved.addAll(unresolvedDependencies);
    return resolvedAndUnresolved;
}
Also used : IdeExtendedRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.IdeExtendedRepoFileDependency) UnresolvedIdeRepoFileDependency(org.gradle.plugins.ide.internal.resolver.model.UnresolvedIdeRepoFileDependency) ArrayList(java.util.ArrayList) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) JavadocArtifact(org.gradle.language.java.artifact.JavadocArtifact) SourcesArtifact(org.gradle.language.base.artifact.SourcesArtifact) Artifact(org.gradle.api.component.Artifact)

Example 28 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier 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 29 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier 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) {
        ResolvedVariantResult selectedVariant = dependency.getSelectedVariant();
        // 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, selectedVariant));
                current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null, selectedVariant);
                out.add(current);
            } else {
                current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), getReasonDescription(dependency.getReason()), selectedVariant);
                out.add(current);
            }
        } else if (!current.getRequested().equals(dependency.getRequested())) {
            current = new RequestedVersion(dependency.getRequested(), dependency.getActual(), dependency.isResolvable(), null, selectedVariant);
            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) ResolvedVariantResult(org.gradle.api.artifacts.result.ResolvedVariantResult) 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 30 with ComponentIdentifier

use of org.gradle.api.artifacts.component.ComponentIdentifier in project gradle by gradle.

the class ShortCircuitEmptyConfigurationResolver method emptyGraph.

private void emptyGraph(ConfigurationInternal configuration, ResolverResults results, boolean verifyLocking) {
    if (verifyLocking && configuration.getResolutionStrategy().isDependencyLockingEnabled()) {
        DependencyLockingProvider dependencyLockingProvider = configuration.getResolutionStrategy().getDependencyLockingProvider();
        DependencyLockingState lockingState = dependencyLockingProvider.loadLockState(configuration.getName());
        if (lockingState.mustValidateLockState() && !lockingState.getLockedDependencies().isEmpty()) {
            // Invalid lock state, need to do a real resolution to gather locking failures
            delegate.resolveGraph(configuration, results);
            return;
        }
        dependencyLockingProvider.persistResolvedDependencies(configuration.getName(), Collections.emptySet(), Collections.emptySet());
    }
    Module module = configuration.getModule();
    ModuleVersionIdentifier id = moduleIdentifierFactory.moduleWithVersion(module);
    ComponentIdentifier componentIdentifier = componentIdentifierFactory.createComponentIdentifier(module);
    ResolutionResult emptyResult = DefaultResolutionResultBuilder.empty(id, componentIdentifier, configuration.getAttributes());
    ResolvedLocalComponentsResult emptyProjectResult = new ResolvedLocalComponentsResultGraphVisitor(thisBuild);
    results.graphResolved(emptyResult, emptyProjectResult, EmptyResults.INSTANCE);
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DependencyLockingProvider(org.gradle.api.internal.artifacts.dsl.dependencies.DependencyLockingProvider) DependencyLockingState(org.gradle.api.internal.artifacts.dsl.dependencies.DependencyLockingState) 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

ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)39 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)17 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)15 File (java.io.File)14 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)10 OpaqueComponentArtifactIdentifier (org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier)7 NonNull (com.android.annotations.NonNull)6 ArtifactCollection (org.gradle.api.artifacts.ArtifactCollection)6 ResolvedArtifactResult (org.gradle.api.artifacts.result.ResolvedArtifactResult)6 FilteredArtifactCollection (com.android.build.gradle.internal.dependency.FilteredArtifactCollection)5 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)5 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)5 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)5 Module (org.gradle.api.internal.artifacts.Module)5 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)4 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)4 ResolutionResult (org.gradle.api.artifacts.result.ResolutionResult)4 ResolvedVariantResult (org.gradle.api.artifacts.result.ResolvedVariantResult)4 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)4 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)4