Search in sources :

Example 1 with DirectoryTree

use of org.gradle.api.file.DirectoryTree in project gradle by gradle.

the class DefaultSourceDirectorySet method doGetSrcDirTrees.

private Set<DirectoryTree> doGetSrcDirTrees() {
    Set<DirectoryTree> result = new LinkedHashSet<DirectoryTree>();
    for (Object path : source) {
        if (path instanceof SourceDirectorySet) {
            SourceDirectorySet nested = (SourceDirectorySet) path;
            result.addAll(nested.getSrcDirTrees());
        } else {
            for (File srcDir : fileResolver.resolveFiles(path)) {
                if (srcDir.exists() && !srcDir.isDirectory()) {
                    throw new InvalidUserDataException(String.format("Source directory '%s' is not a directory.", srcDir));
                }
                result.add(directoryFileTreeFactory.create(srcDir, patterns));
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DirectoryTree(org.gradle.api.file.DirectoryTree) InvalidUserDataException(org.gradle.api.InvalidUserDataException) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) File(java.io.File)

Example 2 with DirectoryTree

use of org.gradle.api.file.DirectoryTree in project gradle by gradle.

the class SourceFoldersCreator method projectRelativeFolders.

private List<SourceFolder> projectRelativeFolders(Iterable<SourceSet> sourceSets, Function<File, String> provideRelativePath) {
    ArrayList<SourceFolder> entries = Lists.newArrayList();
    List<SourceSet> sortedSourceSets = sortSourceSetsAsPerUsualConvention(sourceSets);
    for (SourceSet sourceSet : sortedSourceSets) {
        List<DirectoryTree> sortedSourceDirs = sortSourceDirsAsPerUsualConvention(sourceSet.getAllSource().getSrcDirTrees());
        for (DirectoryTree tree : sortedSourceDirs) {
            File dir = tree.getDir();
            if (dir.isDirectory()) {
                String relativePath = provideRelativePath.apply(dir);
                SourceFolder folder = new SourceFolder(relativePath, null);
                folder.setDir(dir);
                folder.setName(dir.getName());
                folder.setIncludes(getIncludesForTree(sourceSet, tree));
                folder.setExcludes(getExcludesForTree(sourceSet, tree));
                entries.add(folder);
            }
        }
    }
    return entries;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) SourceSet(org.gradle.api.tasks.SourceSet) DirectoryTree(org.gradle.api.file.DirectoryTree) File(java.io.File)

Example 3 with DirectoryTree

use of org.gradle.api.file.DirectoryTree in project gradle by gradle.

the class FileSystemSubset method contains.

public boolean contains(File file) {
    File absoluteFile = file.getAbsoluteFile();
    String pathWithSeparator = file.getAbsolutePath() + File.separator;
    for (File candidateFile : files) {
        String candidateFilePathWithSeparator = candidateFile.getPath() + File.separator;
        if (pathWithSeparator.startsWith(candidateFilePathWithSeparator)) {
            return true;
        }
    }
    for (DirectoryTree tree : trees) {
        if (tree.getDir().getAbsoluteFile().equals(absoluteFile) || DirectoryTrees.contains(FileSystems.getDefault(), tree, absoluteFile)) {
            return true;
        }
    }
    return false;
}
Also used : DirectoryTree(org.gradle.api.file.DirectoryTree) File(java.io.File)

Aggregations

File (java.io.File)3 DirectoryTree (org.gradle.api.file.DirectoryTree)3 LinkedHashSet (java.util.LinkedHashSet)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 SourceSet (org.gradle.api.tasks.SourceSet)1 SourceFolder (org.gradle.plugins.ide.eclipse.model.SourceFolder)1