< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java
Print this page
rev 3911 : [mq]: 8171294
*** 500,510 ****
}
private final class ArchiveContainer implements Container {
private final Path archivePath;
private final FileSystem fileSystem;
! private final Map<RelativePath, Path> pathCache = new HashMap<>();
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
this.archivePath = archivePath;
if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
--- 500,510 ----
}
private final class ArchiveContainer implements Container {
private final Path archivePath;
private final FileSystem fileSystem;
! private final Map<RelativePath, Path> packages;
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
this.archivePath = archivePath;
if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
*** 512,521 ****
--- 512,536 ----
Assert.checkNonNull(jarFSProvider, "should have been caught before!");
this.fileSystem = jarFSProvider.newFileSystem(archivePath, env);
} else {
this.fileSystem = FileSystems.newFileSystem(archivePath, null);
}
+ packages = new HashMap<>();
+ for (Path root : fileSystem.getRootDirectories()) {
+ Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
+ new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
+ if (isValid(dir.getFileName())) {
+ packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir);
+ return FileVisitResult.CONTINUE;
+ } else {
+ return FileVisitResult.SKIP_SUBTREE;
+ }
+ }
+ });
+ }
}
/**
* Insert all files in subdirectory subdirectory of this archive
* which match fileKinds into resultList
*** 524,534 ****
public void list(Path userPath,
RelativeDirectory subdirectory,
Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> resultList) throws IOException {
! Path resolvedSubdirectory = resolvePath(subdirectory);
if (resolvedSubdirectory == null)
return ;
int maxDepth = (recurse ? Integer.MAX_VALUE : 1);
--- 539,549 ----
public void list(Path userPath,
RelativeDirectory subdirectory,
Set<JavaFileObject.Kind> fileKinds,
boolean recurse,
ListBuffer<JavaFileObject> resultList) throws IOException {
! Path resolvedSubdirectory = packages.get(subdirectory);
if (resolvedSubdirectory == null)
return ;
int maxDepth = (recurse ? Integer.MAX_VALUE : 1);
*** 542,563 ****
} else {
return FileVisitResult.SKIP_SUBTREE;
}
}
- boolean isValid(Path fileName) {
- if (fileName == null) {
- return true;
- } else {
- String name = fileName.toString();
- if (name.endsWith("/")) {
- name = name.substring(0, name.length() - 1);
- }
- return SourceVersion.isIdentifier(name);
- }
- }
-
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (attrs.isRegularFile() && fileKinds.contains(getKind(file.getFileName().toString()))) {
JavaFileObject fe = PathFileObject.forJarPath(
JavacFileManager.this, file, archivePath);
--- 557,566 ----
*** 567,597 ****
}
});
}
! @Override
! public JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException {
! Path p = resolvePath(name);
! if (p != null)
! return PathFileObject.forJarPath(JavacFileManager.this, p, userPath);
!
! return null;
}
-
- private synchronized Path resolvePath(RelativePath path) {
- if (!pathCache.containsKey(path)) {
- Path relativePath = path.resolveAgainst(fileSystem);
-
- if (!Files.exists(relativePath)) {
- relativePath = null;
}
! pathCache.put(path, relativePath);
! return relativePath;
}
! return pathCache.get(path);
}
@Override
public void close() throws IOException {
fileSystem.close();
--- 570,602 ----
}
});
}
! private boolean isValid(Path fileName) {
! if (fileName == null) {
! return true;
! } else {
! String name = fileName.toString();
! if (name.endsWith("/")) {
! name = name.substring(0, name.length() - 1);
! }
! return SourceVersion.isIdentifier(name);
}
}
! @Override
! public JavaFileObject getFileObject(Path userPath, RelativeFile name) throws IOException {
! RelativeDirectory root = name.dirname();
! Path packagepath = packages.get(root);
! if (packagepath != null) {
! Path relpath = packagepath.resolve(name.basename());
! if (Files.exists(relpath)) {
! return PathFileObject.forJarPath(JavacFileManager.this, relpath, userPath);
}
! }
! return null;
}
@Override
public void close() throws IOException {
fileSystem.close();
< prev index next >