Search in sources :

Example 1 with PatternStep

use of org.gradle.api.internal.file.pattern.PatternStep in project gradle by gradle.

the class SingleIncludePatternFileTree method doVisit.

private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
    if (stopFlag.get()) {
        return;
    }
    String segment = patternSegments.get(segmentIndex);
    if (segment.contains("**")) {
        PatternSet patternSet = new PatternSet();
        patternSet.include(includePattern);
        patternSet.exclude(excludeSpec);
        DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet, fileSystem);
        fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
    } else if (segment.contains("*") || segment.contains("?")) {
        PatternStep step = PatternStepFactory.getStep(segment, false);
        File[] children = file.listFiles();
        if (children == null) {
            if (!file.canRead()) {
                throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
            }
            // else, might be a link which points to nothing, or has been removed while we're visiting, or ...
            throw new GradleException(String.format("Could not list contents of '%s'.", file));
        }
        for (File child : children) {
            if (stopFlag.get()) {
                break;
            }
            String childName = child.getName();
            if (step.matches(childName)) {
                relativePath.addLast(childName);
                doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
                relativePath.removeLast();
            }
        }
    } else {
        relativePath.addLast(segment);
        doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
        relativePath.removeLast();
    }
}
Also used : RelativePath(org.gradle.api.file.RelativePath) PatternStep(org.gradle.api.internal.file.pattern.PatternStep) GradleException(org.gradle.api.GradleException) PatternSet(org.gradle.api.tasks.util.PatternSet) File(java.io.File)

Aggregations

File (java.io.File)1 GradleException (org.gradle.api.GradleException)1 RelativePath (org.gradle.api.file.RelativePath)1 PatternStep (org.gradle.api.internal.file.pattern.PatternStep)1 PatternSet (org.gradle.api.tasks.util.PatternSet)1