Search in sources :

Example 6 with ComponentIdentifier

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

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

the class DefaultResolvedArtifactsBuilder method visitArtifacts.

@Override
public void visitArtifacts(DependencyGraphNode from, DependencyGraphNode to, int artifactSetId, ArtifactSet artifacts) {
    // Don't collect build dependencies if not required
    if (!buildProjectDependencies) {
        artifacts = new NoBuildDependenciesArtifactSet(artifacts);
    } else {
        ConfigurationMetadata configurationMetadata = to.getMetadata();
        if (configurationMetadata instanceof LocalConfigurationMetadata) {
            // For a dependency from _another_ build to _this_ build, don't make the artifact buildable
            // Making these artifacts buildable leads to poor error reporting due to direct task dependency cycle (losing the intervening build dependencies)
            ComponentIdentifier incomingId = from.getOwner().getComponentId();
            ComponentIdentifier outgoingId = to.getOwner().getComponentId();
            if (incomingId instanceof ProjectComponentIdentifier && outgoingId instanceof ProjectComponentIdentifier) {
                if (!isCurrentBuild(incomingId) && isCurrentBuild(outgoingId)) {
                    artifacts = new NoBuildDependenciesArtifactSet(artifacts);
                }
            }
        }
    }
    collectArtifacts(artifactSetId, artifacts);
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 8 with ComponentIdentifier

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

the class LocalFileDependencyBackedArtifactSet method startVisit.

@Override
public Completion startVisit(BuildOperationQueue<RunnableBuildOperation> actions, AsyncArtifactListener listener) {
    if (!listener.includeFileDependencies()) {
        return EMPTY_RESULT;
    }
    ComponentIdentifier componentIdentifier = dependencyMetadata.getComponentId();
    if (componentIdentifier != null && !componentFilter.isSatisfiedBy(componentIdentifier)) {
        return EMPTY_RESULT;
    }
    Set<File> files;
    try {
        files = dependencyMetadata.getFiles().getFiles();
    } catch (Throwable throwable) {
        return new BrokenResolvedArtifactSet(throwable);
    }
    List<ResolvedArtifactSet> selectedArtifacts = Lists.newArrayListWithCapacity(files.size());
    for (File file : files) {
        ComponentArtifactIdentifier artifactIdentifier;
        if (componentIdentifier == null) {
            artifactIdentifier = new OpaqueComponentArtifactIdentifier(file);
            if (!componentFilter.isSatisfiedBy(artifactIdentifier.getComponentIdentifier())) {
                continue;
            }
        } else {
            artifactIdentifier = new ComponentFileArtifactIdentifier(componentIdentifier, file.getName());
        }
        AttributeContainerInternal variantAttributes = artifactTypeRegistry.mapAttributesFor(file);
        SingletonFileResolvedVariant variant = new SingletonFileResolvedVariant(file, artifactIdentifier, "local file", variantAttributes, dependencyMetadata);
        selectedArtifacts.add(selector.select(variant));
    }
    return CompositeResolvedArtifactSet.of(selectedArtifacts).startVisit(actions, listener);
}
Also used : OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ComponentFileArtifactIdentifier(org.gradle.internal.component.local.model.ComponentFileArtifactIdentifier) OpaqueComponentArtifactIdentifier(org.gradle.internal.component.local.model.OpaqueComponentArtifactIdentifier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) File(java.io.File) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal)

Example 9 with ComponentIdentifier

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

the class DependencyGraphBuilder method toComponentId.

private ComponentIdentifier toComponentId(ModuleVersionIdentifier id, Map<ModuleVersionIdentifier, ComponentIdentifier> componentIdentifierCache) {
    ComponentIdentifier identifier = componentIdentifierCache.get(id);
    if (identifier == null) {
        identifier = DefaultModuleComponentIdentifier.newId(id);
        componentIdentifierCache.put(id, identifier);
    }
    return identifier;
}
Also used : ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)

Example 10 with ComponentIdentifier

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

the class DefaultArtifactResolutionQuery method createResult.

private ArtifactResolutionResult createResult(ComponentMetaDataResolver componentMetaDataResolver, ArtifactResolver artifactResolver) {
    Set<ComponentResult> componentResults = Sets.newHashSet();
    for (ComponentIdentifier componentId : componentIds) {
        try {
            ComponentIdentifier validId = validateComponentIdentifier(componentId);
            componentResults.add(buildComponentResult(validId, componentMetaDataResolver, artifactResolver));
        } catch (Throwable t) {
            componentResults.add(new DefaultUnresolvedComponentResult(componentId, t));
        }
    }
    return new DefaultArtifactResolutionResult(componentResults);
}
Also used : DefaultUnresolvedComponentResult(org.gradle.api.internal.artifacts.result.DefaultUnresolvedComponentResult) ComponentResult(org.gradle.api.artifacts.result.ComponentResult) DefaultArtifactResolutionResult(org.gradle.api.internal.artifacts.result.DefaultArtifactResolutionResult) 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) DefaultUnresolvedComponentResult(org.gradle.api.internal.artifacts.result.DefaultUnresolvedComponentResult)

Aggregations

ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)18 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)8 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)7 File (java.io.File)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)5 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)4 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)4 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)4 Module (org.gradle.api.internal.artifacts.Module)4 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)3 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)3 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)3 DefaultLocalComponentMetadata (org.gradle.internal.component.local.model.DefaultLocalComponentMetadata)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)2 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)2 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)2 ResolutionResult (org.gradle.api.artifacts.result.ResolutionResult)2 DefaultModuleIdentifier (org.gradle.api.internal.artifacts.DefaultModuleIdentifier)2