Search in sources :

Example 36 with ProjectComponentIdentifier

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

the class DefaultConfigurationResolver method resolveGraph.

@Override
public void resolveGraph(ConfigurationInternal configuration, ResolverResults results) {
    List<ResolutionAwareRepository> resolutionAwareRepositories = getRepositories();
    StoreSet stores = storeFactory.createStoreSet();
    BinaryStore oldModelStore = stores.nextBinaryStore();
    Store<TransientConfigurationResults> oldModelCache = stores.oldModelCache();
    TransientConfigurationResultsBuilder oldTransientModelBuilder = new TransientConfigurationResultsBuilder(oldModelStore, oldModelCache, moduleIdentifierFactory, buildOperationExecutor);
    DefaultResolvedConfigurationBuilder oldModelBuilder = new DefaultResolvedConfigurationBuilder(oldTransientModelBuilder);
    ResolvedConfigurationDependencyGraphVisitor oldModelVisitor = new ResolvedConfigurationDependencyGraphVisitor(oldModelBuilder);
    BinaryStore newModelStore = stores.nextBinaryStore();
    Store<ResolvedComponentResult> newModelCache = stores.newModelCache();
    StreamingResolutionResultBuilder newModelBuilder = new StreamingResolutionResultBuilder(newModelStore, newModelCache, moduleIdentifierFactory, attributeContainerSerializer, attributeDesugaring, componentSelectionDescriptorFactory);
    ResolvedLocalComponentsResultGraphVisitor localComponentsVisitor = new ResolvedLocalComponentsResultGraphVisitor(currentBuild);
    ResolutionStrategyInternal resolutionStrategy = configuration.getResolutionStrategy();
    DefaultResolvedArtifactsBuilder artifactsBuilder = new DefaultResolvedArtifactsBuilder(buildProjectDependencies, resolutionStrategy.getSortOrder());
    FileDependencyCollectingGraphVisitor fileDependencyVisitor = new FileDependencyCollectingGraphVisitor();
    ResolutionFailureCollector failureCollector = new ResolutionFailureCollector(componentSelectorConverter);
    DependencyGraphVisitor graphVisitor = new CompositeDependencyGraphVisitor(newModelBuilder, localComponentsVisitor, failureCollector);
    ImmutableList.Builder<DependencyArtifactsVisitor> visitors = new ImmutableList.Builder<>();
    visitors.add(oldModelVisitor);
    visitors.add(fileDependencyVisitor);
    visitors.add(artifactsBuilder);
    if (resolutionStrategy.getConflictResolution() == ConflictResolution.strict) {
        ProjectComponentIdentifier projectId = configuration.getModule().getProjectId();
        // projectId is null for DefaultModule used in settings
        String projectPath = projectId != null ? projectId.getProjectPath() : "";
        visitors.add(new FailOnVersionConflictArtifactsVisitor(projectPath, configuration.getName()));
    }
    DependencyLockingArtifactVisitor lockingVisitor = null;
    if (resolutionStrategy.isDependencyLockingEnabled()) {
        lockingVisitor = new DependencyLockingArtifactVisitor(configuration.getName(), resolutionStrategy.getDependencyLockingProvider());
        visitors.add(lockingVisitor);
    } else {
        resolutionStrategy.confirmUnlockedConfigurationResolved(configuration.getName());
    }
    ImmutableList<DependencyArtifactsVisitor> allVisitors = visitors.build();
    CompositeDependencyArtifactsVisitor artifactsVisitor = new CompositeDependencyArtifactsVisitor(allVisitors);
    resolver.resolve(configuration, resolutionAwareRepositories, metadataHandler, Specs.satisfyAll(), graphVisitor, artifactsVisitor, attributesSchema, artifactTypeRegistry, true);
    VisitedArtifactsResults artifactsResults = artifactsBuilder.complete();
    VisitedFileDependencyResults fileDependencyResults = fileDependencyVisitor.complete();
    ResolvedGraphResults graphResults = oldModelBuilder.complete();
    // Append to failures for locking and fail on version conflict
    Set<UnresolvedDependency> extraFailures = lockingVisitor == null ? Collections.emptySet() : lockingVisitor.collectLockingFailures();
    Set<UnresolvedDependency> failures = failureCollector.complete(extraFailures);
    results.graphResolved(newModelBuilder.complete(extraFailures), localComponentsVisitor, new BuildDependenciesOnlyVisitedArtifactSet(failures, artifactsResults, artifactTransforms, configuration.getDependenciesResolver()));
    results.retainState(new ArtifactResolveState(graphResults, artifactsResults, fileDependencyResults, failures, oldTransientModelBuilder));
    if (!results.hasError() && failures.isEmpty()) {
        artifactsVisitor.complete();
    }
}
Also used : TransientConfigurationResultsBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResultsBuilder) ResolvedConfigurationDependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.ResolvedConfigurationDependencyGraphVisitor) ResolutionAwareRepository(org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository) StreamingResolutionResultBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.StreamingResolutionResultBuilder) ImmutableList(com.google.common.collect.ImmutableList) DefaultResolvedArtifactsBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultResolvedArtifactsBuilder) StreamingResolutionResultBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.StreamingResolutionResultBuilder) TransientConfigurationResultsBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResultsBuilder) DefaultResolvedConfigurationBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.DefaultResolvedConfigurationBuilder) CompositeDependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.CompositeDependencyGraphVisitor) CompositeDependencyArtifactsVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.CompositeDependencyArtifactsVisitor) DefaultResolvedArtifactsBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultResolvedArtifactsBuilder) DependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.DependencyGraphVisitor) CompositeDependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.CompositeDependencyGraphVisitor) ResolvedConfigurationDependencyGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.ResolvedConfigurationDependencyGraphVisitor) CompositeDependencyArtifactsVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.CompositeDependencyArtifactsVisitor) DependencyArtifactsVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DependencyArtifactsVisitor) StoreSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.store.StoreSet) FileDependencyCollectingGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.result.FileDependencyCollectingGraphVisitor) BinaryStore(org.gradle.cache.internal.BinaryStore) VisitedFileDependencyResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.VisitedFileDependencyResults) ResolvedGraphResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.ResolvedGraphResults) FailOnVersionConflictArtifactsVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.conflicts.FailOnVersionConflictArtifactsVisitor) ResolvedLocalComponentsResultGraphVisitor(org.gradle.api.internal.artifacts.ivyservice.resolveengine.projectresult.ResolvedLocalComponentsResultGraphVisitor) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) UnresolvedDependency(org.gradle.api.artifacts.UnresolvedDependency) VisitedArtifactsResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.VisitedArtifactsResults) DefaultResolvedConfigurationBuilder(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.DefaultResolvedConfigurationBuilder) ResolutionFailureCollector(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.ResolutionFailureCollector) BuildDependenciesOnlyVisitedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.BuildDependenciesOnlyVisitedArtifactSet) TransientConfigurationResults(org.gradle.api.internal.artifacts.ivyservice.resolveengine.oldresult.TransientConfigurationResults) DependencyLockingArtifactVisitor(org.gradle.internal.locking.DependencyLockingArtifactVisitor) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult) ResolutionStrategyInternal(org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal) DependencyVerificationOverride(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.verification.DependencyVerificationOverride)

