org.gradle.api.internal.tasks.DefaultTaskOutputs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.tasks;
import com.google.common.base.Function;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Callables;
import groovy.lang.Closure;
import org.gradle.api.Task;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.TaskExecutionHistory;
import org.gradle.api.internal.TaskInternal;
import org.gradle.api.internal.TaskOutputsInternal;
import org.gradle.api.internal.changedetection.state.TaskFilePropertyCompareStrategy;
import org.gradle.api.internal.changedetection.state.TaskFilePropertyPathSensitivity;
import org.gradle.api.internal.file.CompositeFileCollection;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.internal.file.collections.FileCollectionResolveContext;
import org.gradle.api.internal.file.collections.SimpleFileCollection;
import org.gradle.api.internal.tasks.CacheableTaskOutputFilePropertySpec.OutputType;
import org.gradle.api.specs.AndSpec;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskOutputFilePropertyBuilder;
import org.gradle.api.tasks.TaskOutputs;
import org.gradle.util.DeprecationLogger;
import java.io.File;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.concurrent.Callable;
import static org.gradle.api.internal.changedetection.state.TaskFilePropertyCompareStrategy.OUTPUT;
import static org.gradle.util.GUtil.uncheckedCall;
public class DefaultTaskOutputs implements TaskOutputsInternal {
private final FileCollection allOutputFiles;
private AndSpec upToDateSpec = AndSpec.empty();
private AndSpec cacheIfSpec = AndSpec.empty();
private TaskExecutionHistory history;
private final List filePropertiesInternal = Lists.newArrayList();
private SortedSet fileProperties;
private final FileResolver resolver;
private final TaskInternal task;
private final TaskMutator taskMutator;
public DefaultTaskOutputs(FileResolver resolver, final TaskInternal task, TaskMutator taskMutator) {
this.resolver = resolver;
this.task = task;
this.taskMutator = taskMutator;
final DefaultTaskDependency buildDependencies = new DefaultTaskDependency();
buildDependencies.add(task);
this.allOutputFiles = new CompositeFileCollection() {
@Override
public String getDisplayName() {
return task + " output files";
}
@Override
public void visitContents(FileCollectionResolveContext context) {
for (TaskFilePropertySpec propertySpec : getFileProperties()) {
context.add(propertySpec.getPropertyFiles());
}
}
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
context.add(buildDependencies);
super.visitDependencies(context);
}
};
}
@Override
public Spec super TaskInternal> getUpToDateSpec() {
return upToDateSpec;
}
@Override
public void upToDateWhen(final Closure upToDateClosure) {
taskMutator.mutate("TaskOutputs.upToDateWhen(Closure)", new Runnable() {
public void run() {
upToDateSpec = upToDateSpec.and(upToDateClosure);
}
});
}
@Override
public void upToDateWhen(final Spec super Task> spec) {
taskMutator.mutate("TaskOutputs.upToDateWhen(Spec)", new Runnable() {
public void run() {
upToDateSpec = upToDateSpec.and(spec);
}
});
}
@Override
public boolean isCacheEnabled() {
return !cacheIfSpec.getSpecs().isEmpty() && cacheIfSpec.isSatisfiedBy(task);
}
@Override
public boolean isCacheAllowed() {
for (BasePropertySpec spec : filePropertiesInternal) {
if (spec instanceof NonCacheablePropertySpec) {
return false;
}
}
return true;
}
@Override
public void cacheIf(final Spec super Task> spec) {
taskMutator.mutate("TaskOutputs.cacheIf(Spec)", new Runnable() {
public void run() {
cacheIfSpec = cacheIfSpec.and(spec);
}
});
}
@Override
public boolean getHasOutput() {
return hasDeclaredOutputs() || !upToDateSpec.isEmpty();
}
@Override
public boolean hasDeclaredOutputs() {
return !filePropertiesInternal.isEmpty();
}
@Override
public FileCollection getFiles() {
return allOutputFiles;
}
@Override
public SortedSet getFileProperties() {
if (fileProperties == null) {
TaskPropertyUtils.ensurePropertiesHaveNames(filePropertiesInternal);
Iterable flattenedProperties = Iterables.concat(
Iterables.transform(filePropertiesInternal, new Function>() {
@Override
public Iterable extends TaskOutputFilePropertySpec> apply(BasePropertySpec propertySpec) {
if (propertySpec instanceof CompositePropertySpec) {
return (CompositePropertySpec) propertySpec;
} else {
return Collections.singleton((TaskOutputFilePropertySpec) propertySpec);
}
}
})
);
fileProperties = TaskPropertyUtils.collectFileProperties("output", flattenedProperties);
}
return fileProperties;
}
@Override
public TaskOutputFilePropertyBuilder file(final Object path) {
return taskMutator.mutate("TaskOutputs.file(Object)", new Callable() {
@Override
public TaskOutputFilePropertyBuilder call() throws Exception {
return addSpec(new CacheablePropertySpec(task.getName(), resolver, OutputType.FILE, path));
}
});
}
@Override
public TaskOutputFilePropertyBuilder dir(final Object path) {
return taskMutator.mutate("TaskOutputs.dir(Object)", new Callable() {
@Override
public TaskOutputFilePropertyBuilder call() throws Exception {
return addSpec(new CacheablePropertySpec(task.getName(), resolver, OutputType.DIRECTORY, path));
}
});
}
@Override
public TaskOutputFilePropertyBuilder namedFiles(final Callable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy