use of java.nio.file.PathMatcher in project copybara by google.
the class GitRepository method checkout.
public void checkout(Glob glob, Path destRoot, GitRevision rev) throws RepoException {
ImmutableList<TreeElement> treeElements = lsTree(rev, null, true, true);
PathMatcher pathMatcher = glob.relativeTo(destRoot);
for (TreeElement file : treeElements) {
Path path = destRoot.resolve(file.getPath());
if (pathMatcher.matches(path)) {
try {
Files.write(path, readFile(rev.getSha1(), file.getPath()).getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RepoException(String.format("Cannot write '%s' from reference '%s' into '%s'", file.getPath(), rev, path), e);
}
}
}
}
use of java.nio.file.PathMatcher in project copybara by google.
the class Glob method relativeTo.
public PathMatcher relativeTo(Path path) {
ImmutableList.Builder<PathMatcher> includeList = ImmutableList.builder();
for (GlobAtom path1 : include) {
includeList.add(path1.matcher(path));
}
for (Glob g : globInclude) {
includeList.add(g.relativeTo(path));
}
PathMatcher excludeMatcher = (exclude == null) ? FileUtil.anyPathMatcher(ImmutableList.of()) : exclude.relativeTo(path);
return new GlobPathMatcher(FileUtil.anyPathMatcher(includeList.build()), excludeMatcher);
}
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, ImmutableList.of(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 GlobTest method iteratedUnion_doesNotCreateTallGlobTree.
@Test
public void iteratedUnion_doesNotCreateTallGlobTree() throws Exception {
String config = "glob(['foo/**'], exclude=['foo/file*'])";
for (int i = 0; i < 1000; i++) {
config += String.format(" + glob(['foo/file%d'])", i);
}
Glob glob = parseGlob(config);
assertThat(glob.roots()).containsExactly("foo");
assertThat(glob.heightOfGlobTree()).isLessThan(3);
PathMatcher matcher = glob.relativeTo(workdir);
assertThat(matcher.matches(workdir.resolve("foo/file777"))).isTrue();
assertThat(matcher.matches(workdir.resolve("foo/file1000"))).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();
}
Aggregations