Search in sources :

Example 1 with PropertyFileCollection

use of org.gradle.api.internal.tasks.PropertyFileCollection 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));
            }
        });
    }
}
Also used : FileTreeInternal(org.gradle.api.internal.file.FileTreeInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) PropertyFileCollection(org.gradle.api.internal.tasks.PropertyFileCollection) FileCollectionStructureVisitor(org.gradle.api.internal.file.FileCollectionStructureVisitor) FileSystemMirroringFileTree(org.gradle.api.internal.file.collections.FileSystemMirroringFileTree) Map(java.util.Map) File(java.io.File) PatternSet(org.gradle.api.tasks.util.PatternSet)

Example 2 with PropertyFileCollection

use of org.gradle.api.internal.tasks.PropertyFileCollection in project gradle by gradle.

the class GetInputFilesVisitor method visitInputFileProperty.

@Override
public void visitInputFileProperty(final String propertyName, boolean optional, boolean skipWhenEmpty, DirectorySensitivity directorySensitivity, LineEndingSensitivity lineEndingSensitivity, boolean incremental, @Nullable Class<? extends FileNormalizer> fileNormalizer, PropertyValue value, InputFilePropertyType filePropertyType) {
    FileCollectionInternal actualValue = FileParameterUtils.resolveInputFileValue(fileCollectionFactory, filePropertyType, value);
    Class<? extends FileNormalizer> normalizer = FileParameterUtils.normalizerOrDefault(fileNormalizer);
    specs.add(new DefaultInputFilePropertySpec(propertyName, normalizer, new PropertyFileCollection(ownerDisplayName, propertyName, "input", actualValue), value, skipWhenEmpty, incremental, normalizeDirectorySensitivity(normalizer, directorySensitivity), lineEndingSensitivity));
    if (skipWhenEmpty) {
        hasSourceFiles = true;
    }
}
Also used : FileCollectionInternal(org.gradle.api.internal.file.FileCollectionInternal) PropertyFileCollection(org.gradle.api.internal.tasks.PropertyFileCollection)

Aggregations

FileCollectionInternal (org.gradle.api.internal.file.FileCollectionInternal)2 PropertyFileCollection (org.gradle.api.internal.tasks.PropertyFileCollection)2 File (java.io.File)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FileCollectionStructureVisitor (org.gradle.api.internal.file.FileCollectionStructureVisitor)1 FileTreeInternal (org.gradle.api.internal.file.FileTreeInternal)1 FileSystemMirroringFileTree (org.gradle.api.internal.file.collections.FileSystemMirroringFileTree)1 PatternSet (org.gradle.api.tasks.util.PatternSet)1