Search in sources :

Example 11 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class VcsDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, VersionSelector rejector, BuildableComponentIdResolveResult result) {
    if (dependency.getSelector() instanceof ModuleComponentSelector) {
        final ModuleComponentSelector depSelector = (ModuleComponentSelector) dependency.getSelector();
        VersionControlSpec spec = vcsResolver.locateVcsFor(depSelector);
        // TODO: Need failure handling, e.g., cannot clone repository
        if (spec != null) {
            VersionControlRepositoryConnection repository = versionControlSystemFactory.create(spec);
            File dependencyWorkingDir;
            try {
                dependencyWorkingDir = workingDirResolver.selectVersion(depSelector, repository);
            } catch (ModuleVersionResolveException e) {
                result.failed(e);
                return;
            }
            if (dependencyWorkingDir == null) {
                result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
                return;
            }
            File buildRootDir = new File(dependencyWorkingDir, spec.getRootDir());
            BuildDefinition buildDefinition = toBuildDefinition((AbstractVersionControlSpec) spec, buildRootDir);
            IncludedBuildState includedBuild = buildRegistry.addImplicitIncludedBuild(buildDefinition);
            Collection<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> moduleToProject = includedBuild.getAvailableModules();
            Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry = CollectionUtils.findFirst(moduleToProject, new Spec<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>>() {

                @Override
                public boolean isSatisfiedBy(Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry) {
                    ModuleVersionIdentifier possibleMatch = entry.left;
                    return depSelector.getGroup().equals(possibleMatch.getGroup()) && depSelector.getModule().equals(possibleMatch.getName());
                }
            });
            if (entry == null) {
                result.failed(new ModuleVersionResolveException(depSelector, () -> spec.getDisplayName() + " did not contain a project publishing the specified dependency."));
            } else {
                LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(entry.right);
                result.resolved(componentMetaData);
            }
        }
    }
}
Also used : VersionControlRepositoryConnection(org.gradle.vcs.internal.VersionControlRepositoryConnection) ModuleVersionNotFoundException(org.gradle.internal.resolve.ModuleVersionNotFoundException) BuildDefinition(org.gradle.api.internal.BuildDefinition) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) VersionControlSpec(org.gradle.vcs.VersionControlSpec) AbstractVersionControlSpec(org.gradle.vcs.internal.spec.AbstractVersionControlSpec) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) IncludedBuildState(org.gradle.internal.build.IncludedBuildState) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) File(java.io.File) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) Pair(org.gradle.internal.Pair)

Example 12 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class DefaultComponentMetadataHandler method processMetadata.

public ModuleComponentResolveMetadata processMetadata(ModuleComponentResolveMetadata metadata) {
    ModuleComponentResolveMetadata updatedMetadata;
    if (rules.isEmpty()) {
        updatedMetadata = metadata;
    } else {
        MutableModuleComponentResolveMetadata mutableMetadata = metadata.asMutable();
        ComponentMetadataDetails details = instantiator.newInstance(ComponentMetadataDetailsAdapter.class, mutableMetadata, instantiator, dependencyMetadataNotationParser, dependencyConstraintMetadataNotationParser);
        processAllRules(metadata, details);
        updatedMetadata = mutableMetadata.asImmutable();
    }
    if (!updatedMetadata.getStatusScheme().contains(updatedMetadata.getStatus())) {
        throw new ModuleVersionResolveException(updatedMetadata.getModuleVersionId(), String.format("Unexpected status '%s' specified for %s. Expected one of: %s", updatedMetadata.getStatus(), updatedMetadata.getId().getDisplayName(), updatedMetadata.getStatusScheme()));
    }
    return updatedMetadata;
}
Also used : MutableModuleComponentResolveMetadata(org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata) MutableModuleComponentResolveMetadata(org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata) ModuleComponentResolveMetadata(org.gradle.internal.component.external.model.ModuleComponentResolveMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ComponentMetadataDetails(org.gradle.api.artifacts.ComponentMetadataDetails)

Example 13 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class EdgeState method calculateTargetConfigurations.

private void calculateTargetConfigurations() {
    targetNodes.clear();
    targetNodeSelectionFailure = null;
    ComponentResolveMetadata targetModuleVersion = targetModuleRevision.getMetadata();
    if (targetModuleVersion == null) {
        // Broken version
        return;
    }
    ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
    List<ConfigurationMetadata> targetConfigurations;
    try {
        targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema());
    } catch (Throwable t) {
        // Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
        return;
    }
    for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
        NodeState targetNodeState = resolveState.getNode(targetModuleRevision, targetConfiguration);
        this.targetNodes.add(targetNodeState);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata)

Example 14 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class NodeState method maybeSubstitute.

/**
 * Execute any dependency substitution rules that apply to this dependency.
 *
 * This may be better done as a decorator on ConfigurationMetadata.getDependencies()
 */
