Search in sources :

Example 1 with LibraryResolveException

use of org.gradle.language.base.internal.resolve.LibraryResolveException 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;
    }
    final Collection<? extends Binary> matchingVariants = chooseMatchingVariants(selectedLibrary, variant);
    if (matchingVariants.isEmpty()) {
        // no compatible variant found
        final Iterable<? extends Binary> values = selectedLibrary.getVariants();
        result.failed(new ModuleVersionResolveException(selector, new Factory<String>() {

            @Nullable
            @Override
            public String create() {
                return errorMessageBuilder.noCompatibleVariantErrorMessage(libraryName, values);
            }
        }));
    } else if (matchingVariants.size() > 1) {
        result.failed(new ModuleVersionResolveException(selector, new Factory<String>() {

            @Nullable
            @Override
            public String create() {
                return 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 parameterized
        LocalComponentMetadata metaData;
        if (variant == null) {
            metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, false);
        } else {
            metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, true);
        }
        result.resolved(metaData);
    }
}
Also used : CalculatedValueContainerFactory(org.gradle.internal.model.CalculatedValueContainerFactory) Factory(org.gradle.internal.Factory) LibraryResolveException(org.gradle.language.base.internal.resolve.LibraryResolveException) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) VariantComponent(org.gradle.platform.base.VariantComponent) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) Binary(org.gradle.platform.base.Binary) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 Factory (org.gradle.internal.Factory)1 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)1 CalculatedValueContainerFactory (org.gradle.internal.model.CalculatedValueContainerFactory)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1 LibraryResolveException (org.gradle.language.base.internal.resolve.LibraryResolveException)1 Binary (org.gradle.platform.base.Binary)1 VariantComponent (org.gradle.platform.base.VariantComponent)1