/** * Returns <code>true</code> if some JAR file has to be accepted. */ protected boolean acceptJar(File jarFile) { String path = jarFile.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); return rulesJars.match(path); }
/** * Resolves file path depending on {@link Match matching type} * Returned path is formatted in unix style. */ protected String getMatchingFilePath(File file) { String path = null; switch (matchType) { case FULL_PATH: path = file.getAbsolutePath(); break; case RELATIVE_PATH: path = file.getAbsolutePath(); path = path.substring(rootPath.length()); break; case NAME: path = file.getName(); } path = FileNameUtil.separatorsToUnix(path); return path; }
/** * Converts all separators to the system separator. * * @param path the path to be changed, null ignored * @return the updated path */ public static String separatorsToSystem(String path) { if (path == null) { return null; } if (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR) { return separatorsToWindows(path); } else { return separatorsToUnix(path); } }
/** * Returns <code>true</code> if some JAR file has to be accepted. */ protected boolean acceptJar(final File jarFile) { String path = jarFile.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); return rulesJars.match(path); }
/** * Resolves file path depending on {@link Match matching type} * Returned path is formatted in unix style. */ protected String getMatchingFilePath(final File file) { String path = null; switch (matchType) { case FULL_PATH: path = file.getAbsolutePath(); break; case RELATIVE_PATH: path = file.getAbsolutePath(); path = path.substring(rootPath.length()); break; case NAME: path = file.getName(); } path = FileNameUtil.separatorsToUnix(path); return path; }
/** * Converts all separators to the system separator. * * @param path the path to be changed, null ignored * @return the updated path */ public static String separatorsToSystem(final String path) { if (path == null) { return null; } if (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR) { return separatorsToWindows(path); } else { return separatorsToUnix(path); } }
@Test void testWildcardPath() { FindFile ff = new WildcardFindFile() .include("**/file/*") .recursive(true) .includeDirs(true) .searchPath(dataRoot); int countDirs = 0; int countFiles = 0; File f; while ((f = ff.nextFile()) != null) { if (f.isDirectory()) { countDirs++; } else { countFiles++; String path = f.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); if (!path.startsWith("/")) { path = '/' + path; } boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt"); assertTrue(matched); } } assertEquals(0, countDirs); assertEquals(2, countFiles); }
@Test void testRegexp() { FindFile ff = FindFile.createRegExpFF() .include(".*/a[.].*") .recursive(true) .includeDirs(true) .searchPath(dataRoot); int countDirs = 0; int countFiles = 0; File f; while ((f = ff.nextFile()) != null) { if (f.isDirectory()) { countDirs++; } else { countFiles++; String path = f.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); if (!path.startsWith("/")) { path = '/' + path; } boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt"); assertTrue(matched); } } assertEquals(0, countDirs); assertEquals(2, countFiles); }
countFiles++; String path = f.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); if (!path.startsWith("/")) { path = '/' + path; countFiles2.value++; String path = file.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); if (!path.startsWith("/")) { path = '/' + path;
@Test void testTwoAccept() { FindFile ff = new WildcardFindFile() .include("**/*file/a.png") .include("**/*file/a.txt") .recursive(true) .includeDirs(true) .searchPath(dataRoot); final MutableInteger countFiles = new MutableInteger(); final MutableInteger countDirs = new MutableInteger(); ff.forEach(f -> { if (f.isDirectory()) { countDirs.value++; } else { countFiles.value++; String path = f.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); if (!path.startsWith("/")) { path = '/' + path; } boolean matched = path.equals(dataRoot + "/file/a.png") || path.equals(dataRoot + "/file/a.txt"); assertTrue(matched); } }); assertEquals(0, countDirs.value); assertEquals(2, countFiles.value); }
/** * Returns <code>true</code> if some JAR file has to be accepted. */ protected boolean acceptJar(final File jarFile) { String path = jarFile.getAbsolutePath(); path = FileNameUtil.separatorsToUnix(path); return rulesJars.match(path); }
/** * Resolves file path depending on {@link Match matching type} * Returned path is formatted in unix style. */ protected String getMatchingFilePath(final File file) { String path = null; switch (matchType) { case FULL_PATH: path = file.getAbsolutePath(); break; case RELATIVE_PATH: path = file.getAbsolutePath(); path = path.substring(rootPath.length()); break; case NAME: path = file.getName(); } path = FileNameUtil.separatorsToUnix(path); return path; }
/** * Converts all separators to the system separator. * * @param path the path to be changed, null ignored * @return the updated path */ public static String separatorsToSystem(final String path) { if (path == null) { return null; } if (SYSTEM_SEPARATOR == WINDOWS_SEPARATOR) { return separatorsToWindows(path); } else { return separatorsToUnix(path); } }