Example 37 with ProjectComponentIdentifier

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

the class DefaultRootComponentMetadataBuilder method buildRootComponentMetadata.

private DefaultLocalComponentMetadata buildRootComponentMetadata(final Module module, final ComponentIdentifier componentIdentifier) {
    final ModuleVersionIdentifier moduleVersionIdentifier = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getName(), module.getVersion());
    ProjectComponentIdentifier projectId = module.getProjectId();
    if (projectId != null) {
        ProjectState projectState = projectStateRegistry.stateFor(projectId);
        if (!projectState.hasMutableState()) {
            throw new IllegalStateException("Thread should hold project lock for " + projectId);
        }
        return projectState.fromMutableState(project -> {
            AttributesSchemaInternal schema = (AttributesSchemaInternal) project.getDependencies().getAttributesSchema();
            return getRootComponentMetadata(module, componentIdentifier, moduleVersionIdentifier, schema, dependencyLockingProvider);
        });
    } else {
        return getRootComponentMetadata(module, componentIdentifier, moduleVersionIdentifier, null, dependencyLockingProvider);
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ProjectState(org.gradle.api.internal.project.ProjectState) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal)

Example 38 with ProjectComponentIdentifier

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

the class ProjectArtifactResolver method resolveArtifact.

@Override
public void resolveArtifact(ComponentArtifactMetadata artifact, ModuleSources moduleSources, BuildableArtifactResolveResult result) {
    LocalComponentArtifactMetadata projectArtifact = (LocalComponentArtifactMetadata) artifact;
    ProjectComponentIdentifier projectId = (ProjectComponentIdentifier) artifact.getComponentId();
    File localArtifactFile = projectStateRegistry.stateFor(projectId).fromMutableState(p -> projectArtifact.getFile());
    if (localArtifactFile != null) {
        result.resolved(localArtifactFile);
    } else {
        result.notFound(projectArtifact.getId());
    }
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) File(java.io.File) LocalComponentArtifactMetadata(org.gradle.internal.component.local.model.LocalComponentArtifactMetadata)

