Search in sources :

Example 21 with PathMatcher

use of java.nio.file.PathMatcher in project jetty.project by eclipse.

the class CorrectMavenCentralRefs method fix.

public void fix(Path buildRoot) throws IOException {
    // Find all of the *.mod files
    PathFinder finder = new PathFinder();
    finder.setFileMatcher("glob:**/*.mod");
    finder.setBase(buildRoot);
    // Matcher for target directories
    PathMatcher targetMatcher = PathMatchers.getMatcher("glob:**/target/**");
    PathMatcher testMatcher = PathMatchers.getMatcher("glob:**/test/**");
    System.out.printf("Walking path: %s%n", buildRoot);
    Set<FileVisitOption> options = Collections.emptySet();
    Files.walkFileTree(buildRoot, options, 30, finder);
    System.out.printf("Found: %d hits%n", finder.getHits().size());
    int count = 0;
    for (Path path : finder.getHits()) {
        if (Files.isDirectory(path)) {
            // skip
            continue;
        }
        if (targetMatcher.matches(path)) {
            // skip
            continue;
        }
        if (testMatcher.matches(path)) {
            // skip
            continue;
        }
        if (processModFile(path)) {
            count++;
        }
    }
    System.out.printf("Processed %,d modules", count);
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) FileVisitOption(java.nio.file.FileVisitOption) PathFinder(org.eclipse.jetty.start.PathFinder)

Example 22 with PathMatcher

use of java.nio.file.PathMatcher in project jetty.project by eclipse.

the class RebuildTestResources method copyXmls.

private void copyXmls() throws IOException {
    System.out.println("Copying xmls (etc dir) ...");
    Path xmlDir = destDir.resolve("etc");
    FS.ensureDirExists(xmlDir.toFile());
    PathMatcher matcher = getPathMatcher("glob:**.xml");
    Renamer renamer = new NoRenamer();
    FileCopier copier = new TouchFileCopier();
    copyDir(srcDir.resolve("etc"), xmlDir, matcher, renamer, copier);
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher)

Example 23 with PathMatcher

use of java.nio.file.PathMatcher in project jetty.project by eclipse.

the class RebuildTestResources method copyModules.

private void copyModules() throws IOException {
    System.out.println("Copying modules ...");
    Path modulesDir = destDir.resolve("modules");
    FS.ensureDirExists(modulesDir.toFile());
    PathMatcher matcher = getPathMatcher("glob:**.mod");
    Renamer renamer = new NoRenamer();
    FileCopier copier = new NormalFileCopier();
    copyDir(srcDir.resolve("modules"), modulesDir, matcher, renamer, copier);
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher)

Example 24 with PathMatcher

use of java.nio.file.PathMatcher in project jetty.project by eclipse.

the class RebuildTestResources method copyLibs.

private void copyLibs() throws IOException {
    System.out.println("Copying libs (lib dir) ...");
    Path libsDir = destDir.resolve("lib");
    FS.ensureDirExists(libsDir.toFile());
    PathMatcher matcher = getPathMatcher("glob:**.jar");
    Renamer renamer = new RegexRenamer("-9\\.[0-9.]*(v[0-9-]*)?(-SNAPSHOT)?(RC[0-9])?(M[0-9])?", "-" + JETTY_VERSION);
    FileCopier copier = new TouchFileCopier();
    copyDir(srcDir.resolve("lib"), libsDir, matcher, renamer, copier);
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher)

Example 25 with PathMatcher

use of java.nio.file.PathMatcher in project elasticsearch by elastic.

the class IngestGeoIpPlugin method loadDatabaseReaders.

static Map<String, DatabaseReaderLazyLoader> loadDatabaseReaders(Path geoIpConfigDirectory, NodeCache cache) throws IOException {
    if (Files.exists(geoIpConfigDirectory) == false && Files.isDirectory(geoIpConfigDirectory)) {
        throw new IllegalStateException("the geoip directory [" + geoIpConfigDirectory + "] containing databases doesn't exist");
    }
    Map<String, DatabaseReaderLazyLoader> databaseReaders = new HashMap<>();
    try (Stream<Path> databaseFiles = Files.list(geoIpConfigDirectory)) {
        PathMatcher pathMatcher = geoIpConfigDirectory.getFileSystem().getPathMatcher("glob:**.mmdb.gz");
        // Use iterator instead of forEach otherwise IOException needs to be caught twice...
        Iterator<Path> iterator = databaseFiles.iterator();
        while (iterator.hasNext()) {
            Path databasePath = iterator.next();
            if (Files.isRegularFile(databasePath) && pathMatcher.matches(databasePath)) {
                String databaseFileName = databasePath.getFileName().toString();
                DatabaseReaderLazyLoader holder = new DatabaseReaderLazyLoader(databaseFileName, () -> {
                    try (InputStream inputStream = new GZIPInputStream(Files.newInputStream(databasePath, StandardOpenOption.READ))) {
                        return new DatabaseReader.Builder(inputStream).withCache(cache).build();
                    }
                });
                databaseReaders.put(databaseFileName, holder);
            }
        }
    }
    return Collections.unmodifiableMap(databaseReaders);
}
Also used : Path(java.nio.file.Path) GZIPInputStream(java.util.zip.GZIPInputStream) PathMatcher(java.nio.file.PathMatcher) HashMap(java.util.HashMap) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream)

Aggregations

PathMatcher (java.nio.file.PathMatcher)31 Path (java.nio.file.Path)15 File (java.io.File)9 HashSet (java.util.HashSet)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 Test (org.junit.Test)5 IOException (java.io.IOException)4 FileSystem (java.nio.file.FileSystem)4 ArrayList (java.util.ArrayList)4 EventService (org.eclipse.che.api.core.notification.EventService)4 FileVisitResult (java.nio.file.FileVisitResult)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 Set (java.util.Set)3 ProjectManager (org.eclipse.che.api.project.server.ProjectManager)3