Search in sources :

Example 1 with InputFingerprinter

use of org.gradle.internal.execution.fingerprint.InputFingerprinter 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 2 with InputFingerprinter

use of org.gradle.internal.execution.fingerprint.InputFingerprinter in project gradle by gradle.

the class DefaultTransformerInvocationFactory method createInvocation.

@Override
public CacheableInvocation<ImmutableList<File>> createInvocation(Transformer transformer, File inputArtifact, ArtifactTransformDependencies dependencies, TransformationSubject subject, InputFingerprinter inputFingerprinter) {
    ProjectInternal producerProject = determineProducerProject(subject);
    TransformationWorkspaceServices workspaceServices = determineWorkspaceServices(producerProject);
    UnitOfWork execution;
    if (producerProject == null) {
        execution = new ImmutableTransformerExecution(transformer, inputArtifact, dependencies, buildOperationExecutor, fileCollectionFactory, inputFingerprinter, fileSystemAccess, workspaceServices);
    } else {
        execution = new MutableTransformerExecution(transformer, inputArtifact, dependencies, buildOperationExecutor, fileCollectionFactory, inputFingerprinter, workspaceServices);
    }
    return executionEngine.createRequest(execution).withIdentityCache(workspaceServices.getIdentityCache()).getOrDeferExecution(new DeferredExecutionHandler<TransformationResult, CacheableInvocation<ImmutableList<File>>>() {

        @Override
        public CacheableInvocation<ImmutableList<File>> processCachedOutput(Try<TransformationResult> cachedOutput) {
            return CacheableInvocation.cached(mapResult(cachedOutput));
        }

        @Override
        public CacheableInvocation<ImmutableList<File>> processDeferredOutput(Supplier<Try<TransformationResult>> deferredExecution) {
            return CacheableInvocation.nonCached(() -> fireTransformListeners(transformer, subject, () -> mapResult(deferredExecution.get())));
        }

        @Nonnull
        private Try<ImmutableList<File>> mapResult(Try<TransformationResult> cachedOutput) {
            return cachedOutput.map(result -> result.resolveOutputsForInputArtifact(inputArtifact)).mapFailure(failure -> new TransformException(String.format("Execution failed for %s.", execution.getDisplayName()), failure));
        }
    });
}
Also used : InputChangesInternal(org.gradle.internal.execution.history.changes.InputChangesInternal) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ProjectStateRegistry(org.gradle.api.internal.project.ProjectStateRegistry) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) Hashing(org.gradle.internal.hash.Hashing) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) INCREMENTAL(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputPropertyType.INCREMENTAL) FileValueSupplier(org.gradle.internal.execution.fingerprint.InputFingerprinter.FileValueSupplier) Provider(org.gradle.api.provider.Provider) ExecutionEngine(org.gradle.internal.execution.ExecutionEngine) ImmutableList(com.google.common.collect.ImmutableList) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Duration(java.time.Duration) Map(java.util.Map) DeferredExecutionHandler(org.gradle.internal.execution.DeferredExecutionHandler) WorkspaceProvider(org.gradle.internal.execution.workspace.WorkspaceProvider) Providers(org.gradle.api.internal.provider.Providers) DefaultFileNormalizationSpec(org.gradle.internal.execution.fingerprint.impl.DefaultFileNormalizationSpec) Nonnull(javax.annotation.Nonnull) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) Nullable(javax.annotation.Nullable) UnitOfWork(org.gradle.internal.execution.UnitOfWork) FileSystemLocation(org.gradle.api.file.FileSystemLocation) OverridingMethodsMustInvokeSuper(javax.annotation.OverridingMethodsMustInvokeSuper) FileSystemLocationSnapshot(org.gradle.internal.snapshot.FileSystemLocationSnapshot) InputVisitor(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputVisitor) CallableBuildOperation(org.gradle.internal.operations.CallableBuildOperation) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) Hasher(org.gradle.internal.hash.Hasher) BuildOperationDescriptor(org.gradle.internal.operations.BuildOperationDescriptor) FileSystemAccess(org.gradle.internal.vfs.FileSystemAccess) FileCollectionFingerprinter(org.gradle.internal.execution.fingerprint.FileCollectionFingerprinter) HashCode(org.gradle.internal.hash.HashCode) File(java.io.File) CachingDisabledReason(org.gradle.internal.execution.caching.CachingDisabledReason) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) FILE(org.gradle.internal.file.TreeType.FILE) Try(org.gradle.internal.Try) CachingDisabledReasonCategory(org.gradle.internal.execution.caching.CachingDisabledReasonCategory) DIRECTORY(org.gradle.internal.file.TreeType.DIRECTORY) BuildOperationContext(org.gradle.internal.operations.BuildOperationContext) Optional(java.util.Optional) DefaultFileSystemLocation(org.gradle.api.internal.file.DefaultFileSystemLocation) NON_INCREMENTAL(org.gradle.internal.execution.fingerprint.InputFingerprinter.InputPropertyType.NON_INCREMENTAL) UnitOfWork(org.gradle.internal.execution.UnitOfWork) Nonnull(javax.annotation.Nonnull) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Try(org.gradle.internal.Try) File(java.io.File)

