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();
}
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());
}
}
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();
}
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);
}
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);
}
Aggregations