Search in sources :

Example 1 with VariantComponent

use of org.gradle.platform.base.VariantComponent in project gradle by gradle.

the class LocalLibraryDependencyResolver method doResolve.

private LibraryResolutionResult doResolve(String selectorProjectPath, String libraryName) {
    try {
        ModelRegistry projectModel = projectModelResolver.resolveProjectModel(selectorProjectPath);
        Collection<VariantComponent> candidates = libraryResolver.resolveCandidates(projectModel, libraryName);
        if (candidates.isEmpty()) {
            return LibraryResolutionResult.emptyResolutionResult(binaryType);
        }
        return LibraryResolutionResult.of(binaryType, candidates, libraryName, binaryPredicate);
    } catch (UnknownProjectException e) {
        return LibraryResolutionResult.projectNotFound(binaryType);
    }
}
Also used : ModelRegistry(org.gradle.model.internal.registry.ModelRegistry) VariantComponent(org.gradle.platform.base.VariantComponent) UnknownProjectException(org.gradle.api.UnknownProjectException)

Example 2 with VariantComponent

use of org.gradle.platform.base.VariantComponent 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)

Example 3 with VariantComponent

use of org.gradle.platform.base.VariantComponent in project gradle by gradle.

the class LibraryResolutionResult method resolve.

private void resolve(String libraryName) {
    if (libraryName == null) {
        VariantComponent singleMatchingLibrary = getSingleMatchingLibrary();
        if (singleMatchingLibrary == null) {
            return;
        }
        libraryName = singleMatchingLibrary.getName();
    }
    selectedLibrary = libsMatchingRequirements.get(libraryName);
    nonMatchingLibrary = libsNotMatchingRequirements.get(libraryName);
}
Also used : VariantComponent(org.gradle.platform.base.VariantComponent)

Example 4 with VariantComponent

use of org.gradle.platform.base.VariantComponent in project gradle by gradle.

the class LibraryResolutionResult method toResolutionErrorMessage.

public String toResolutionErrorMessage(LibraryComponentSelector selector) {
    List<String> candidateLibraries = formatLibraryNames(getCandidateLibraries());
    String projectPath = selector.getProjectPath();
    String libraryName = selector.getLibraryName();
    StringBuilder sb = new StringBuilder("Project '").append(projectPath).append("'");
    if (libraryName == null || !hasLibraries()) {
        if (isProjectNotFound()) {
            sb.append(" not found.");
        } else if (!hasLibraries()) {
            sb.append(" doesn't define any library.");
        } else {
            sb.append(" contains more than one library. Please select one of ");
            Joiner.on(", ").appendTo(sb, candidateLibraries);
        }
    } else {
        VariantComponent notMatchingRequirements = getNonMatchingLibrary();
        if (notMatchingRequirements != null) {
            sb.append(" contains a library named '").append(libraryName).append("' but it doesn't have any binary of type ").append(binaryType.getSimpleName());
        } else {
            sb.append(" does not contain library '").append(libraryName).append("'. Did you want to use ");
            if (candidateLibraries.size() == 1) {
                sb.append(candidateLibraries.get(0));
            } else {
                sb.append("one of ");
                Joiner.on(", ").appendTo(sb, candidateLibraries);
            }
            sb.append("?");
        }
    }
    return sb.toString();
}
Also used : VariantComponent(org.gradle.platform.base.VariantComponent)

Example 5 with VariantComponent

use of org.gradle.platform.base.VariantComponent in project gradle by gradle.

the class LibraryResolutionResult method of.

public static LibraryResolutionResult of(Class<? extends Binary> binaryType, Collection<? extends VariantComponent> libraries, String libraryName, Predicate<? super VariantComponent> libraryFilter) {
    LibraryResolutionResult result = new LibraryResolutionResult(binaryType);
    for (VariantComponent librarySpec : libraries) {
        if (libraryFilter.apply(librarySpec)) {
            result.libsMatchingRequirements.put(librarySpec.getName(), librarySpec);
        } else {
            result.libsNotMatchingRequirements.put(librarySpec.getName(), librarySpec);
        }
    }
    result.resolve(libraryName);
    return result;
}
Also used : VariantComponent(org.gradle.platform.base.VariantComponent)

Aggregations

VariantComponent (org.gradle.platform.base.VariantComponent)5 Nullable (javax.annotation.Nullable)1 UnknownProjectException (org.gradle.api.UnknownProjectException)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 ModelRegistry (org.gradle.model.internal.registry.ModelRegistry)1 Binary (org.gradle.platform.base.Binary)1