Search in sources :

Example 1 with TypeMetadata

use of org.gradle.api.internal.tasks.properties.TypeMetadata in project gradle by gradle.

the class AbstractNestedRuntimeBeanNode method visitProperties.

protected void visitProperties(PropertyVisitor visitor, final Queue<RuntimeBeanNode<?>> queue, final RuntimeBeanNodeFactory nodeFactory, TypeValidationContext validationContext) {
    TypeMetadata typeMetadata = getTypeMetadata();
    typeMetadata.visitValidationFailures(getPropertyName(), validationContext);
    for (PropertyMetadata propertyMetadata : typeMetadata.getPropertiesMetadata()) {
        PropertyAnnotationHandler annotationHandler = typeMetadata.getAnnotationHandlerFor(propertyMetadata);
        if (annotationHandler.shouldVisit(visitor)) {
            String propertyName = getQualifiedPropertyName(propertyMetadata.getPropertyName());
            PropertyValue value = new BeanPropertyValue(getBean(), propertyMetadata.getGetterMethod());
            annotationHandler.visitPropertyValue(propertyName, value, propertyMetadata, visitor, new BeanPropertyContext() {

                @Override
                public void addNested(String propertyName, Object bean) {
                    queue.add(nodeFactory.create(AbstractNestedRuntimeBeanNode.this, propertyName, bean));
                }
            });
        }
    }
}
Also used : TypeMetadata(org.gradle.api.internal.tasks.properties.TypeMetadata) PropertyAnnotationHandler(org.gradle.api.internal.tasks.properties.annotations.PropertyAnnotationHandler) BeanPropertyContext(org.gradle.api.internal.tasks.properties.BeanPropertyContext) PropertyMetadata(org.gradle.internal.reflect.PropertyMetadata) PropertyValue(org.gradle.api.internal.tasks.properties.PropertyValue)

Example 2 with TypeMetadata

use of org.gradle.api.internal.tasks.properties.TypeMetadata in project gradle by gradle.

the class DefaultTransformationRegistrationFactory method create.

@Override
public ArtifactTransformRegistration create(ImmutableAttributes from, ImmutableAttributes to, Class<? extends TransformAction<?>> implementation, @Nullable TransformParameters parameterObject) {
    TypeMetadata actionMetadata = actionMetadataStore.getTypeMetadata(implementation);
    boolean cacheable = implementation.isAnnotationPresent(CacheableTransform.class);
    DefaultTypeValidationContext validationContext = DefaultTypeValidationContext.withoutRootType(documentationRegistry, cacheable);
    actionMetadata.visitValidationFailures(null, validationContext);
    // Should retain this on the metadata rather than calculate on each invocation
    Class<? extends FileNormalizer> inputArtifactNormalizer = null;
    Class<? extends FileNormalizer> dependenciesNormalizer = null;
    DirectorySensitivity artifactDirectorySensitivity = DirectorySensitivity.DEFAULT;
    DirectorySensitivity dependenciesDirectorySensitivity = DirectorySensitivity.DEFAULT;
    LineEndingSensitivity artifactLineEndingSensitivity = LineEndingSensitivity.DEFAULT;
    LineEndingSensitivity dependenciesLineEndingSensitivity = LineEndingSensitivity.DEFAULT;
    for (PropertyMetadata propertyMetadata : actionMetadata.getPropertiesMetadata()) {
        Class<? extends Annotation> propertyType = propertyMetadata.getPropertyType();
        if (propertyType.equals(InputArtifact.class)) {
            // Should ask the annotation handler to figure this out instead
            NormalizerCollectingVisitor visitor = new NormalizerCollectingVisitor();
            actionMetadata.getAnnotationHandlerFor(propertyMetadata).visitPropertyValue(propertyMetadata.getPropertyName(), null, propertyMetadata, visitor, null);
            inputArtifactNormalizer = visitor.normalizer;
            artifactDirectorySensitivity = visitor.directorySensitivity;
            artifactLineEndingSensitivity = visitor.lineEndingSensitivity;
            DefaultTransformer.validateInputFileNormalizer(propertyMetadata.getPropertyName(), inputArtifactNormalizer, cacheable, validationContext);
        } else if (propertyType.equals(InputArtifactDependencies.class)) {
            NormalizerCollectingVisitor visitor = new NormalizerCollectingVisitor();
            actionMetadata.getAnnotationHandlerFor(propertyMetadata).visitPropertyValue(propertyMetadata.getPropertyName(), null, propertyMetadata, visitor, null);
            dependenciesNormalizer = visitor.normalizer;
            dependenciesDirectorySensitivity = visitor.directorySensitivity;
            dependenciesLineEndingSensitivity = visitor.lineEndingSensitivity;
            DefaultTransformer.validateInputFileNormalizer(propertyMetadata.getPropertyName(), dependenciesNormalizer, cacheable, validationContext);
        }
    }
    ImmutableMap<String, Severity> validationMessages = validationContext.getProblems();
    if (!validationMessages.isEmpty()) {
        String formatString = validationMessages.size() == 1 ? "A problem was found with the configuration of %s." : "Some problems were found with the configuration of %s.";
        throw new DefaultMultiCauseException(String.format(formatString, ModelType.of(implementation).getDisplayName()), validationMessages.keySet().stream().sorted().map(InvalidUserDataException::new).collect(Collectors.toList()));
    }
    Transformer transformer = new DefaultTransformer(implementation, parameterObject, from, FileParameterUtils.normalizerOrDefault(inputArtifactNormalizer), FileParameterUtils.normalizerOrDefault(dependenciesNormalizer), cacheable, artifactDirectorySensitivity, dependenciesDirectorySensitivity, artifactLineEndingSensitivity, dependenciesLineEndingSensitivity, buildOperationExecutor, classLoaderHierarchyHasher, isolatableFactory, fileCollectionFactory, fileLookup, parametersPropertyWalker, actionInstantiationScheme, owner, calculatedValueContainerFactory, internalServices, documentationRegistry);
    return new DefaultArtifactTransformRegistration(from, to, new TransformationStep(transformer, transformerInvocationFactory, owner, inputFingerprinter));
}
Also used : LineEndingSensitivity(org.gradle.internal.fingerprint.LineEndingSensitivity) TypeMetadata(org.gradle.api.internal.tasks.properties.TypeMetadata) InputArtifactDependencies(org.gradle.api.artifacts.transform.InputArtifactDependencies) DirectorySensitivity(org.gradle.internal.fingerprint.DirectorySensitivity) Severity(org.gradle.internal.reflect.validation.Severity) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DefaultTypeValidationContext(org.gradle.internal.reflect.DefaultTypeValidationContext) PropertyMetadata(org.gradle.internal.reflect.PropertyMetadata)

