Search in sources :

Example 1 with VariantAspect

use of org.gradle.platform.base.internal.VariantAspect 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());
}
Also used : StructSchema(org.gradle.model.internal.manage.schema.StructSchema) ModelType(org.gradle.model.internal.type.ModelType) VariantAspect(org.gradle.platform.base.internal.VariantAspect) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with VariantAspect

use of org.gradle.platform.base.internal.VariantAspect 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()));
    }
}
Also used : StructSchema(org.gradle.model.internal.manage.schema.StructSchema) VariantAspect(org.gradle.platform.base.internal.VariantAspect) ModelMap(org.gradle.model.ModelMap) Map(java.util.Map)

Aggregations

StructSchema (org.gradle.model.internal.manage.schema.StructSchema)2 VariantAspect (org.gradle.platform.base.internal.VariantAspect)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 ModelMap (org.gradle.model.ModelMap)1 ModelType (org.gradle.model.internal.type.ModelType)1