Java Code Examples for org.gradle.api.file.FileCollection#getFiles()

The following examples show how to use org.gradle.api.file.FileCollection#getFiles() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultTaskInputs.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Object prepareValue(Object value) {
    while (true) {
        if (value instanceof Callable) {
            Callable callable = (Callable) value;
            try {
                value = callable.call();
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        } else if (value instanceof Closure) {
            Closure closure = (Closure) value;
            value = closure.call();
        } else if (value instanceof FileCollection) {
            FileCollection fileCollection = (FileCollection) value;
            return fileCollection.getFiles();
        } else {
            return avoidGString(value);
        }
    }
}
 
Example 2
Source File: OutputFilesCollectionSnapshotter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public OutputFilesSnapshot snapshot(final FileCollection files) {
    final Map<String, Long> snapshotDirIds = new HashMap<String, Long>();
    final Set<File> theFiles = files.getFiles();
    cacheAccess.useCache("create dir snapshots", new Runnable() {
        public void run() {
            for (File file : theFiles) {
                Long dirId;
                if (file.exists()) {
                    dirId = dirIdentifierCache.get(file.getAbsolutePath());
                    if (dirId == null) {
                        dirId = idGenerator.generateId();
                        dirIdentifierCache.put(file.getAbsolutePath(), dirId);
                    }
                } else {
                    dirIdentifierCache.remove(file.getAbsolutePath());
                    dirId = null;
                }
                snapshotDirIds.put(file.getAbsolutePath(), dirId);
            }

        }
    });
    return new OutputFilesSnapshot(snapshotDirIds, snapshotter.snapshot(files));
}
 