Example 3 with TypeMetadata

use of org.gradle.api.internal.tasks.properties.TypeMetadata in project gradle by gradle.

the class AbstractNestedRuntimeBeanNode method visitProperties.

public void visitProperties(PropertyVisitor visitor, PropertySpecFactory specFactory, final Queue<RuntimeBeanNode<?>> queue, final RuntimeBeanNodeFactory nodeFactory) {
    TypeMetadata typeMetadata = getTypeMetadata();
    for (final PropertyMetadata propertyMetadata : typeMetadata.getPropertiesMetadata()) {
        PropertyValueVisitor propertyValueVisitor = propertyMetadata.getPropertyValueVisitor();
        if (propertyValueVisitor == null) {
            continue;
        }
        String propertyName = getQualifiedPropertyName(propertyMetadata.getFieldName());
        PropertyValue propertyValue = new DefaultPropertyValue(propertyName, propertyMetadata.getAnnotations(), getBean(), propertyMetadata.getMethod());
        propertyValueVisitor.visitPropertyValue(propertyValue, visitor, specFactory, new BeanPropertyContext() {

            @Override
            public void addNested(String propertyName, Object bean) {
                queue.add(nodeFactory.create(AbstractNestedRuntimeBeanNode.this, propertyName, bean));
            }
        });
    }
}
Also used : TypeMetadata(org.gradle.api.internal.tasks.properties.TypeMetadata) BeanPropertyContext(org.gradle.api.internal.tasks.properties.BeanPropertyContext) PropertyMetadata(org.gradle.api.internal.tasks.properties.PropertyMetadata) PropertyValue(org.gradle.api.internal.tasks.properties.PropertyValue) PropertyValueVisitor(org.gradle.api.internal.tasks.properties.PropertyValueVisitor)

Example 4 with TypeMetadata

use of org.gradle.api.internal.tasks.properties.TypeMetadata in project gradle by gradle.

the class RuntimeBeanNodeFactory method create.

public RuntimeBeanNode<?> create(RuntimeBeanNode parentNode, String propertyName, Object bean) {
    parentNode.checkCycles(propertyName, bean);
    TypeMetadata typeMetadata = metadataStore.getTypeMetadata(bean.getClass());
    if (!typeMetadata.hasAnnotatedProperties()) {
        if (bean instanceof Map<?, ?>) {
            return new MapRuntimeBeanNode(parentNode, propertyName, (Map<?, ?>) bean, typeMetadata);
        }
        if (bean instanceof Iterable<?>) {
            return new IterableRuntimeBeanNode(parentNode, propertyName, (Iterable<?>) bean, typeMetadata);
        }
    }
    return new NestedRuntimeBeanNode(parentNode, propertyName, bean, typeMetadata);
}
Also used : TypeMetadata(org.gradle.api.internal.tasks.properties.TypeMetadata) Map(java.util.Map)

Aggregations

TypeMetadata (org.gradle.api.internal.tasks.properties.TypeMetadata)4 BeanPropertyContext (org.gradle.api.internal.tasks.properties.BeanPropertyContext)2 PropertyValue (org.gradle.api.internal.tasks.properties.PropertyValue)2 PropertyMetadata (org.gradle.internal.reflect.PropertyMetadata)2 Map (java.util.Map)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 InputArtifactDependencies (org.gradle.api.artifacts.transform.InputArtifactDependencies)1 PropertyMetadata (org.gradle.api.internal.tasks.properties.PropertyMetadata)1 PropertyValueVisitor (org.gradle.api.internal.tasks.properties.PropertyValueVisitor)1 PropertyAnnotationHandler (org.gradle.api.internal.tasks.properties.annotations.PropertyAnnotationHandler)1 DefaultMultiCauseException (org.gradle.internal.exceptions.DefaultMultiCauseException)1 DirectorySensitivity (org.gradle.internal.fingerprint.DirectorySensitivity)1 LineEndingSensitivity (org.gradle.internal.fingerprint.LineEndingSensitivity)1 DefaultTypeValidationContext (org.gradle.internal.reflect.DefaultTypeValidationContext)1 Severity (org.gradle.internal.reflect.validation.Severity)1