Search in sources :

Example 1 with Binary

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

the class DefaultLibraryResolutionErrorMessageBuilder method multipleCompatibleVariantsErrorMessage.

@Override
public String multipleCompatibleVariantsErrorMessage(String libraryName, Iterable<? extends Binary> binaries) {
    List<String> variantDescriptors = new ArrayList<String>();
    StringBuilder variantDescriptor = new StringBuilder();
    for (Binary binary : binaries) {
        BinarySpec variant = (BinarySpec) binary;
        variantDescriptor.setLength(0);
        boolean first = true;
        variantDescriptor.append("    - ").append(variant.getDisplayName()).append(" [");
        VariantsMetaData metaData = DefaultVariantsMetaData.extractFrom(variant, schemaStore.getSchema(((BinarySpecInternal) variant).getPublicType()));
        for (String axis : metaData.getNonNullVariantAxes()) {
            if (first) {
                first = false;
            } else {
                variantDescriptor.append(", ");
            }
            variantDescriptor.append(renderAxisName(axis)).append(":'").append(metaData.getValueAsString(axis)).append("'");
        }
        variantDescriptor.append(TextUtil.toPlatformLineSeparators("]\n"));
        variantDescriptors.add(variantDescriptor.toString());
    }
    StringBuilder sb = new StringBuilder(String.format(TextUtil.toPlatformLineSeparators("Multiple compatible variants found for library '%s':\n"), libraryName));
    for (String descriptor : variantDescriptors) {
        sb.append(descriptor);
    }
    return sb.toString();
}
Also used : BinarySpecInternal(org.gradle.platform.base.internal.BinarySpecInternal) ArrayList(java.util.ArrayList) Binary(org.gradle.platform.base.Binary) BinarySpec(org.gradle.platform.base.BinarySpec)

Example 2 with Binary

use of org.gradle.platform.base.Binary 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 3 with Binary

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

the class DefaultLibraryResolutionErrorMessageBuilder method noCompatibleVariantErrorMessage.

@Override
public String noCompatibleVariantErrorMessage(String libraryName, Iterable<? extends Binary> allBinaries) {
    HashMultimap<String, String> variantAxisMessages = HashMultimap.create();
    for (Binary binary : allBinaries) {
        BinarySpec spec = (BinarySpec) binary;
        VariantsMetaData md = DefaultVariantsMetaData.extractFrom(spec, schemaStore.getSchema(((BinarySpecInternal) spec).getPublicType()));
        Set<String> variantAxesWithIncompatibleTypes = VariantsMetaDataHelper.determineAxesWithIncompatibleTypes(variantsMetaData, md, variantAxesToResolve);
        for (String variantAxis : variantAxesToResolve) {
            String value = md.getValueAsString(variantAxis);
            if (value != null) {
                String message = String.format("'%s'", value);
                if (variantAxesWithIncompatibleTypes.contains(variantAxis)) {
                    message = String.format("%s but with an incompatible type (expected '%s' was '%s')", message, variantsMetaData.getVariantAxisType(variantAxis).getConcreteClass().getName(), md.getVariantAxisType(variantAxis).getConcreteClass().getName());
                }
                variantAxisMessages.put(variantAxis, message);
            }
        }
    }
    Joiner joiner = Joiner.on(", ").skipNulls();
    StringBuilder error = new StringBuilder(String.format(TextUtil.toPlatformLineSeparators("Cannot find a compatible variant for library '%s'.\n"), libraryName));
    for (String variantAxis : variantAxesToResolve) {
        String axisName = renderAxisName(variantAxis);
        error.append("    Required ").append(axisName).append(" '").append(variantsMetaData.getValueAsString(variantAxis)).append("'");
        Set<String> available = new TreeSet<String>(variantAxisMessages.get(variantAxis));
        if (!available.isEmpty()) {
            error.append(", available: ").append(joiner.join(available)).append("\n");
        } else {
            error.append(" but no compatible variant was found\n");
        }
    }
    return error.toString();
}
Also used : Joiner(com.google.common.base.Joiner) BinarySpecInternal(org.gradle.platform.base.internal.BinarySpecInternal) TreeSet(java.util.TreeSet) Binary(org.gradle.platform.base.Binary) BinarySpec(org.gradle.platform.base.BinarySpec)

Example 4 with Binary

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

the class JvmVariantSelector method selectVariants.

@Override
public Collection<? extends BinarySpec> selectVariants(VariantComponent componentSpec, @Nullable String requestedVariant) {
    // We know that Jvm binaries are BinarySpec instances
    Collection<BinarySpec> allBinaries = Lists.newArrayList();
    for (Binary binary : componentSpec.getVariants()) {
        allBinaries.add((BinarySpec) binary);
    }
    if (requestedVariant != null) {
        // Choose explicit variant
        for (Binary binarySpec : allBinaries) {
            BinarySpecInternal binary = (BinarySpecInternal) binarySpec;
            LibraryBinaryIdentifier id = binary.getId();
            if (Objects.equal(requestedVariant, id.getVariant())) {
                return Collections.singleton(binary);
            }
        }
        return Collections.emptySet();
    }
    return variantsMatcher.filterBinaries(variantsMetaData, allBinaries);
}
Also used : BinarySpecInternal(org.gradle.platform.base.internal.BinarySpecInternal) LibraryBinaryIdentifier(org.gradle.api.artifacts.component.LibraryBinaryIdentifier) BinarySpec(org.gradle.platform.base.BinarySpec) Binary(org.gradle.platform.base.Binary)

Aggregations

Binary (org.gradle.platform.base.Binary)4 BinarySpec (org.gradle.platform.base.BinarySpec)3 BinarySpecInternal (org.gradle.platform.base.internal.BinarySpecInternal)3 Joiner (com.google.common.base.Joiner)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 LibraryBinaryIdentifier (org.gradle.api.artifacts.component.LibraryBinaryIdentifier)1 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)1 ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)1 LibraryResolveException (org.gradle.language.base.internal.resolve.LibraryResolveException)1 VariantComponent (org.gradle.platform.base.VariantComponent)1