public static FileMatcher getMatcher(File file) { return getMatcher(file.getName()); }
public PatternFileRef(File file) { File dir = file.getParentFile(); File[] files = dir.listFiles(); if (files != null) { FileMatcher fm = FileMatcher.getMatcher(file); for (File f : files) { if (fm.match(f.getName())) { key = fm.getKey(); value = fm.getValue(); this.file = f; break; } } } }
public static Match<File> find(File filePattern) { File dir = filePattern.getParentFile(); File[] files = dir.listFiles(); if (files != null) { FileMatcher fm = FileMatcher.getMatcher(filePattern.getName().concat("-{v:r?[0-9]+.*}\\.jar")); String studioSnapshotName = filePattern.getName().concat(".jar"); for (File f : files) { if (fm.match(f.getName())) { Match<File> result = new Match<File>(); result.version = fm.getValue(); result.object = f; return result; } if (studioSnapshotName.equals(f.getName())) { Match<File> result = new Match<File>(); result.version = UpdateManager.STUDIO_SNAPSHOT_VERSION; result.object = f; return result; } } } return null; }
/** * Look for a matching file for the given path. * * @param path Searched file path, optionally including the pattern. * @param map The pattern variable will be put in the given map if any. Since 5.5, map can be null. * @return File found. Null if none. */ public static File getMatchingFile(String path, Map<String, Object> map) { File file = new File(path); FileMatcher matcher = getMatcher(path); if (matcher.getPattern() == null) { return file; } // a pattern -> find the first file that match that pattern File dir = file.getParentFile(); File[] list = dir.listFiles(); if (list != null) { for (File f : list) { if (matcher.match(f.getName())) { if (map != null) { map.put(matcher.getKey(), matcher.getValue()); } return f; } } } return null; }
FileMatcher filenameMatcher = FileMatcher.getMatcher("{n:.*-}[0-9]+.*\\.jar"); boolean isVersionnedJarFile = filenameMatcher.match(fileToCopy.getName()); if (isVersionnedJarFile) { FileMatcher versionMatcher = FileMatcher.getMatcher(filenameWithoutVersion + "{v:[0-9]+.*}\\.jar");