use of org.gradle.api.internal.file.collections.FileSystemMirroringFileTree in project gradle by gradle.
the class FileParameterUtils method resolveCompositeOutputFilePropertySpecs.
private static void resolveCompositeOutputFilePropertySpecs(final String ownerDisplayName, final String propertyName, Object unpackedValue, final TreeType outputType, FileCollectionFactory fileCollectionFactory, Consumer<OutputFilePropertySpec> consumer) {
if (unpackedValue instanceof Map) {
for (Map.Entry<?, ?> entry : ((Map<?, ?>) unpackedValue).entrySet()) {
Object key = entry.getKey();
if (key == null) {
throw new IllegalArgumentException(String.format("Mapped output property '%s' has null key", propertyName));
}
String id = key.toString();
FileCollectionInternal outputFiles = fileCollectionFactory.resolving(entry.getValue());
consumer.accept(new DefaultCacheableOutputFilePropertySpec(propertyName, "." + id, outputFiles, outputType));
}
} else {
FileCollectionInternal outputFileCollection = fileCollectionFactory.resolving(unpackedValue);
AtomicInteger index = new AtomicInteger(0);
outputFileCollection.visitStructure(new FileCollectionStructureVisitor() {
@Override
public void visitCollection(FileCollectionInternal.Source source, Iterable<File> contents) {
for (File content : contents) {
FileCollectionInternal outputFiles = fileCollectionFactory.fixed(content);
consumer.accept(new DefaultCacheableOutputFilePropertySpec(propertyName, "$" + index.incrementAndGet(), outputFiles, outputType));
}
}
@Override
public void visitGenericFileTree(FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
failOnInvalidOutputType(fileTree);
}
@Override
public void visitFileTreeBackedByFile(File file, FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
failOnInvalidOutputType(fileTree);
}
@Override
public void visitFileTree(File root, PatternSet patterns, FileTreeInternal fileTree) {
// We could support an unfiltered DirectoryFileTree here as a cacheable root,
// but because @OutputDirectory also doesn't support it we choose not to.
consumer.accept(new DirectoryTreeOutputFilePropertySpec(propertyName + "$" + index.incrementAndGet(), new PropertyFileCollection(ownerDisplayName, propertyName, "output", fileTree), root));
}
});
}
}
use of org.gradle.api.internal.file.collections.FileSystemMirroringFileTree in project gradle by gradle.
the class FileCollectionMatchers method sameCollection.
@Factory
public static <T extends FileCollection> Matcher<T> sameCollection(final FileCollection expected) {
return new BaseMatcher<T>() {
@Override
public boolean matches(Object o) {
FileCollection actual = (FileCollection) o;
List<Object> actualCollections = unpack(actual);
List<Object> expectedCollections = unpack(expected);
boolean equals = actualCollections.equals(expectedCollections);
if (!equals) {
System.out.println("expected: " + expectedCollections);
System.out.println("actual: " + actualCollections);
}
return equals;
}
private List<Object> unpack(FileCollection expected) {
if (expected instanceof FileCollectionInternal) {
FileCollectionInternal collection = (CompositeFileCollection) expected;
List<Object> collections = new ArrayList<>();
collection.visitStructure(new FileCollectionStructureVisitor() {
@Override
public void visitCollection(FileCollectionInternal.Source source, Iterable<File> contents) {
for (File content : contents) {
collections.add(content);
}
}
@Override
public void visitGenericFileTree(FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
collections.add(fileTree);
}
@Override
public void visitFileTree(File root, PatternSet patterns, FileTreeInternal fileTree) {
collections.add(fileTree);
}
@Override
public void visitFileTreeBackedByFile(File file, FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
collections.add(fileTree);
}
});
return collections;
}
throw new RuntimeException("Cannot get children of " + expected);
}
@Override
public void describeTo(Description description) {
description.appendText("same file collection as ").appendValue(expected);
}
};
}
use of org.gradle.api.internal.file.collections.FileSystemMirroringFileTree in project gradle by gradle.
the class AbstractFileCollection method getAsFileTrees.
/**
* Returns this collection as a set of {@link DirectoryFileTree} instance. These are used to map to Ant types.
*/
protected Collection<DirectoryTree> getAsFileTrees() {
List<DirectoryTree> fileTrees = new ArrayList<>();
visitStructure(new FileCollectionStructureVisitor() {
@Override
public void visitCollection(Source source, Iterable<File> contents) {
for (File file : contents) {
if (file.isFile()) {
fileTrees.add(new FileBackedDirectoryFileTree(file));
}
}
}
@Override
public void visitFileTree(File root, PatternSet patterns, FileTreeInternal fileTree) {
if (root.isFile()) {
fileTrees.add(new FileBackedDirectoryFileTree(root));
} else if (root.isDirectory()) {
fileTrees.add(new DirectoryTree() {
@Override
public File getDir() {
return root;
}
@Override
public PatternSet getPatterns() {
return patterns;
}
});
}
}
@Override
public void visitGenericFileTree(FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
// Visit the contents of the tree to generate the tree
if (visitAll(sourceTree)) {
fileTrees.add(sourceTree.getMirror());
}
}
@Override
public void visitFileTreeBackedByFile(File file, FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
visitGenericFileTree(fileTree, sourceTree);
}
});
return fileTrees;
}
use of org.gradle.api.internal.file.collections.FileSystemMirroringFileTree in project gradle by gradle.
the class LocalTaskNodeExecutor method detectMissingDependencies.
private void detectMissingDependencies(LocalTaskNode node, boolean historyMaintained, ExecutionNodeAccessHierarchies.InputNodeAccessHierarchy inputHierarchy, TypeValidationContext validationContext) {
for (String outputPath : node.getMutationInfo().outputPaths) {
inputHierarchy.getNodesAccessing(outputPath).stream().filter(consumerNode -> hasNoSpecifiedOrder(node, consumerNode)).filter(LocalTaskNodeExecutor::isEnabled).forEach(consumerWithoutDependency -> collectValidationProblem(node, consumerWithoutDependency, validationContext, outputPath));
}
Set<String> taskInputs = new LinkedHashSet<>();
Set<FilteredTree> filteredFileTreeTaskInputs = new LinkedHashSet<>();
node.getTaskProperties().getInputFileProperties().forEach(spec -> {
try {
spec.getPropertyFiles().visitStructure(new FileCollectionStructureVisitor() {
@Override
public void visitCollection(FileCollectionInternal.Source source, Iterable<File> contents) {
contents.forEach(location -> taskInputs.add(location.getAbsolutePath()));
}
@Override
public void visitGenericFileTree(FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
fileTree.forEach(location -> taskInputs.add(location.getAbsolutePath()));
}
@Override
public void visitFileTree(File root, PatternSet patterns, FileTreeInternal fileTree) {
if (patterns.isEmpty()) {
taskInputs.add(root.getAbsolutePath());
} else {
filteredFileTreeTaskInputs.add(new FilteredTree(root.getAbsolutePath(), patterns));
}
}
@Override
public void visitFileTreeBackedByFile(File file, FileTreeInternal fileTree, FileSystemMirroringFileTree sourceTree) {
taskInputs.add(file.getAbsolutePath());
}
});
} catch (Exception e) {
if (historyMaintained) {
// We would later try to snapshot the inputs anyway, no need to suppress the exception
throw e;
} else {
validationContext.visitPropertyProblem(problem -> problem.withId(ValidationProblemId.UNRESOLVABLE_INPUT).forProperty(spec.getPropertyName()).reportAs(Severity.WARNING).withDescription(() -> String.format("cannot be resolved:%n%s%n", TextUtil.indent(e.getMessage(), " "))).happensBecause("An input file collection couldn't be resolved, making it impossible to determine task inputs").addPossibleSolution("Consider using Task.dependsOn instead").documentedAt("validation_problems", "unresolvable_input"));
}
}
});
inputHierarchy.recordNodeAccessingLocations(node, taskInputs);
for (String locationConsumedByThisTask : taskInputs) {
collectValidationProblemsForConsumer(node, validationContext, locationConsumedByThisTask, outputHierarchy.getNodesAccessing(locationConsumedByThisTask));
}
for (FilteredTree filteredFileTreeInput : filteredFileTreeTaskInputs) {
Spec<FileTreeElement> spec = filteredFileTreeInput.getPatterns().getAsSpec();
inputHierarchy.recordNodeAccessingFileTree(node, filteredFileTreeInput.getRoot(), spec);
collectValidationProblemsForConsumer(node, validationContext, filteredFileTreeInput.getRoot(), outputHierarchy.getNodesAccessing(filteredFileTreeInput.getRoot(), spec));
}
}
Aggregations