Search in sources :

Example 1 with PropertyValue

use of org.gradle.api.internal.tasks.properties.PropertyValue 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 PropertyValue

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

the class DefaultTransformer method fingerprintParameters.

private static void fingerprintParameters(DocumentationRegistry documentationRegistry, InputFingerprinter inputFingerprinter, FileCollectionFactory fileCollectionFactory, PropertyWalker propertyWalker, Hasher hasher, Object parameterObject, boolean cacheable) {
    DefaultTypeValidationContext validationContext = DefaultTypeValidationContext.withoutRootType(documentationRegistry, cacheable);
    InputFingerprinter.Result result = inputFingerprinter.fingerprintInputProperties(ImmutableSortedMap.of(), ImmutableSortedMap.of(), ImmutableSortedMap.of(), ImmutableSortedMap.of(), visitor -> propertyWalker.visitProperties(parameterObject, validationContext, new PropertyVisitor.Adapter() {

        @Override
        public void visitInputProperty(String propertyName, PropertyValue value, boolean optional) {
            try {
                Object preparedValue = InputParameterUtils.prepareInputParameterValue(value);
                if (preparedValue == null && !optional) {
                    reportValueNotSet(propertyName, validationContext);
                }
                visitor.visitInputProperty(propertyName, () -> preparedValue);
            } catch (Throwable e) {
                throw new InvalidUserDataException(String.format("Error while evaluating property '%s' of %s", propertyName, getParameterObjectDisplayName(parameterObject)), e);
            }
        }

        @Override
        public void visitInputFileProperty(String propertyName, boolean optional, boolean skipWhenEmpty, DirectorySensitivity directorySensitivity, LineEndingSensitivity lineEndingNormalization, boolean incremental, @Nullable Class<? extends FileNormalizer> fileNormalizer, PropertyValue value, InputFilePropertyType filePropertyType) {
            validateInputFileNormalizer(propertyName, fileNormalizer, cacheable, validationContext);
            visitor.visitInputFileProperty(propertyName, incremental ? InputFingerprinter.InputPropertyType.INCREMENTAL : InputFingerprinter.InputPropertyType.NON_INCREMENTAL, new FileValueSupplier(value, fileNormalizer == null ? AbsolutePathInputNormalizer.class : fileNormalizer, directorySensitivity, lineEndingNormalization, () -> FileParameterUtils.resolveInputFileValue(fileCollectionFactory, filePropertyType, value)));
        }

        @Override
        public void visitOutputFileProperty(String propertyName, boolean optional, PropertyValue value, OutputFilePropertyType filePropertyType) {
            validationContext.visitPropertyProblem(problem -> problem.withId(ValidationProblemId.ARTIFACT_TRANSFORM_SHOULD_NOT_DECLARE_OUTPUT).reportAs(Severity.ERROR).forProperty(propertyName).withDescription("declares an output").happensBecause("is annotated with an output annotation").addPossibleSolution("Remove the output property and use the TransformOutputs parameter from transform(TransformOutputs) instead").documentedAt("validation_problems", "artifact_transform_should_not_declare_output"));
        }
    }));
    ImmutableMap<String, Severity> validationMessages = validationContext.getProblems();
    if (!validationMessages.isEmpty()) {
        throw new DefaultMultiCauseException(String.format(validationMessages.size() == 1 ? "A problem was found with the configuration of the artifact transform parameter %s." : "Some problems were found with the configuration of the artifact transform parameter %s.", getParameterObjectDisplayName(parameterObject)), validationMessages.keySet().stream().sorted().map(InvalidUserDataException::new).collect(Collectors.toList()));
    }
    for (Map.Entry<String, ValueSnapshot> entry : result.getValueSnapshots().entrySet()) {
        hasher.putString(entry.getKey());
        entry.getValue().appendToHasher(hasher);
    }
    for (Map.Entry<String, CurrentFileCollectionFingerprint> entry : result.getFileFingerprints().entrySet()) {
        hasher.putString(entry.getKey());
        hasher.putHash(entry.getValue().getHash());
    }
}
Also used : LineEndingSensitivity(org.gradle.internal.fingerprint.LineEndingSensitivity) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) FileValueSupplier(org.gradle.internal.execution.fingerprint.InputFingerprinter.FileValueSupplier) FileNormalizer(org.gradle.api.tasks.FileNormalizer) OutputFilePropertyType(org.gradle.api.internal.tasks.properties.OutputFilePropertyType) DefaultTypeValidationContext(org.gradle.internal.reflect.DefaultTypeValidationContext) DirectorySensitivity(org.gradle.internal.fingerprint.DirectorySensitivity) PropertyValue(org.gradle.api.internal.tasks.properties.PropertyValue) InputFilePropertyType(org.gradle.api.internal.tasks.properties.InputFilePropertyType) Severity(org.gradle.internal.reflect.validation.Severity) DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) InvalidUserDataException(org.gradle.api.InvalidUserDataException) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) DslObject(org.gradle.api.internal.plugins.DslObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Nullable(javax.annotation.Nullable)

Example 3 with PropertyValue

use of org.gradle.api.internal.tasks.properties.PropertyValue 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)

Aggregations

PropertyValue (org.gradle.api.internal.tasks.properties.PropertyValue)3 BeanPropertyContext (org.gradle.api.internal.tasks.properties.BeanPropertyContext)2 TypeMetadata (org.gradle.api.internal.tasks.properties.TypeMetadata)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 DslObject (org.gradle.api.internal.plugins.DslObject)1 InputFilePropertyType (org.gradle.api.internal.tasks.properties.InputFilePropertyType)1 OutputFilePropertyType (org.gradle.api.internal.tasks.properties.OutputFilePropertyType)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 FileNormalizer (org.gradle.api.tasks.FileNormalizer)1 DefaultMultiCauseException (org.gradle.internal.exceptions.DefaultMultiCauseException)1 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)1 FileValueSupplier (org.gradle.internal.execution.fingerprint.InputFingerprinter.FileValueSupplier)1 CurrentFileCollectionFingerprint (org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint)1 DirectorySensitivity (org.gradle.internal.fingerprint.DirectorySensitivity)1