< prev index next > src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
Print this page
static final Path javaHome = FileSystems.getDefault().getPath(System.getProperty("java.home"));
static final Path thisSystemModules = javaHome.resolve("lib").resolve("modules");
Map<Path, FileSystem> fileSystems = new LinkedHashMap<>();
! List<Closeable> closeables = new ArrayList<>();
private String releaseVersion = null;
Locations() {
initHandlers();
}
static final Path javaHome = FileSystems.getDefault().getPath(System.getProperty("java.home"));
static final Path thisSystemModules = javaHome.resolve("lib").resolve("modules");
Map<Path, FileSystem> fileSystems = new LinkedHashMap<>();
! // List of resources to be closed (self-sychronized).
+ private final List<Closeable> closeables = new ArrayList<>();
private String releaseVersion = null;
+ private boolean previewMode = false;
Locations() {
initHandlers();
}
} catch (InvalidPathException ipe) {
throw new IllegalArgumentException(ipe);
}
}
public void close() throws IOException {
ListBuffer<IOException> list = new ListBuffer<>();
! closeables.forEach(closeable -> {
try {
closeable.close();
} catch (IOException ex) {
list.add(ex);
}
! });
if (list.nonEmpty()) {
IOException ex = new IOException();
for (IOException e: list)
ex.addSuppressed(e);
throw ex;
} catch (InvalidPathException ipe) {
throw new IllegalArgumentException(ipe);
}
}
+ private void addCloseable(Closeable c) {
+ synchronized (closeables) {
+ closeables.add(c);
+ }
+ }
+
public void close() throws IOException {
ListBuffer<IOException> list = new ListBuffer<>();
! Closeable[] arr;
+ synchronized (closeables) {
+ arr = closeables.toArray(Closeable[]::new);
+ closeables.clear();
+ }
+ for (Closeable closeable : arr) {
try {
closeable.close();
} catch (IOException ex) {
list.add(ex);
}
! }
if (list.nonEmpty()) {
IOException ex = new IOException();
for (IOException e: list)
ex.addSuppressed(e);
throw ex;
public void setMultiReleaseValue(String multiReleaseValue) {
// Null is implicitly allowed and unsets the value.
this.releaseVersion = multiReleaseValue;
}
+ public void setPreviewMode(boolean previewMode) {
+ // Null is implicitly allowed and unsets the value.
+ this.previewMode = previewMode;
+ }
+
private boolean contains(Collection<Path> searchPath, Path file) throws IOException {
if (searchPath == null) {
return false;
}
try {
Path moduleInfoClass = fs.getPath("classes/module-info.class");
String moduleName = readModuleName(moduleInfoClass);
Path modulePath = fs.getPath("classes");
fileSystems.put(p, fs);
! closeables.add(fs);
fs = null; // prevent fs being closed in the finally clause
return new Pair<>(moduleName, modulePath);
} finally {
if (fs != null)
fs.close();
try {
Path moduleInfoClass = fs.getPath("classes/module-info.class");
String moduleName = readModuleName(moduleInfoClass);
Path modulePath = fs.getPath("classes");
fileSystems.put(p, fs);
! addCloseable(fs);
fs = null; // prevent fs being closed in the finally clause
return new Pair<>(moduleName, modulePath);
} finally {
if (fs != null)
fs.close();
try {
URI jrtURI = URI.create("jrt:/");
FileSystem jrtfs;
if (isCurrentPlatform(systemJavaHome)) {
! jrtfs = FileSystems.getFileSystem(jrtURI);
} else {
try {
Map<String, String> attrMap =
! Collections.singletonMap("java.home", systemJavaHome.toString());
jrtfs = FileSystems.newFileSystem(jrtURI, attrMap);
} catch (ProviderNotFoundException ex) {
URL jfsJar = resolveInJavaHomeLib(systemJavaHome, "jrt-fs.jar").toUri().toURL();
ClassLoader currentLoader = Locations.class.getClassLoader();
URLClassLoader fsLoader =
new URLClassLoader(new URL[] {jfsJar}, currentLoader);
jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader);
! closeables.add(fsLoader);
}
! closeables.add(jrtfs);
}
modules = jrtfs.getPath("/modules");
} catch (FileSystemNotFoundException | ProviderNotFoundException e) {
modules = resolveInJavaHomeLib(systemJavaHome, "modules");
try {
URI jrtURI = URI.create("jrt:/");
FileSystem jrtfs;
if (isCurrentPlatform(systemJavaHome)) {
! JRTIndex jrtIndex = JRTIndex.instance(previewMode);
+ addCloseable(jrtIndex);
+ jrtfs = jrtIndex.getFileSystem();
} else {
try {
Map<String, String> attrMap =
! Map.of("java.home", systemJavaHome.toString(),
+ "previewMode", String.valueOf(previewMode));
jrtfs = FileSystems.newFileSystem(jrtURI, attrMap);
} catch (ProviderNotFoundException ex) {
URL jfsJar = resolveInJavaHomeLib(systemJavaHome, "jrt-fs.jar").toUri().toURL();
ClassLoader currentLoader = Locations.class.getClassLoader();
URLClassLoader fsLoader =
new URLClassLoader(new URL[] {jfsJar}, currentLoader);
jrtfs = FileSystems.newFileSystem(jrtURI, Collections.emptyMap(), fsLoader);
! addCloseable(fsLoader);
}
! addCloseable(jrtfs);
}
modules = jrtfs.getPath("/modules");
} catch (FileSystemNotFoundException | ProviderNotFoundException e) {
modules = resolveInJavaHomeLib(systemJavaHome, "modules");
< prev index next >