Search in sources :

Example 6 with ModuleVersionResolveException

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

the class CompositeBuildDependencySubstitutions method getReplacementFor.

private ProjectComponentIdentifier getReplacementFor(ModuleComponentSelector selector) {
    ModuleIdentifier candidateId = moduleIdentifierFactory.module(selector.getGroup(), selector.getModule());
    Collection<ProjectComponentIdentifier> providingProjects = replacementMap.get(candidateId);
    if (providingProjects.isEmpty()) {
        LOGGER.info("Found no composite build substitute for module '" + candidateId + "'.");
        return null;
    }
    if (providingProjects.size() == 1) {
        ProjectComponentIdentifier match = providingProjects.iterator().next();
        LOGGER.info("Found project '" + match + "' as substitute for module '" + candidateId + "'.");
        return match;
    }
    SortedSet<String> sortedProjects = Sets.newTreeSet(CollectionUtils.collect(providingProjects, new Transformer<String, ProjectComponentIdentifier>() {

        @Override
        public String transform(ProjectComponentIdentifier projectComponentIdentifier) {
            return projectComponentIdentifier.getDisplayName();
        }
    }));
    String failureMessage = String.format("Module version '%s' is not unique in composite: can be provided by %s.", selector.getDisplayName(), sortedProjects);
    throw new ModuleVersionResolveException(selector, failureMessage);
}
Also used : Transformer(org.gradle.api.Transformer) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 7 with ModuleVersionResolveException

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

the class LocalLibraryDependencyResolver method resolveLibraryAndChooseBinary.

private void resolveLibraryAndChooseBinary(BuildableComponentIdResolveResult result, LibraryComponentSelector selector) {
    final String selectorProjectPath = selector.getProjectPath();
    final String libraryName = selector.getLibraryName();
    final String variant = selector.getVariant();
    LibraryResolutionResult resolutionResult = doResolve(selectorProjectPath, libraryName);
    VariantComponent selectedLibrary = resolutionResult.getSelectedLibrary();
    if (selectedLibrary == null) {
        String message = resolutionResult.toResolutionErrorMessage(selector);
        ModuleVersionResolveException failure = new ModuleVersionResolveException(selector, new LibraryResolveException(message));
        result.failed(failure);
        return;
    }
    Collection<? extends Binary> matchingVariants = chooseMatchingVariants(selectedLibrary, variant);
    if (matchingVariants.isEmpty()) {
        // no compatible variant found
        Iterable<? extends Binary> values = selectedLibrary.getVariants();
        result.failed(new ModuleVersionResolveException(selector, errorMessageBuilder.noCompatibleVariantErrorMessage(libraryName, values)));
    } else if (matchingVariants.size() > 1) {
        result.failed(new ModuleVersionResolveException(selector, errorMessageBuilder.multipleCompatibleVariantsErrorMessage(libraryName, matchingVariants)));
    } else {
        Binary selectedBinary = matchingVariants.iterator().next();
        // TODO:Cedric This is not quite right. We assume that if we are asking for a specific binary, then we resolve to the assembly instead
        // of the jar, but it should be somehow parametrized
        LocalComponentMetadata metaData;
        if (variant == null) {
            metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, false);
        } else {
            metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, true);
        }
        result.resolved(metaData);
    }
}
Also used : LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) VariantComponent(org.gradle.platform.base.VariantComponent) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) LibraryResolveException(org.gradle.language.base.internal.resolve.LibraryResolveException) Binary(org.gradle.platform.base.Binary)

Example 8 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);
        processAllRules(metadata, details);
        updatedMetadata = mutableMetadata.asImmutable();
    }
    if (!updatedMetadata.getStatusScheme().contains(updatedMetadata.getStatus())) {
        throw new ModuleVersionResolveException(updatedMetadata.getId(), String.format("Unexpected status '%s' specified for %s. Expected one of: %s", updatedMetadata.getStatus(), updatedMetadata.getComponentId().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 9 with ModuleVersionResolveException

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

the class ProjectDependencyResolver method resolve.

@Override
public void resolve(ComponentIdentifier identifier, ComponentOverrideMetadata componentOverrideMetadata, BuildableComponentResolveResult result) {
    if (identifier instanceof ProjectComponentIdentifier) {
        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)

Example 10 with ModuleVersionResolveException

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

the class DependencyResultSerializer method read.

public DependencyResult read(Decoder decoder, Map<Long, ComponentSelector> selectors, Map<ComponentSelector, ModuleVersionResolveException> failures) throws IOException {
    Long selectorId = decoder.readSmallLong();
    ComponentSelector requested = selectors.get(selectorId);
    byte resultByte = decoder.readByte();
    if (resultByte == SUCCESSFUL) {
        Long selectedId = decoder.readSmallLong();
        return new DefaultDependencyResult(requested, selectedId, null, null);
    } else if (resultByte == FAILED) {
        ComponentSelectionReason reason = componentSelectionReasonSerializer.read(decoder);
        ModuleVersionResolveException failure = failures.get(requested);
        return new DefaultDependencyResult(requested, null, reason, failure);
    } else {
        throw new IllegalArgumentException("Unknown result type: " + resultByte);
    }
}
Also used : ComponentSelectionReason(org.gradle.api.artifacts.result.ComponentSelectionReason) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException)

Aggregations

ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)10 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)3 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)3 ArrayList (java.util.ArrayList)2 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)2 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)2 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)2 Transformer (org.gradle.api.Transformer)1 ComponentMetadataDetails (org.gradle.api.artifacts.ComponentMetadataDetails)1 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)1 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)1 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)1 ComponentSelectionReason (org.gradle.api.artifacts.result.ComponentSelectionReason)1 DependencySubstitutionInternal (org.gradle.api.internal.artifacts.DependencySubstitutionInternal)1 ModuleComponentResolveMetadata (org.gradle.internal.component.external.model.ModuleComponentResolveMetadata)1 MutableModuleComponentResolveMetadata (org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata)1 LibraryResolveException (org.gradle.language.base.internal.resolve.LibraryResolveException)1 Binary (org.gradle.platform.base.Binary)1 VariantComponent (org.gradle.platform.base.VariantComponent)1