Example 3
Source File: DefaultTaskInputs.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Object unwrap(Object value) {
    while (true) {
        if (value instanceof Callable) {
            Callable callable = (Callable) value;
            try {
                value = callable.call();
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        } else if (value instanceof Closure) {
            Closure closure = (Closure) value;
            value = closure.call();
        } else if (value instanceof FileCollection) {
            FileCollection fileCollection = (FileCollection) value;
            return fileCollection.getFiles();
        } else {
            return value;
        }
    }
}
 
Example 4
Source File: OutputFilesCollectionSnapshotter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public OutputFilesSnapshot snapshot(final FileCollection files) {
    final Map<String, Long> snapshotDirIds = new HashMap<String, Long>();
    final Set<File> theFiles = files.getFiles();
    cacheAccess.useCache("create dir snapshots", new Runnable() {
        public void run() {
            for (File file : theFiles) {
                Long dirId;
                if (file.exists()) {
                    dirId = dirIdentifierCache.get(file.getAbsolutePath());
                    if (dirId == null) {
                        dirId = idGenerator.generateId();
                        dirIdentifierCache.put(file.getAbsolutePath(), dirId);
                    }
                } else {
                    dirIdentifierCache.remove(file.getAbsolutePath());
                    dirId = null;
                }
                snapshotDirIds.put(file.getAbsolutePath(), dirId);
            }

        }
    });
    return new OutputFilesSnapshot(snapshotDirIds, snapshotter.snapshot(files));
}
 
Example 5
Source File: DefaultTaskInputs.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Object prepareValue(Object value) {
    while (true) {
        if (value instanceof Callable) {
            Callable callable = (Callable) value;
            try {
                value = callable.call();
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        } else if (value instanceof Closure) {
            Closure closure = (Closure) value;
            value = closure.call();
        } else if (value instanceof FileCollection) {
            FileCollection fileCollection = (FileCollection) value;
            return fileCollection.getFiles();
        } else {
            return avoidGString(value);
        }
    }
}
 
Example 6
Source File: OutputFilesCollectionSnapshotter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public OutputFilesSnapshot snapshot(final FileCollection files) {
    final Map<String, Long> snapshotDirIds = new HashMap<String, Long>();
    final Set<File> theFiles = files.getFiles();
    cacheAccess.useCache("create dir snapshots", new Runnable() {
        public void run() {
            for (File file : theFiles) {
                Long dirId;
                if (file.exists()) {
                    dirId = dirIdentifierCache.get(file.getAbsolutePath());
                    if (dirId == null) {
                        dirId = idGenerator.generateId();
                        dirIdentifierCache.put(file.getAbsolutePath(), dirId);
                    }
                } else {
                    dirIdentifierCache.remove(file.getAbsolutePath());
                    dirId = null;
                }
                snapshotDirIds.put(file.getAbsolutePath(), dirId);
            }

        }
    });
    return new OutputFilesSnapshot(snapshotDirIds, snapshotter.snapshot(files));
}
 
Example 7
Source File: DefaultTaskInputs.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Object unwrap(Object value) {
    while (true) {
        if (value instanceof Callable) {
            Callable callable = (Callable) value;
            try {
                value = callable.call();
            } catch (Exception e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        } else if (value instanceof Closure) {
            Closure closure = (Closure) value;
            value = closure.call();
        } else if (value instanceof FileCollection) {
            FileCollection fileCollection = (FileCollection) value;
            return fileCollection.getFiles();
        } else {
            return value;
        }
    }
}
 
Example 8
Source File: OutputFilesCollectionSnapshotter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public OutputFilesSnapshot snapshot(final FileCollection files) {
    final Map<String, Long> snapshotDirIds = new HashMap<String, Long>();
    final Set<File> theFiles = files.getFiles();
    cacheAccess.useCache("create dir snapshots", new Runnable() {
        public void run() {
            for (File file : theFiles) {
                Long dirId;
                if (file.exists()) {
                    dirId = dirIdentifierCache.get(file.getAbsolutePath());
                    if (dirId == null) {
                        dirId = idGenerator.generateId();
                        dirIdentifierCache.put(file.getAbsolutePath(), dirId);
                    }
                } else {
                    dirIdentifierCache.remove(file.getAbsolutePath());
                    dirId = null;
                }
                snapshotDirIds.put(file.getAbsolutePath(), dirId);
            }

        }
    });
    return new OutputFilesSnapshot(snapshotDirIds, snapshotter.snapshot(files));
}
 
Example 9
Source File: MergeClassesHelper.java    From gradle-modules-plugin with MIT License 5 votes vote down vote up
public FileCollection getMergeAdjustedClasspath(FileCollection classpath) {
    if (!isMergeRequired()) {
        return classpath;
    }

    Set<File> files = new HashSet<>(classpath.getFiles());
    allCompileTaskStream().map(AbstractCompile::getDestinationDir).forEach(files::remove);
    files.add(helper().getMergedDir());
    return project.files(files.toArray());
}
 
Example 10
Source File: DependencyOrder.java    From pygradle with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of configuration files in the tree post-order,
 * or sorted, or in the original insert order.
 *
 * Attempt to collect dependency tree post-order and fall back to
 * sorted or insert order.
 * If sorted is false, it will always return the original insert order.
 */
public static Collection<File> getConfigurationFiles(FileCollection files, boolean sorted) {
    if (sorted && (files instanceof Configuration)) {
        try {
            return DependencyOrder.configurationPostOrderFiles((Configuration) files);
        } catch (Throwable e) {
            // Log and fall back to old style installation order as before.
            logger.lifecycle("***** WARNING: ${ e.message } *****");
        }
    }
    return sorted
        ? files.getFiles().stream().sorted().collect(Collectors.toSet())
        : files.getFiles();
}
 
Example 11
Source File: JapicmpTask.java    From japicmp-gradle-plugin with Apache License 2.0 5 votes vote down vote up
private static List<JApiCmpWorkerAction.Archive> toArchives(FileCollection fc) {
    Set<File> files = fc.getFiles();
    List<JApiCmpWorkerAction.Archive> archives = new ArrayList<>(files.size());
    for (File file : files) {
        archives.add(new JApiCmpWorkerAction.Archive(file, "1.0"));
    }
    return archives;
}
 
Example 12
Source File: QuarkusGradleUtils.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public static String getClassesDir(SourceSet sourceSet, File tmpDir, boolean populated) {
    FileCollection classesDirs = sourceSet.getOutput().getClassesDirs();
    Set<File> classDirFiles = classesDirs.getFiles();
    if (classDirFiles.size() == 1) {
        return classesDirs.getAsPath();
    }

    Path classesDir = null;
    final Iterator<File> i = classDirFiles.iterator();
    int dirCount = 0;
    while (i.hasNext()) {
        final File next = i.next();
        if (!next.exists()) {
            continue;
        }
        try {
            switch (dirCount++) {
                case 0:
                    classesDir = next.toPath();
                    break;
                case 1:
                    //there does not seem to be any sane way of dealing with multiple output dirs, as there does not seem
                    //to be a way to map them. We will need to address this at some point, but for now we just stick them
                    //all in a temp dir
                    final Path tmpClassesDir = tmpDir.toPath().resolve("quarkus-app-classes");
                    if (!populated) {
                        return tmpClassesDir.toString();
                    }
                    if (Files.exists(tmpClassesDir)) {
                        IoUtils.recursiveDelete(tmpClassesDir);
                    }
                    IoUtils.copy(classesDir, tmpClassesDir);
                    classesDir = tmpClassesDir;
                default:
                    IoUtils.copy(next.toPath(), classesDir);

            }
        } catch (IOException e) {
            throw new UncheckedIOException(ERROR_COLLECTING_PROJECT_CLASSES, e);
        }
    }
    if (classesDir == null) {
        throw new IllegalStateException("Failed to locate classes directory in the project");
    }
    return classesDir.toString();
}