Example 3 with InputFingerprinter

use of org.gradle.internal.execution.fingerprint.InputFingerprinter in project gradle by gradle.

the class TransformationStep method createInvocation.

public CacheableInvocation<TransformationSubject> createInvocation(TransformationSubject subjectToTransform, TransformUpstreamDependencies upstreamDependencies, @Nullable NodeExecutionContext context) {
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Transforming {} with {}", subjectToTransform.getDisplayName(), transformer.getDisplayName());
    }
    InputFingerprinter inputFingerprinter = context != null ? context.getService(InputFingerprinter.class) : globalInputFingerprinter;
    Try<ArtifactTransformDependencies> resolvedDependencies = upstreamDependencies.computeArtifacts();
    return resolvedDependencies.map(dependencies -> {
        ImmutableList<File> inputArtifacts = subjectToTransform.getFiles();
        if (inputArtifacts.isEmpty()) {
            return CacheableInvocation.cached(Try.successful(subjectToTransform.createSubjectFromResult(ImmutableList.of())));
        } else if (inputArtifacts.size() > 1) {
            return CacheableInvocation.nonCached(() -> doTransform(subjectToTransform, inputFingerprinter, dependencies, inputArtifacts));
        } else {
            File inputArtifact = inputArtifacts.get(0);
            return transformerInvocationFactory.createInvocation(transformer, inputArtifact, dependencies, subjectToTransform, inputFingerprinter).map(subjectToTransform::createSubjectFromResult);
        }
    }).getOrMapFailure(failure -> CacheableInvocation.cached(Try.failure(failure)));
}
Also used : Logger(org.slf4j.Logger) Action(org.gradle.api.Action) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) TaskDependencyContainer(org.gradle.api.internal.tasks.TaskDependencyContainer) LoggerFactory(org.slf4j.LoggerFactory) File(java.io.File) ImmutableList(com.google.common.collect.ImmutableList) DomainObjectContext(org.gradle.api.internal.DomainObjectContext) NodeExecutionContext(org.gradle.api.internal.tasks.NodeExecutionContext) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) Try(org.gradle.internal.Try) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Nullable(javax.annotation.Nullable) InputFingerprinter(org.gradle.internal.execution.fingerprint.InputFingerprinter) ImmutableList(com.google.common.collect.ImmutableList) File(java.io.File)

Aggregations

Nullable (javax.annotation.Nullable)3 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)3 ImmutableList (com.google.common.collect.ImmutableList)2 File (java.io.File)2 Map (java.util.Map)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 Try (org.gradle.internal.Try)2 FileValueSupplier (org.gradle.internal.execution.fingerprint.InputFingerprinter.FileValueSupplier)2 CurrentFileCollectionFingerprint (org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint)2 ValueSnapshot (org.gradle.internal.snapshot.ValueSnapshot)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Duration (java.time.Duration)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Nonnull (javax.annotation.Nonnull)1 OverridingMethodsMustInvokeSuper (javax.annotation.OverridingMethodsMustInvokeSuper)1 Action (org.gradle.api.Action)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1