use of java.nio.file.PathMatcher in project copybara by google.
the class GlobTest method testWithDirs.
@Test
public void testWithDirs() throws IOException, ValidationException, RepoException {
PathMatcher pathMatcher = createPathMatcher("" + "glob(\n" + " include = ['**/*.java'], \n" + " exclude = ['**/Generated*.java']\n" + ")");
assertThat(pathMatcher.matches(workdir.resolve("foo/Some.java"))).isTrue();
assertThat(pathMatcher.matches(workdir.resolve("foo/GeneratedSome.java"))).isFalse();
// Doesn't match because '**/' matches when there is already one directory segment.
assertThat(pathMatcher.matches(workdir.resolve("Some.java"))).isFalse();
assertThat(pathMatcher.matches(workdir.resolve("GeneratedSome.java"))).isFalse();
}
use of java.nio.file.PathMatcher in project copybara by google.
the class GlobTest method windowsGlobWorks.
@Test
public void windowsGlobWorks() throws Exception {
FileSystem workFs = Jimfs.newFileSystem(Configuration.windows());
workdir = workFs.getPath("c:/tmp");
Path folder = workdir.resolve("foo");
Files.createDirectories(folder);
Files.write(folder.resolve("bar"), new byte[0]);
PathMatcher matcher = createPathMatcher("glob(['foo/**'])");
assertThat(matcher.matches(workdir.resolve("foo/bar"))).isTrue();
}
use of java.nio.file.PathMatcher in project copybara by google.
the class GlobTest method unionWithExcludeAndInclude.
@Test
public void unionWithExcludeAndInclude() throws Exception {
Glob glob = parseGlob("glob(['foo/**'], exclude = ['foo/bar/**'])" + " + glob(['foo/bar/baz/**'])");
assertThat(glob.roots()).containsExactly("foo");
PathMatcher matcher = glob.relativeTo(workdir);
assertThat(matcher.matches(workdir.resolve("foo/a"))).isTrue();
assertThat(matcher.matches(workdir.resolve("foo/bar/a"))).isFalse();
assertThat(matcher.matches(workdir.resolve("foo/bar/baz/a"))).isTrue();
}
use of java.nio.file.PathMatcher in project copybara by google.
the class WorkflowTest method testDestinationFilesPassedToDestination_squash.
@Test
public void testDestinationFilesPassedToDestination_squash() throws Exception {
destinationFiles = "glob(['**'], exclude = ['foo', 'bar/**'])";
workflow().run(workdir, HEAD);
assertThat(destination.processed).hasSize(1);
PathMatcher matcher = destination.processed.get(0).getDestinationFiles().relativeTo(workdir);
assertThat(matcher.matches(workdir.resolve("foo"))).isFalse();
assertThat(matcher.matches(workdir.resolve("foo/indir"))).isTrue();
assertThat(matcher.matches(workdir.resolve("bar/indir"))).isFalse();
}
use of java.nio.file.PathMatcher in project copybara by google.
the class SimpleGlob method relativeTo.
@Override
public PathMatcher relativeTo(Path path) {
Builder<PathMatcher> includeList = ImmutableList.builder();
for (String path1 : include) {
includeList.add(ReadablePathMatcher.relativeGlob(path, path1));
}
PathMatcher excludeMatcher = (exclude == null) ? FileUtil.anyPathMatcher(ImmutableList.of()) : exclude.relativeTo(path);
return new GlobPathMatcher(FileUtil.anyPathMatcher(includeList.build()), excludeMatcher);
}
Aggregations