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);
}
});
}
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);
}
}
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);
}
}));
}
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")));
}
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();
}
Aggregations