Example 39 with ProjectComponentIdentifier

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

the class ProjectDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, @Nullable VersionSelector rejector, BuildableComponentIdResolveResult result) {
    if (dependency.getSelector() instanceof ProjectComponentSelector) {
        ProjectComponentSelector selector = (ProjectComponentSelector) dependency.getSelector();
        ProjectComponentIdentifier projectId = componentIdentifierFactory.createProjectComponentIdentifier(selector);
        LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(projectId);
        if (componentMetaData == null) {
            result.failed(new ModuleVersionResolveException(selector, () -> projectId + " not found."));
        } else {
            if (rejector != null && rejector.accept(componentMetaData.getModuleVersionId().getVersion())) {
                result.rejected(projectId, componentMetaData.getModuleVersionId());
            } else {
                result.resolved(componentMetaData);
            }
        }
    }
}
Also used : ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 40 with ProjectComponentIdentifier

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

the class ProjectDependencyResolver method resolve.

@Override
public void resolve(ComponentIdentifier identifier, ComponentOverrideMetadata componentOverrideMetadata, final BuildableComponentResolveResult result) {
    if (isProjectModule(identifier)) {
        ProjectComponentIdentifier projectId = (ProjectComponentIdentifier) identifier;
        LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(projectId);
        if (componentMetaData == null) {
            result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(projectId), () -> projectId + " not found."));
        } else {
            result.resolved(componentMetaData);
        }
    }
}
Also used : LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Aggregations

ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)52 File (java.io.File)12 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)12 ComponentIdentifier (org.gradle.api.artifacts.component.ComponentIdentifier)9 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)9 ResolvedComponentResult (org.gradle.api.artifacts.result.ResolvedComponentResult)7 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)7 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)6 DefaultLocalComponentMetadata (org.gradle.internal.component.local.model.DefaultLocalComponentMetadata)6 Project (org.gradle.api.Project)5 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)5 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)5 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)5 DependencyResult (org.gradle.api.artifacts.result.DependencyResult)5 ResolvedDependencyResult (org.gradle.api.artifacts.result.ResolvedDependencyResult)5 LocalComponentRegistry (org.gradle.api.internal.artifacts.ivyservice.projectmodule.LocalComponentRegistry)5 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)4 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)3 UnresolvedDependencyResult (org.gradle.api.artifacts.result.UnresolvedDependencyResult)3