use of org.gradle.model.internal.manage.schema.StructSchema in project gradle by gradle.
the class DefaultVariantsMetaData method extractFrom.
public static VariantsMetaData extractFrom(BinarySpec binarySpec, ModelSchema<?> binarySpecSchema) {
Map<String, Object> variants = Maps.newLinkedHashMap();
ImmutableMap.Builder<String, ModelType<?>> dimensionTypesBuilder = ImmutableMap.builder();
if (binarySpecSchema instanceof StructSchema) {
VariantAspect variantAspect = ((StructSchema<?>) binarySpecSchema).getAspect(VariantAspect.class);
if (variantAspect != null) {
for (ModelProperty<?> property : variantAspect.getDimensions()) {
// note: it's not the role of this class to validate that the annotation is properly used, that
// is to say only on a getter returning String or a Named instance, so we trust the result of
// the call
Object value = property.getPropertyValue(binarySpec);
variants.put(property.getName(), value);
dimensionTypesBuilder.put(property.getName(), property.getType());
}
}
}
return new DefaultVariantsMetaData(Collections.unmodifiableMap(variants), dimensionTypesBuilder.build());
}
use of org.gradle.model.internal.manage.schema.StructSchema in project gradle by gradle.
the class AbstractBinaryRenderer method renderVariants.
protected void renderVariants(T binary, TextReportBuilder builder) {
ModelSchema<?> schema = schemaStore.getSchema(((BinarySpecInternal) binary).getPublicType());
if (!(schema instanceof StructSchema)) {
return;
}
Map<String, Object> variants = Maps.newTreeMap();
VariantAspect variantAspect = ((StructSchema<?>) schema).getAspect(VariantAspect.class);
if (variantAspect != null) {
for (ModelProperty<?> property : variantAspect.getDimensions()) {
variants.put(property.getName(), property.getPropertyValue(binary));
}
}
for (Map.Entry<String, Object> variant : variants.entrySet()) {
String variantName = GUtil.toWords(variant.getKey());
builder.item(variantName, RendererUtils.displayValueOf(variant.getValue()));
}
}
Aggregations