private DependencyState maybeSubstitute(DependencyState dependencyState) {
    DependencySubstitutionApplicator.SubstitutionResult substitutionResult = resolveState.getDependencySubstitutionApplicator().apply(dependencyState.getDependency());
    if (substitutionResult.hasFailure()) {
        dependencyState.failure = new ModuleVersionResolveException(dependencyState.getRequested(), substitutionResult.getFailure());
        return dependencyState;
    }
    DependencySubstitutionInternal details = substitutionResult.getResult();
    if (details != null && details.isUpdated()) {
        return dependencyState.withTarget(details.getTarget(), details.getSelectionDescription());
    }
    return dependencyState;
}
Also used : ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) DependencySubstitutionApplicator(org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DependencySubstitutionApplicator) DependencySubstitutionInternal(org.gradle.api.internal.artifacts.DependencySubstitutionInternal)

Example 15 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class VcsDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint versionConstraint, BuildableComponentIdResolveResult result) {
    if (dependency.getSelector() instanceof ModuleComponentSelector) {
        final ModuleComponentSelector depSelector = (ModuleComponentSelector) dependency.getSelector();
        VersionControlSpec spec = vcsResolver.locateVcsFor(depSelector);
        // TODO: Need failure handling, e.g., cannot clone repository
        if (spec != null) {
            VersionControlSystem versionControlSystem = versionControlSystemFactory.create(spec);
            VersionRef selectedVersion = selectVersion(depSelector, spec, versionControlSystem);
            if (selectedVersion == null) {
                result.failed(new ModuleVersionNotFoundException(depSelector, Collections.singleton(spec.getDisplayName())));
                return;
            }
            File dependencyWorkingDir = new File(populateWorkingDirectory(baseWorkingDir, spec, versionControlSystem, selectedVersion), spec.getRootDir());
            // TODO: This shouldn't rely on the service registry to find NestedBuildFactory
            IncludedBuildRegistry includedBuildRegistry = serviceRegistry.get(IncludedBuildRegistry.class);
            NestedBuildFactory nestedBuildFactory = serviceRegistry.get(NestedBuildFactory.class);
            IncludedBuildInternal includedBuild = includedBuildRegistry.addImplicitBuild(((AbstractVersionControlSpec) spec).getBuildDefinition(dependencyWorkingDir), nestedBuildFactory);
            Collection<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>> moduleToProject = includedBuild.getAvailableModules();
            Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry = CollectionUtils.findFirst(moduleToProject, new Spec<Pair<ModuleVersionIdentifier, ProjectComponentIdentifier>>() {

                @Override
                public boolean isSatisfiedBy(Pair<ModuleVersionIdentifier, ProjectComponentIdentifier> entry) {
                    ModuleVersionIdentifier possibleMatch = entry.left;
                    return depSelector.getGroup().equals(possibleMatch.getGroup()) && depSelector.getModule().equals(possibleMatch.getName());
                }
            });
            if (entry == null) {
                result.failed(new ModuleVersionResolveException(depSelector, spec.getDisplayName() + " did not contain a project publishing the specified dependency."));
            } else {
                LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(entry.right);
                if (componentMetaData == null) {
                    result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(includedBuild.getModel(), entry.right.getProjectPath()), spec.getDisplayName() + " could not be resolved into a usable project."));
                } else {
                    result.resolved(componentMetaData);
                }
                return;
            }
        }
    }
    projectDependencyResolver.resolve(dependency, versionConstraint, result);
}
Also used : VersionRef(org.gradle.vcs.internal.VersionRef) ModuleVersionNotFoundException(org.gradle.internal.resolve.ModuleVersionNotFoundException) VersionControlSystem(org.gradle.vcs.internal.VersionControlSystem) NestedBuildFactory(org.gradle.initialization.NestedBuildFactory) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) IncludedBuildInternal(org.gradle.composite.internal.IncludedBuildInternal) IncludedBuildRegistry(org.gradle.composite.internal.IncludedBuildRegistry) VersionControlSpec(org.gradle.vcs.VersionControlSpec) AbstractVersionControlSpec(org.gradle.vcs.internal.spec.AbstractVersionControlSpec) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) File(java.io.File) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) Pair(org.gradle.internal.Pair)

Aggregations

ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)28 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)7 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)7 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)7 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)5 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)5 ArrayList (java.util.ArrayList)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)4 DependencySubstitutionInternal (org.gradle.api.internal.artifacts.DependencySubstitutionInternal)3 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)3 File (java.io.File)2 ComponentMetadataDetails (org.gradle.api.artifacts.ComponentMetadataDetails)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)2 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)2 DependencySubstitutionApplicator (org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DependencySubstitutionApplicator)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 Pair (org.gradle.internal.Pair)2 ModuleComponentResolveMetadata (org.gradle.internal.component.external.model.ModuleComponentResolveMetadata)2 MutableModuleComponentResolveMetadata (org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata)2