use of org.gradle.internal.fingerprint.DirectorySensitivity 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.internal.fingerprint.DirectorySensitivity 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());
}
}
Aggregations