diff options
author | Glavo <zjx001202@126.com> | 2019-12-06 03:42:00 +0800 |
---|---|---|
committer | Glavo <zjx001202@126.com> | 2019-12-06 03:42:00 +0800 |
commit | e48c0668029849af07d1966729c5b703e89b1d00 (patch) | |
tree | fec378e2c6e52d86e601f0df45ba13728003fa2b /src/main/java/org/glavo/javah/ModulePath.java | |
parent | 6fd5804e3f2c337839efcf5c10426faed1d8b1af (diff) | |
download | gjavah-e48c0668029849af07d1966729c5b703e89b1d00.tar.gz gjavah-e48c0668029849af07d1966729c5b703e89b1d00.tar.bz2 gjavah-e48c0668029849af07d1966729c5b703e89b1d00.zip |
update
Diffstat (limited to 'src/main/java/org/glavo/javah/ModulePath.java')
-rw-r--r-- | src/main/java/org/glavo/javah/ModulePath.java | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/main/java/org/glavo/javah/ModulePath.java b/src/main/java/org/glavo/javah/ModulePath.java index b355b24..0a9c2cc 100644 --- a/src/main/java/org/glavo/javah/ModulePath.java +++ b/src/main/java/org/glavo/javah/ModulePath.java @@ -1,34 +1,46 @@ package org.glavo.javah; import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.util.Collections; +import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; public class ModulePath implements SearchPath { private final Path path; - private final List<Path> paths; + private List<Path> roots; public ModulePath(Path path) { Objects.requireNonNull(path); - + path = path.toAbsolutePath(); this.path = path; - try { - paths = Files.list(path) - .filter(Files::isRegularFile) - .flatMap(p -> Utils.getPathsFrom(p).stream()) - .collect(Collectors.toList()); - } catch (IOException e) { - throw new UncheckedIOException(e); + if (Files.notExists(path) || !Files.isDirectory(path)) { + roots = Collections.emptyList(); + } else { + try { + roots = Files.list(path) + .map(Path::toAbsolutePath) + .filter(Files::isRegularFile) + .filter(p -> { + String n = p.getFileName().toString().toLowerCase(); + return n.endsWith(".jar") || n.endsWith(".zip") || n.endsWith(".jmod"); + }) + .map(Utils::classPathRoot) + .filter(Objects::nonNull) + .flatMap(p -> SearchPath.multiReleaseRoots(p).stream()) + .collect(Collectors.toList()); + } catch (IOException e) { + roots = Collections.emptyList(); + } } } @Override - public Path searchClass(String className) { - return Utils.searchFrom(paths, className); + public Path search(ClassName name) { + Objects.requireNonNull(name); + return SearchPath.searchFromRoots(roots, name); } @Override |