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