@Override public PathMatcher getPathMatcher(String syntaxAndPattern) { return delegate.getPathMatcher(syntaxAndPattern); }
private ArrayList<PathMatcher> buildPatterns(List<String> patterns) { FileSystem fileSystem = FileSystems.getDefault(); ArrayList<PathMatcher> matchers = new ArrayList<>(patterns.size()); for (String patternStr : patterns) { matchers.add(fileSystem.getPathMatcher("glob:" + patternStr)); } return matchers; }
private PathMatcher globMatcher(String fieldGlobPattern) { return FileSystems.getDefault().getPathMatcher("glob:" + fieldGlobPattern); }
@Override public PathMatcher getPathMatcher(String syntaxAndPattern) { return FileSystems.getDefault().getPathMatcher(syntaxAndPattern); }
public GlobPathMatcher(final String expression) { this.expression = expression.trim(); this.matcher = FileSystems.getDefault().getPathMatcher("glob:" + this.expression); }
public void insertLineRecursive(final String baseFileNameGlob, final Pattern pattern, final StringUpsert stringUpsert) throws IOException { final ImmutableList.Builder<Matcher> matchers = ImmutableList.<Matcher>builder(); final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + baseFileNameGlob); Files.walkFileTree(this.basePath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes attributes) throws IOException { if (pathMatcher.matches(filePath.getFileName())) { insertLine(filePath, pattern, stringUpsert); } return FileVisitResult.CONTINUE; } }); }
public static MountPredicate include(final String glob) { checkNotNullOrEmpty(glob, "Glob should not be null or empty"); final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); return new MountPredicate() { @Override public boolean apply(final String filename) { return matcher.matches(Paths.get(filename)); } }; }
@Signature public static boolean match(String path, String pattern) { PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(pattern); return pathMatcher.matches(Paths.get(path)); }
public List<Matcher> matchersRecursive(final String baseFileNameGlob, final Pattern pattern) throws IOException { final ImmutableList.Builder<Matcher> matchers = ImmutableList.<Matcher>builder(); final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + baseFileNameGlob); Files.walkFileTree(this.basePath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes attributes) throws IOException { if (pathMatcher.matches(filePath.getFileName())) { final Matcher matcher = pattern.matcher(read(filePath)); if (matcher.find()) { matchers.add(matcher); } } return FileVisitResult.CONTINUE; } }); return matchers.build(); }
/** * Finder constructor. * * @param includeSet file paths that should be analyzed * @param excludeSet file paths that should be ignored * @param base location of .tailor.yml file */ public Finder(Set<String> includeSet, Set<String> excludeSet, URI base) { this.includeMatcher = includeSet .stream() .map(includePattern -> FileSystems.getDefault().getPathMatcher("glob:" + includePattern)) .collect(Collectors.toSet()); this.excludeMatcher = excludeSet .stream() .map(excludePattern -> FileSystems.getDefault().getPathMatcher("glob:" + excludePattern)) .collect(Collectors.toSet()); this.base = base; }
private static PathMatcher buildPathMatcherForBaseFileNamePrefix(final String baseFileNamePrefix) { final StringBuilder builder = buildGlobPatternStringBuilder(baseFileNamePrefix); return FileSystems.getDefault().getPathMatcher("glob:" + builder.toString() + "*"); }
private static ImmutableList<String> doGlob(final Path path, final Path searchPath) { final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + path); try { final ImmutableList.Builder<String> builder = ImmutableList.builder(); Files.walkFileTree(searchPath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (matcher.matches(file)) { builder.add(file.toString()); } return FileVisitResult.CONTINUE; } }); return builder.build(); } catch (IOException e) { throw new MocoException(e); } }
private static PathMatcher buildPathMatcherForDirectory(final Path dir) { final String dirString = dir.toString(); final int dirLength = dirString.length(); final StringBuilder builder = buildGlobPatternStringBuilder(dirString); // |dir| can be empty when just a file/directory name directly on the working directory is given. For example, // // path_prefix: file.txt if (dirLength > 1 && builder.charAt(dirLength - 1) != File.separatorChar) { if (File.separatorChar == '\\') { builder.append('\\'); } builder.append(File.separator); } return FileSystems.getDefault().getPathMatcher("glob:" + builder.toString() + "**"); }
private static PathMatcher pathMatcher(final String expressions) { List<PathMatcher> matchers = new ArrayList<>(); for (String expression : expressions.split(File.pathSeparator)) { matchers.add(FileSystems.getDefault().getPathMatcher("glob:" + expression.trim())); } return new PathMatcher() { @Override public boolean matches(final Path path) { for (PathMatcher matcher : matchers) { if (matcher.matches(path)) { return true; } } return false; } @Override public String toString() { return "[" + expressions + "]"; } }; }
@Signature(@Arg("pattern")) public Memory matches(Environment env, Memory... args) { FileSystem aDefault = FileSystems.getDefault(); PathMatcher pathMatcher = aDefault.getPathMatcher(args[0].toString()); return pathMatcher.matches(aDefault.getPath(file.getPath())) ? Memory.TRUE : Memory.FALSE; }
/** * Search for all {@link #YAML_FILES_PATTERN} in provided base path * * @param path base path to start (can be file or directory) * @return list of all paths matching pattern. Only base file itself if it is a file matching pattern */ public List<Path> configs(String path) throws ConfiguratorException { final PathMatcher matcher = FileSystems.getDefault().getPathMatcher(YAML_FILES_PATTERN); final Path root = Paths.get(path); if (!Files.exists(root)) { throw new ConfiguratorException("Invalid configuration: '"+path+"' isn't a valid path."); } if (!Files.isDirectory(root)) { return matcher.matches(root) ? Collections.singletonList(root) : Collections.emptyList(); } try { return Files.list(root) .filter(Files::isRegularFile) // only consider regular files, following symlinks .filter(matcher::matches) // matching pattern .collect(toList()); } catch (IOException e) { throw new IllegalStateException("failed config scan for " + path, e); } }
public List<String> getBundledCasCURIs() { final String cascFile = "/WEB-INF/" + DEFAULT_JENKINS_YAML_PATH; final String cascDirectory = "/WEB-INF/" + DEFAULT_JENKINS_YAML_PATH + ".d/"; List<String> res = new ArrayList<>(); final ServletContext servletContext = Jenkins.getInstance().servletContext; try { URL bundled = servletContext.getResource(cascFile); if (bundled != null) { res.add(bundled.toString()); } } catch (IOException e) { LOGGER.log(WARNING, "Failed to load " + cascFile, e); } PathMatcher matcher = FileSystems.getDefault().getPathMatcher(YAML_FILES_PATTERN); Set<String> resources = servletContext.getResourcePaths(cascDirectory); if (resources!=null) { // sort to execute them in a deterministic order for (String cascItem : new TreeSet<>(resources)) { try { URL bundled = servletContext.getResource(cascItem); if (bundled != null && matcher.matches(new File(bundled.getPath()).toPath())) { res.add(bundled.toString()); } //TODO: else do some handling? } catch (IOException e) { LOGGER.log(WARNING, "Failed to execute " + res, e); } } } return res; }
/** * Parse all IGFS log files in specified log directory. * * @param logDir Folder were log files located. * @return List of line with aggregated information by files. */ private List<VisorIgfsProfilerEntry> parse(Path logDir, String igfsName) throws IOException { List<VisorIgfsProfilerEntry> parsedFiles = new ArrayList<>(512); try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(logDir)) { PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:igfs-log-" + igfsName + "-*.csv"); for (Path p : dirStream) { if (matcher.matches(p.getFileName())) { try { parsedFiles.addAll(parseFile(p)); } catch (NoSuchFileException ignored) { // Files was deleted, skip it. } catch (Exception e) { ignite.log().warning("Failed to parse IGFS profiler log file: " + p, e); } } } } return parsedFiles; }
PathMatcher matcher = FileSystems.getDefault().getPathMatcher( "glob:igfs-log-" + arg.getIgfsName() + "-*.csv");
@Test public void testMatcher() throws IOException { try (FileSystem fs = CloudStorageFileSystem.forBucket("bucket")) { String pattern1 = "glob:*.java"; PathMatcher javaFileMatcher = fs.getPathMatcher(pattern1); assertMatches(fs, javaFileMatcher, "a.java", true); assertMatches(fs, javaFileMatcher, "a.text", false); assertMatches(fs, javaFileMatcher, "folder/c.java", true); assertMatches(fs, javaFileMatcher, "d", false); String pattern2 = "glob:*.{java,text}"; PathMatcher javaAndTextFileMatcher = fs.getPathMatcher(pattern2); assertMatches(fs, javaAndTextFileMatcher, "a.java", true); assertMatches(fs, javaAndTextFileMatcher, "a.text", true); assertMatches(fs, javaAndTextFileMatcher, "folder/c.java", true); assertMatches(fs, javaAndTextFileMatcher, "d", false); } }