Search in sources :

Example 1 with BinarySpecInternal

use of org.gradle.platform.base.internal.BinarySpecInternal 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 BinarySpecInternal

use of org.gradle.platform.base.internal.BinarySpecInternal in project gradle by gradle.

the class AbstractBinaryRenderer method renderBuildAbility.

private void renderBuildAbility(BinarySpec binary, TextReportBuilder builder) {
    BinaryBuildAbility buildAbility = ((BinarySpecInternal) binary).getBuildAbility();
    if (!buildAbility.isBuildable()) {
        TreeFormatter formatter = new TreeFormatter();
        buildAbility.explain(formatter);
        builder.item(formatter.toString());
    }
}
Also used : BinarySpecInternal(org.gradle.platform.base.internal.BinarySpecInternal) BinaryBuildAbility(org.gradle.platform.base.internal.BinaryBuildAbility) TreeFormatter(org.gradle.internal.logging.text.TreeFormatter)

Example 3 with BinarySpecInternal

use of org.gradle.platform.base.internal.BinarySpecInternal 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 BinarySpecInternal

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

Example 5 with BinarySpecInternal

use of org.gradle.platform.base.internal.BinarySpecInternal in project gradle by gradle.

the class VariantsMatcher method filterBinaries.

public Collection<? extends BinarySpec> filterBinaries(VariantsMetaData variantsMetaData, Collection<BinarySpec> binaries) {
    if (binaries.isEmpty()) {
        return binaries;
    }
    Set<String> resolveDimensions = variantsMetaData.getNonNullVariantAxes();
    TreeMultimap<String, VariantValue> selectedVariants = TreeMultimap.create(String.CASE_INSENSITIVE_ORDER, SPEC_COMPARATOR);
    Set<BinarySpec> removedSpecs = Sets.newHashSet();
    for (BinarySpec binarySpec : binaries) {
        if (binarySpecType.isAssignableFrom(binarySpec.getClass())) {
            VariantsMetaData binaryVariants = DefaultVariantsMetaData.extractFrom(binarySpec, schemaStore.getSchema(((BinarySpecInternal) binarySpec).getPublicType()));
            Set<String> commonsDimensions = Sets.intersection(resolveDimensions, binaryVariants.getNonNullVariantAxes());
            Set<String> incompatibleDimensionTypes = VariantsMetaDataHelper.determineAxesWithIncompatibleTypes(variantsMetaData, binaryVariants, commonsDimensions);
            if (incompatibleDimensionTypes.isEmpty()) {
                for (String dimension : commonsDimensions) {
                    Class<?> dimensionType = variantsMetaData.getVariantAxisType(dimension).getConcreteClass();
                    boolean isStringType = String.class == dimensionType;
                    Object requestedValue = isStringType ? variantsMetaData.getValueAsString(dimension) : variantsMetaData.getValueAsType(Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension);
                    Object binaryValue = isStringType ? binaryVariants.getValueAsString(dimension) : binaryVariants.getValueAsType(Cast.<Class<? extends Named>>uncheckedCast(dimensionType), dimension);
                    VariantAxisCompatibility<Object> selector = createSelector(requestedValue);
                    if (selector.isCompatibleWithRequirement(requestedValue, binaryValue)) {
                        VariantValue value = new VariantValue(binaryValue, binarySpec);
                        SortedSet<VariantValue> variantValues = selectedVariants.get(dimension);
                        for (VariantValue variantValue : variantValues) {
                            // and incrementally build a list of binaries which are excluded because of a better match
                            if (selector.betterFit(requestedValue, variantValue.value, binaryValue)) {
                                // the new value is a better fit than the old one
                                removedSpecs.add(variantValue.spec);
                            } else if (selector.betterFit(requestedValue, binaryValue, variantValue.value)) {
                                // the old value is a better fit than the new one, let's ignore the new one altogether
                                removedSpecs.add(value.spec);
                            }
                        }
                        selectedVariants.put(dimension, value);
                    } else {
                        removedSpecs.add(binarySpec);
                    }
                }
            }
        }
    }
    Set<BinarySpec> union = null;
    for (String dimension : selectedVariants.keySet()) {
        Set<BinarySpec> variantValues = ImmutableSet.copyOf(Iterables.transform(selectedVariants.get(dimension), VariantValue.SPEC_FUNCTION));
        union = union == null ? variantValues : Sets.union(union, variantValues);
    }
    return union == null ? Collections.<BinarySpec>emptySet() : Sets.difference(union, removedSpecs);
}
Also used : Named(org.gradle.api.Named) BinarySpecInternal(org.gradle.platform.base.internal.BinarySpecInternal) BinarySpec(org.gradle.platform.base.BinarySpec)

Aggregations

BinarySpecInternal (org.gradle.platform.base.internal.BinarySpecInternal)8 BinarySpec (org.gradle.platform.base.BinarySpec)4 Binary (org.gradle.platform.base.Binary)3 Joiner (com.google.common.base.Joiner)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 DefaultTask (org.gradle.api.DefaultTask)1 Named (org.gradle.api.Named)1 Task (org.gradle.api.Task)1 LibraryBinaryIdentifier (org.gradle.api.artifacts.component.LibraryBinaryIdentifier)1 RepositoryHandler (org.gradle.api.artifacts.dsl.RepositoryHandler)1 ArtifactDependencyResolver (org.gradle.api.internal.artifacts.ArtifactDependencyResolver)1 ImmutableModuleIdentifierFactory (org.gradle.api.internal.artifacts.ImmutableModuleIdentifierFactory)1 ResolutionAwareRepository (org.gradle.api.internal.artifacts.repositories.ResolutionAwareRepository)1 AttributesSchemaInternal (org.gradle.api.internal.attributes.AttributesSchemaInternal)1 BuildIdentity (org.gradle.initialization.BuildIdentity)1 TreeFormatter (org.gradle.internal.logging.text.TreeFormatter)1 BuildOperationExecutor (org.gradle.internal.operations.BuildOperationExecutor)1 JvmBinarySpecInternal (org.gradle.jvm.internal.JvmBinarySpecInternal)1 JvmTestSuiteBinarySpecInternal (org.gradle.jvm.test.internal.JvmTestSuiteBinarySpecInternal)1