use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class ReproducibleDirectoryWalker method walkDir.
@Override
public void walkDir(File file, RelativePath path, FileVisitor visitor, Spec<? super FileTreeElement> spec, AtomicBoolean stopFlag, boolean postfix) {
File[] children = getChildren(file);
if (children == null) {
if (file.isDirectory() && !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));
}
List<FileVisitDetails> dirs = new ArrayList<FileVisitDetails>();
for (int i = 0; !stopFlag.get() && i < children.length; i++) {
File child = children[i];
boolean isFile = child.isFile();
RelativePath childPath = path.append(isFile, child.getName());
FileVisitDetails details = new DefaultFileVisitDetails(child, childPath, stopFlag, fileSystem, fileSystem);
if (DirectoryFileTree.isAllowed(details, spec)) {
if (isFile) {
visitor.visitFile(details);
} else {
dirs.add(details);
}
}
}
// now handle dirs
for (int i = 0; !stopFlag.get() && i < dirs.size(); i++) {
FileVisitDetails dir = dirs.get(i);
if (postfix) {
walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix);
visitor.visitDir(dir);
} else {
visitor.visitDir(dir);
walkDir(dir.getFile(), dir.getRelativePath(), visitor, spec, stopFlag, postfix);
}
}
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class MapFileTree method visit.
public void visit(FileVisitor visitor) {
AtomicBoolean stopFlag = new AtomicBoolean();
Visit visit = new Visit(visitor, stopFlag);
for (Map.Entry<RelativePath, Action<OutputStream>> entry : elements.entrySet()) {
if (stopFlag.get()) {
break;
}
RelativePath path = entry.getKey();
Action<OutputStream> generator = entry.getValue();
visit.visit(path, generator);
}
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class DefaultCopySpec method filesNotMatching.
public CopySpec filesNotMatching(Iterable<String> patterns, Action<? super FileCopyDetails> action) {
if (!patterns.iterator().hasNext()) {
throw new InvalidUserDataException("must provide at least one pattern to not match");
}
List<Spec> matchers = new ArrayList<Spec>();
for (String pattern : patterns) {
matchers.add(PatternMatcherFactory.getPatternMatcher(true, isCaseSensitive(), pattern));
}
Spec unionMatcher = Specs.union(matchers.toArray(new Spec[matchers.size()]));
return eachFile(new MatchingCopyAction(Specs.<RelativePath>negate(unionMatcher), action));
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class RelativePathTest method hasWellBehavedEqualsAndHashCode.
@Test
public void hasWellBehavedEqualsAndHashCode() {
assertThat(new RelativePath(true), strictlyEqual(new RelativePath(true)));
assertThat(new RelativePath(true, "one"), strictlyEqual(new RelativePath(true, "one")));
assertThat(new RelativePath(false, "one", "two"), strictlyEqual(new RelativePath(false, "one", "two")));
assertThat(new RelativePath(true, "one"), not(equalTo(new RelativePath(true, "two"))));
assertThat(new RelativePath(true, "one"), not(equalTo(new RelativePath(true, "one", "two"))));
assertThat(new RelativePath(true, "one"), not(equalTo(new RelativePath(false, "one"))));
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class RelativePathTest method canParsePathIntoRelativePath.
@Test
public void canParsePathIntoRelativePath() {
RelativePath path;
path = RelativePath.parse(true, "one");
assertPathContains(path, true, "one");
path = RelativePath.parse(true, "one/two");
assertPathContains(path, true, "one", "two");
path = RelativePath.parse(true, "one/two/");
assertPathContains(path, true, "one", "two");
path = RelativePath.parse(true, String.format("one%stwo%s", File.separator, File.separator));
assertPathContains(path, true, "one", "two");
path = RelativePath.parse(false, "");
assertPathContains(path, false);
path = RelativePath.parse(false, "/");
assertPathContains(path, false);
path = RelativePath.parse(true, "/one");
assertPathContains(path, true, "one");
path = RelativePath.parse(true, "/one/two");
assertPathContains(path, true, "one", "two");
}
Aggregations