FileMatcher { public boolean matches(final Path path) { final Path canonicalPath= this.root.resolve(path).toAbsolutePath().normalize(); for (final MatchPattern matchPattern : this.i18nExcludePatterns) { if (matchPattern.matchPath(canonicalPath.toString(), true)) { return false; } } for (final MatchPattern matchPattern : this.i18nIncludePatterns) { if (matchPattern.matchPath(canonicalPath.toString(), true)) { return true; } } return false; } FileMatcher(final Path root, final String[] i18nIncludes);  FileMatcher(final Path root, final List<String> i18nIncludes);  FileMatcher(final Path root, final String[] i18nIncludes, final String[] i18nExcludes);  FileMatcher(final Path root, final List<String> i18nIncludes, final List<String> i18nExcludes); boolean matches(final Path path); Set<File> findMatchingFiles(); Path getRoot(); List<String> getI18nIncludes(); List<String> getI18nExcludes();  }
@Test public void testMatches_canonicalizePaths() { final Path root= Paths.get("/my/root/"); final String[] includes= { "sub/my.properties" }; final String[] excludes= { }; final FileMatcher fileMatcher= new FileMatcher(root, includes, excludes); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/my.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my assertThat(fileMatcher.matches(Paths.get("/my/root/../root/sub/my.properties"))).isTrue(); }
@Test public void testMatches_excludePath() { final Path root= Paths.get("/my/root/"); final String[] includes= { "sub/*.properties" }; final String[] excludes= { "sub/ex.properties" }; final FileMatcher fileMatcher= new FileMatcher(root, includes, excludes); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/my.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/ex.properties"))).isFalse(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/other.properties"))).isTrue(); }
@Test public void testMatches_singleCharGlob() { final Path root= Paths.get("/my/root/"); final String[] includes= { "f?o.properties" }; final String[] excludes= { }; final FileMatcher fileMatcher= new FileMatcher(root, includes, excludes); assertThat(fileMatcher.matches(Paths.get("/my/root/foo.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/froo.properties"))).isFalse(); assertThat(fileMatcher.matches(Paths.get("/my/root/fro.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/aro.properties"))).isFalse(); }
@Test public void testMatches_multiCharGlob() { final Path root= Paths.get("/my/root/"); final String[] includes= { "f*o.properties" }; final String[] excludes= { }; final FileMatcher fileMatcher= new FileMatcher(root, includes, excludes); assertThat(fileMatcher.matches(Paths.get("/my/root/foo.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/froo.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/fro.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/aro.properties"))).isFalse(); }
@Test public void testMatches_singleAndMultiCharGlob() { final Path root= Paths.get("/my/root/"); final String[] includes= { "f?o*m.properties" }; final String[] excludes= { }; final FileMatcher fileMatcher= new FileMatcher(root, includes, excludes); assertThat(fileMatcher.matches(Paths.get("/my/root/foom.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/froom.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/froouam.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/from.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/arom.properties"))).isFalse(); }
@Test public void testMatches_GlobInDir() { final Path root= Paths.get("/my/root/"); final String[] includes= { "sub/f*/my.properties" }; final String[] excludes= { }; final FileMatcher fileMatcher= new FileMatcher(root, includes, excludes); assertThat(fileMatcher.matches(Paths.get("/my/root/my.properties"))).isFalse(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/my.properties"))).isFalse(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/foo/my.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/f/my.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/fantasy/my.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/pants/my.properties"))).isFalse(); }
@Test public void testMatches_recursiveInclusion() { final Path root= Paths.get("/my/root/"); final String[] includes= { "**/*.properties" }; final String[] excludes= { }; final FileMatcher fileMatcher= new FileMatcher(root, includes, excludes); assertThat(fileMatcher.matches(Paths.get("/my/root/my.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/my.properties"))).isTrue(); assertThat(fileMatcher.matches(Paths.get("/my/root/sub/sub/my.properties"))).isTrue(); }