Search in sources :

Example 36 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class GlobTest method emptyIncludeExcludesEverything.

@Test
public void emptyIncludeExcludesEverything() throws Exception {
    PathMatcher matcher = createPathMatcher("glob([], exclude = ['foo'])");
    assertThat(matcher.matches(workdir.resolve("foo"))).isFalse();
    assertThat(matcher.matches(workdir.resolve("bar/foo"))).isFalse();
    assertThat(matcher.matches(workdir.resolve("baz"))).isFalse();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 37 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class GlobTest method differenceOfDifferences.

@Test
public void differenceOfDifferences() throws Exception {
    // a - (b - (c - d))
    Glob glob = parseGlob("glob(['aaa/**']) - (glob(['**/bbb/**']) - (glob(['**/ccc/**']) - glob(['**/ddd'])))");
    assertThat(glob.roots()).containsExactly("aaa");
    PathMatcher matcher = glob.relativeTo(workdir);
    assertThat(matcher.matches(workdir.resolve("aaa/xxx"))).isTrue();
    assertThat(matcher.matches(workdir.resolve("aaa/bbb/xxx"))).isFalse();
    assertThat(matcher.matches(workdir.resolve("aaa/bbb/ccc/xxx"))).isTrue();
    assertThat(matcher.matches(workdir.resolve("aaa/bbb/ccc/ddd"))).isFalse();
    assertThat(matcher.matches(workdir.resolve("xxx/bbb/ccc/xxx"))).isFalse();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Glob.createGlob(com.google.copybara.util.Glob.createGlob) Test(org.junit.Test)

Example 38 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class GlobTest method differenceTest.

@Test
public void differenceTest() throws Exception {
    Glob glob = parseGlob("glob(['foo/**']) - glob(['foo/bar/**'])");
    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();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Glob.createGlob(com.google.copybara.util.Glob.createGlob) Test(org.junit.Test)

Example 39 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class GlobTest method testSimpleInclude.

@Test
public void testSimpleInclude() throws IOException, ValidationException, RepoException {
    PathMatcher pathMatcher = createPathMatcher("glob(['foo','bar'])");
    assertThat(pathMatcher.matches(workdir.resolve("foo"))).isTrue();
    assertThat(pathMatcher.matches(workdir.resolve("bar"))).isTrue();
    assertThat(pathMatcher.matches(workdir.resolve("baz"))).isFalse();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 40 with PathMatcher

use of java.nio.file.PathMatcher in project copybara by google.

the class GlobTest method iteratedDifference_doesNotCreateTallGlobTree.

@Test
public void iteratedDifference_doesNotCreateTallGlobTree() throws Exception {
    String config = "glob(['foo/**'])";
    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"))).isFalse();
    assertThat(matcher.matches(workdir.resolve("foo/file1000"))).isTrue();
}
Also used : PathMatcher(java.nio.file.PathMatcher) Glob.createGlob(com.google.copybara.util.Glob.createGlob) 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