org.gradle.api.internal.tasks.properties.DefaultTaskProperties 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 2017 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.properties;
import com.google.common.collect.ImmutableSortedSet;
import org.gradle.api.NonNullApi;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.TaskInternal;
import org.gradle.api.internal.file.CompositeFileCollection;
import org.gradle.api.internal.file.FileCollectionFactory;
import org.gradle.api.internal.file.FileCollectionInternal;
import org.gradle.api.internal.tasks.TaskPropertyUtils;
import org.gradle.api.internal.tasks.TaskValidationContext;
import org.gradle.api.tasks.FileNormalizer;
import org.gradle.api.tasks.TaskExecutionException;
import org.gradle.internal.fingerprint.DirectorySensitivity;
import org.gradle.internal.reflect.TypeValidationContext.ReplayingTypeValidationContext;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
@NonNullApi
public class DefaultTaskProperties implements TaskProperties {
private final ImmutableSortedSet inputProperties;
private final ImmutableSortedSet inputFileProperties;
private final ImmutableSortedSet outputFileProperties;
private final FileCollection inputFiles;
private final boolean hasSourceFiles;
private final FileCollection sourceFiles;
private final boolean hasDeclaredOutputs;
private final ReplayingTypeValidationContext validationProblems;
private final FileCollection outputFiles;
private final FileCollection localStateFiles;
private final FileCollection destroyableFiles;
private final List validatingProperties;
public static TaskProperties resolve(PropertyWalker propertyWalker, FileCollectionFactory fileCollectionFactory, TaskInternal task) {
String beanName = task.toString();
GetInputPropertiesVisitor inputPropertiesVisitor = new GetInputPropertiesVisitor();
GetInputFilesVisitor inputFilesVisitor = new GetInputFilesVisitor(beanName, fileCollectionFactory);
GetOutputFilesVisitor outputFilesVisitor = new GetOutputFilesVisitor(beanName, fileCollectionFactory);
GetLocalStateVisitor localStateVisitor = new GetLocalStateVisitor(beanName, fileCollectionFactory);
GetDestroyablesVisitor destroyablesVisitor = new GetDestroyablesVisitor(beanName, fileCollectionFactory);
ValidationVisitor validationVisitor = new ValidationVisitor();
ReplayingTypeValidationContext validationContext = new ReplayingTypeValidationContext();
try {
TaskPropertyUtils.visitProperties(propertyWalker, task, validationContext, new CompositePropertyVisitor(
inputPropertiesVisitor,
inputFilesVisitor,
outputFilesVisitor,
validationVisitor,
destroyablesVisitor,
localStateVisitor
));
} catch (Exception e) {
throw new TaskExecutionException(task, e);
}
return new DefaultTaskProperties(
task.toString(),
inputPropertiesVisitor.getProperties(),
inputFilesVisitor.getFileProperties(),
outputFilesVisitor.getFileProperties(),
outputFilesVisitor.hasDeclaredOutputs(),
localStateVisitor.getFiles(),
destroyablesVisitor.getFiles(),
validationVisitor.getTaskPropertySpecs(),
validationContext);
}
private DefaultTaskProperties(
String name,
ImmutableSortedSet inputProperties,
ImmutableSortedSet inputFileProperties,
ImmutableSortedSet outputFileProperties,
boolean hasDeclaredOutputs,
FileCollection localStateFiles,
FileCollection destroyableFiles,
List validatingProperties,
ReplayingTypeValidationContext validationProblems
) {
this.validatingProperties = validatingProperties;
this.validationProblems = validationProblems;
this.inputProperties = inputProperties;
this.inputFileProperties = inputFileProperties;
this.outputFileProperties = outputFileProperties;
this.hasDeclaredOutputs = hasDeclaredOutputs;
this.inputFiles = new CompositeFileCollection() {
@Override
public String getDisplayName() {
return name + " input files";
}
@Override
protected void visitChildren(Consumer visitor) {
for (InputFilePropertySpec filePropertySpec : inputFileProperties) {
visitor.accept(filePropertySpec.getPropertyFiles());
}
}
};
this.sourceFiles = new CompositeFileCollection() {
@Override
public String getDisplayName() {
return name + " source files";
}
@Override
protected void visitChildren(Consumer visitor) {
for (InputFilePropertySpec filePropertySpec : inputFileProperties) {
if (filePropertySpec.isSkipWhenEmpty()) {
visitor.accept(filePropertySpec.getPropertyFiles());
}
}
}
};
this.hasSourceFiles = inputFileProperties.stream()
.anyMatch(InputFilePropertySpec::isSkipWhenEmpty);
this.outputFiles = new CompositeFileCollection() {
@Override
public String getDisplayName() {
return "output files";
}
@Override
protected void visitChildren(Consumer visitor) {
for (FilePropertySpec propertySpec : outputFileProperties) {
visitor.accept(propertySpec.getPropertyFiles());
}
}
};
this.localStateFiles = localStateFiles;
this.destroyableFiles = destroyableFiles;
}
@Override
public Iterable extends LifecycleAwareValue> getLifecycleAwareValues() {
return validatingProperties;
}
@Override
public ImmutableSortedSet getOutputFileProperties() {
return outputFileProperties;
}
@Override
public FileCollection getOutputFiles() {
return outputFiles;
}
@Override
public FileCollection getSourceFiles() {
return sourceFiles;
}
@Override
public boolean hasSourceFiles() {
return hasSourceFiles;
}
@Override
public FileCollection getInputFiles() {
return inputFiles;
}
@Override
public ImmutableSortedSet getInputFileProperties() {
return inputFileProperties;
}
@Override
public void validate(TaskValidationContext validationContext) {
validationProblems.replay(null, validationContext);
for (ValidatingProperty validatingProperty : validatingProperties) {
validatingProperty.validate(validationContext);
}
}
@Override
public boolean hasDeclaredOutputs() {
return hasDeclaredOutputs;
}
@Override
public ImmutableSortedSet getInputProperties() {
return inputProperties;
}
@Override
public FileCollection getLocalStateFiles() {
return localStateFiles;
}
@Override
public FileCollection getDestroyableFiles() {
return destroyableFiles;
}
private static class GetLocalStateVisitor extends PropertyVisitor.Adapter {
private final String beanName;
private final FileCollectionFactory fileCollectionFactory;
private final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy