Search in sources :

Example 1 with Try

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

use of org.gradle.internal.Try 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)

Example 3 with Try

use of org.gradle.internal.Try in project gradle by gradle.

the class ResolveCachingStateStep method execute.

@Override
public CachingResult execute(UnitOfWork work, C context) {
    CachingState cachingState;
    if (!buildCache.isEnabled() && !buildScansEnabled) {
        cachingState = BUILD_CACHE_DISABLED_STATE;
    } else if (context.getValidationProblems().isPresent()) {
        cachingState = VALIDATION_FAILED_STATE;
    } else {
        cachingState = context.getBeforeExecutionState().map(beforeExecutionState -> calculateCachingState(work, beforeExecutionState)).orElseGet(() -> calculateCachingStateWithNoCapturedInputs(work));
    }
    cachingState.apply(enabled -> logCacheKey(enabled.getKey(), work), disabled -> logDisabledReasons(disabled.getDisabledReasons(), work));
    UpToDateResult result = delegate.execute(work, new CachingContext() {

        @Override
        public CachingState getCachingState() {
            return cachingState;
        }

        @Override
        public Optional<String> getNonIncrementalReason() {
            return context.getNonIncrementalReason();
        }

        @Override
        public WorkValidationContext getValidationContext() {
            return context.getValidationContext();
        }

        @Override
        public ImmutableSortedMap<String, ValueSnapshot> getInputProperties() {
            return context.getInputProperties();
        }

        @Override
        public ImmutableSortedMap<String, CurrentFileCollectionFingerprint> getInputFileProperties() {
            return context.getInputFileProperties();
        }

        @Override
        public UnitOfWork.Identity getIdentity() {
            return context.getIdentity();
        }

        @Override
        public File getWorkspace() {
            return context.getWorkspace();
        }

        @Override
        public Optional<ExecutionHistoryStore> getHistory() {
            return context.getHistory();
        }

        @Override
        public Optional<PreviousExecutionState> getPreviousExecutionState() {
            return context.getPreviousExecutionState();
        }

        @Override
        public Optional<ValidationResult> getValidationProblems() {
            return context.getValidationProblems();
        }

        @Override
        public Optional<BeforeExecutionState> getBeforeExecutionState() {
            return context.getBeforeExecutionState();
        }
    });
    return new CachingResult() {

        @Override
        public CachingState getCachingState() {
            return cachingState;
        }

        @Override
        public ImmutableList<String> getExecutionReasons() {
            return result.getExecutionReasons();
        }

        @Override
        public Optional<AfterExecutionState> getAfterExecutionState() {
            return result.getAfterExecutionState();
        }

        @Override
        public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
            return result.getReusedOutputOriginMetadata();
        }

        @Override
        public Try<ExecutionResult> getExecutionResult() {
            return result.getExecutionResult();
        }

        @Override
        public Duration getDuration() {
            return result.getDuration();
        }
    };
}
Also used : BeforeExecutionState(org.gradle.internal.execution.history.BeforeExecutionState) CurrentFileCollectionFingerprint(org.gradle.internal.fingerprint.CurrentFileCollectionFingerprint) LoggerFactory(org.slf4j.LoggerFactory) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) PreviousExecutionState(org.gradle.internal.execution.history.PreviousExecutionState) Formatter(java.util.Formatter) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext) CachingStateFactory(org.gradle.internal.execution.caching.CachingStateFactory) ExecutionResult(org.gradle.internal.execution.ExecutionResult) ImmutableList(com.google.common.collect.ImmutableList) ExecutionHistoryStore(org.gradle.internal.execution.history.ExecutionHistoryStore) Duration(java.time.Duration) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) OverlappingOutputs(org.gradle.internal.execution.history.OverlappingOutputs) UnitOfWork(org.gradle.internal.execution.UnitOfWork) Logger(org.slf4j.Logger) ValueSnapshot(org.gradle.internal.snapshot.ValueSnapshot) File(java.io.File) BuildCacheKey(org.gradle.caching.BuildCacheKey) CachingDisabledReason(org.gradle.internal.execution.caching.CachingDisabledReason) List(java.util.List) BuildCacheController(org.gradle.caching.internal.controller.BuildCacheController) NOPLogger(org.slf4j.helpers.NOPLogger) Try(org.gradle.internal.Try) CachingDisabledReasonCategory(org.gradle.internal.execution.caching.CachingDisabledReasonCategory) Optional(java.util.Optional) DefaultCachingStateFactory(org.gradle.internal.execution.caching.impl.DefaultCachingStateFactory) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) CachingState(org.gradle.internal.execution.caching.CachingState) AfterExecutionState(org.gradle.internal.execution.history.AfterExecutionState) Optional(java.util.Optional) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ExecutionResult(org.gradle.internal.execution.ExecutionResult) OriginMetadata(org.gradle.caching.internal.origin.OriginMetadata) File(java.io.File) CachingState(org.gradle.internal.execution.caching.CachingState) WorkValidationContext(org.gradle.internal.execution.WorkValidationContext)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 File (java.io.File)3 Try (org.gradle.internal.Try)3 Duration (java.time.Duration)2 Optional (java.util.Optional)2 Nullable (javax.annotation.Nullable)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 UnitOfWork (org.gradle.internal.execution.UnitOfWork)2 CachingDisabledReason (org.gradle.internal.execution.caching.CachingDisabledReason)2 CachingDisabledReasonCategory (org.gradle.internal.execution.caching.CachingDisabledReasonCategory)2 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)2 OverlappingOutputs (org.gradle.internal.execution.history.OverlappingOutputs)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Formatter (java.util.Formatter)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Nonnull (javax.annotation.Nonnull)1 OverridingMethodsMustInvokeSuper (javax.annotation.OverridingMethodsMustInvokeSuper)1