Search in sources :

Example 1 with NodeExecutionContext

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

ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 Nullable (javax.annotation.Nullable)1 Action (org.gradle.api.Action)1 DomainObjectContext (org.gradle.api.internal.DomainObjectContext)1 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 NodeExecutionContext (org.gradle.api.internal.tasks.NodeExecutionContext)1 TaskDependencyContainer (org.gradle.api.internal.tasks.TaskDependencyContainer)1 TaskDependencyResolveContext (org.gradle.api.internal.tasks.TaskDependencyResolveContext)1 Try (org.gradle.internal.Try)1 InputFingerprinter (org.gradle.internal.execution.fingerprint.InputFingerprinter)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1