< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/file/JRTIndex.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -33,11 +33,10 @@
import java.nio.file.FileSystems;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.ProviderNotFoundException;
-import java.nio.file.spi.FileSystemProvider;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
@@ -93,15 +92,10 @@
* The jrt: file system.
*/
private final FileSystem jrtfs;
/**
- * The set of module directories within the jrt: file system.
- */
- private final Set<Path> jrtModules;
-
- /**
* A lazily evaluated set of entries about the contents of the jrt: file system.
*/
private final Map<RelativeDirectory, SoftReference<Entry>> entries;
/**
@@ -181,18 +175,10 @@
/**
* Create and initialize the index.
*/
private JRTIndex() throws IOException {
jrtfs = FileSystems.getFileSystem(URI.create("jrt:/"));
- jrtModules = new LinkedHashSet<>();
- Path root = jrtfs.getPath("/");
- try (DirectoryStream<Path> stream = Files.newDirectoryStream(root)) {
- for (Path entry: stream) {
- if (Files.isDirectory(entry))
- jrtModules.add(entry);
- }
- }
entries = new HashMap<>();
}
public CtSym getCtSym(CharSequence packageName) throws IOException {
return getEntry(RelativeDirectory.forPackage(packageName)).ctSym;
@@ -202,11 +188,20 @@
SoftReference<Entry> ref = entries.get(rd);
Entry e = (ref == null) ? null : ref.get();
if (e == null) {
Map<String, Path> files = new LinkedHashMap<>();
Set<RelativeDirectory> subdirs = new LinkedHashSet<>();
- for (Path module: jrtModules) {
+ Path dir;
+ if (rd.path.isEmpty()) {
+ dir = jrtfs.getPath("/modules");
+ } else {
+ Path pkgs = jrtfs.getPath("/packages");
+ dir = pkgs.resolve(rd.getPath().replaceAll("/$", "").replace("/", "."));
+ }
+ if (Files.exists(dir)) {
+ try (DirectoryStream<Path> modules = Files.newDirectoryStream(dir)) {
+ for (Path module: modules) {
Path p = rd.getFile(module);
if (!Files.exists(p))
continue;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {
for (Path entry: stream) {
@@ -218,10 +213,12 @@
subdirs.add(new RelativeDirectory(rd, name));
}
}
}
}
+ }
+ }
e = new Entry(Collections.unmodifiableMap(files),
Collections.unmodifiableSet(subdirs),
getCtInfo(rd));
entries.put(rd, new SoftReference<>(e));
}
< prev index next >