Search in sources :

Example 96 with PathMatcher

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) IOException(java.io.IOException) RepoException(com.google.copybara.exception.RepoException)

Example 97 with PathMatcher

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);
}
Also used : PathMatcher(java.nio.file.PathMatcher) ImmutableList(com.google.common.collect.ImmutableList)

Example 98 with PathMatcher

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();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 99 with PathMatcher

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();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Glob.createGlob(com.google.copybara.util.Glob.createGlob) Test(org.junit.Test)

Example 100 with PathMatcher

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();
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) FileSystem(java.nio.file.FileSystem) Test(org.junit.Test)

Aggregations

PathMatcher (java.nio.file.PathMatcher)107 Path (java.nio.file.Path)47 Test (org.junit.Test)30 IOException (java.io.IOException)28 File (java.io.File)18 ArrayList (java.util.ArrayList)13 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)11 FileVisitResult (java.nio.file.FileVisitResult)10 Glob.createGlob (com.google.copybara.util.Glob.createGlob)8 Files (java.nio.file.Files)6 Paths (java.nio.file.Paths)6 List (java.util.List)6 FileSystems (java.nio.file.FileSystems)5 HashSet (java.util.HashSet)5 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)5 ProjectImporterRegistry (org.eclipse.che.api.project.server.importer.ProjectImporterRegistry)5 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)5 DefaultFileWatcherNotificationHandler (org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler)5 FileTreeWatcher (org.eclipse.che.api.vfs.impl.file.FileTreeWatcher)5