Search in sources :

Example 81 with PathMatcher

use of java.nio.file.PathMatcher in project jadx by skylot.

the class JavaConvertLoader method processJars.

private static void processJars(List<Path> input, ConvertResult result) {
    PathMatcher jarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.jar");
    input.stream().filter(jarMatcher::matches).forEach(path -> {
        try {
            convertJar(result, path);
        } catch (Exception e) {
            LOG.error("Failed to convert file: {}", path.toAbsolutePath(), e);
        }
    });
}
Also used : PathMatcher(java.nio.file.PathMatcher) IOException(java.io.IOException)

Example 82 with PathMatcher

use of java.nio.file.PathMatcher in project jadx by skylot.

the class JavaConvertLoader method processClassFiles.

private static void processClassFiles(List<Path> input, ConvertResult result) {
    PathMatcher jarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.class");
    List<Path> clsFiles = input.stream().filter(jarMatcher::matches).collect(Collectors.toList());
    if (clsFiles.isEmpty()) {
        return;
    }
    try {
        LOG.debug("Converting class files ...");
        Path jarFile = Files.createTempFile("jadx-", ".jar");
        try (JarOutputStream jo = new JarOutputStream(Files.newOutputStream(jarFile))) {
            for (Path file : clsFiles) {
                String clsName = AsmUtils.getNameFromClassFile(file);
                if (clsName == null || !ZipSecurity.isValidZipEntryName(clsName)) {
                    throw new IOException("Can't read class name from file: " + file);
                }
                addFileToJar(jo, file, clsName + ".class");
            }
        }
        result.addTempPath(jarFile);
        LOG.debug("Packed {} class files into jar: {}", clsFiles.size(), jarFile);
        convertJar(result, jarFile);
    } catch (Exception e) {
        LOG.error("Error process class files", e);
    }
}
Also used : Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 83 with PathMatcher

use of java.nio.file.PathMatcher in project jadx by skylot.

the class JavaConvertLoader method processAars.

private static void processAars(List<Path> input, ConvertResult result) {
    PathMatcher aarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.aar");
    input.stream().filter(aarMatcher::matches).forEach(path -> ZipSecurity.readZipEntries(path.toFile(), (entry, in) -> {
        try {
            String entryName = entry.getName();
            if (entryName.endsWith(".jar")) {
                Path tempJar = CommonFileUtils.saveToTempFile(in, ".jar");
                result.addTempPath(tempJar);
                LOG.debug("Loading jar: {} ...", entryName);
                convertJar(result, tempJar);
            }
        } catch (Exception e) {
            LOG.error("Failed to process zip entry: {}", entry, e);
        }
    }));
}
Also used : Logger(org.slf4j.Logger) Files(java.nio.file.Files) CommonFileUtils(jadx.api.plugins.utils.CommonFileUtils) LoggerFactory(org.slf4j.LoggerFactory) FileTime(java.nio.file.attribute.FileTime) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) LinkOption(java.nio.file.LinkOption) JarEntry(java.util.jar.JarEntry) List(java.util.List) Stream(java.util.stream.Stream) ZipSecurity(jadx.api.plugins.utils.ZipSecurity) PathMatcher(java.nio.file.PathMatcher) Path(java.nio.file.Path) JarOutputStream(java.util.jar.JarOutputStream) FileSystems(java.nio.file.FileSystems) Path(java.nio.file.Path) PathMatcher(java.nio.file.PathMatcher) IOException(java.io.IOException)

Example 84 with PathMatcher

use of java.nio.file.PathMatcher in project j2objc by google.

the class MacOSXFileSystemTest method test_getPathMatcher_glob.

@Test
public void test_getPathMatcher_glob() {
    PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + "*.java");
    assertTrue(pathMatcher.matches(Paths.get("f.java")));
    assertFalse(pathMatcher.matches(Paths.get("f")));
    pathMatcher = fileSystem.getPathMatcher("glob:" + "*.*");
    assertTrue(pathMatcher.matches(Paths.get("f.t")));
    assertFalse(pathMatcher.matches(Paths.get("f")));
    pathMatcher = fileSystem.getPathMatcher("glob:" + "*.{java,class}");
    assertTrue(pathMatcher.matches(Paths.get("f.java")));
    assertTrue(pathMatcher.matches(Paths.get("f.class")));
    assertFalse(pathMatcher.matches(Paths.get("f.clas")));
    assertFalse(pathMatcher.matches(Paths.get("f.t")));
    pathMatcher = fileSystem.getPathMatcher("glob:" + "f.?");
    assertTrue(pathMatcher.matches(Paths.get("f.t")));
    assertFalse(pathMatcher.matches(Paths.get("f.tl")));
    assertFalse(pathMatcher.matches(Paths.get("f.")));
    pathMatcher = fileSystem.getPathMatcher("glob:" + "/home/*/*");
    assertTrue(pathMatcher.matches(Paths.get("/home/f/d")));
    assertTrue(pathMatcher.matches(Paths.get("/home/f/*")));
    assertTrue(pathMatcher.matches(Paths.get("/home/*/*")));
    assertFalse(pathMatcher.matches(Paths.get("/home/f")));
    assertFalse(pathMatcher.matches(Paths.get("/home/f/d/d")));
    pathMatcher = fileSystem.getPathMatcher("glob:" + "/home/**");
    assertTrue(pathMatcher.matches(Paths.get("/home/f/d")));
    assertTrue(pathMatcher.matches(Paths.get("/home/f/*")));
    assertTrue(pathMatcher.matches(Paths.get("/home/*/*")));
    assertTrue(pathMatcher.matches(Paths.get("/home/f")));
    assertTrue(pathMatcher.matches(Paths.get("/home/f/d/d")));
    assertTrue(pathMatcher.matches(Paths.get("/home/f/d/d/d")));
}
Also used : PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 85 with PathMatcher

use of java.nio.file.PathMatcher in project jimfs by google.

the class PathServiceTest method assertCaseSensitiveMatches.

private static void assertCaseSensitiveMatches(PathService service) {
    PathMatcher matcher = service.createPathMatcher("glob:foo");
    JimfsPath lowerCasePath = singleNamePath(service, "foo");
    JimfsPath upperCasePath = singleNamePath(service, "FOO");
    assertThat(matcher.matches(lowerCasePath)).isTrue();
    assertThat(matcher.matches(upperCasePath)).isFalse();
}
Also used : PathMatcher(java.nio.file.PathMatcher)

Aggregations

PathMatcher (java.nio.file.PathMatcher)87 Path (java.nio.file.Path)40 Test (org.junit.Test)23 IOException (java.io.IOException)22 File (java.io.File)16 ArrayList (java.util.ArrayList)12 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)10 FileVisitResult (java.nio.file.FileVisitResult)9 Files (java.nio.file.Files)5 Paths (java.nio.file.Paths)5 HashSet (java.util.HashSet)5 List (java.util.List)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