Search in sources :

Example 56 with PathMatcher

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

Example 57 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)

Example 58 with PathMatcher

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

Example 59 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, 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 60 with PathMatcher

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

Aggregations

PathMatcher (java.nio.file.PathMatcher)87 Path (java.nio.file.Path)40 Test (org.junit.Test)23 IOException (java.io.IOException)22 File (java.io.File)16 ArrayList (java.util.ArrayList)12 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)10 FileVisitResult (java.nio.file.FileVisitResult)9 Files (java.nio.file.Files)5 Paths (java.nio.file.Paths)5 HashSet (java.util.HashSet)5 List (java.util.List)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 LocalVirtualFileSystemProvider (org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider)5 FSLuceneSearcherProvider (org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider)5