Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2017-07-06 07:43:33 -0400
committerJay Arthanareeswaran2017-09-18 09:12:45 -0400
commitc798229d351d6daa2232cff6c15750336659223e (patch)
tree24fcc71a360db7f1b71ee743ab823ab51c1d891d /org.eclipse.jdt.compiler.apt
parent062ac5d7a6bf9c9d3013dabfd6e3cb8633f7baec (diff)
downloadeclipse.jdt.core-c798229d351d6daa2232cff6c15750336659223e.tar.gz
eclipse.jdt.core-c798229d351d6daa2232cff6c15750336659223e.tar.xz
eclipse.jdt.core-c798229d351d6daa2232cff6c15750336659223e.zip
Bug 477291: [1.9] Support JRE 9 in JSR199 implementation
Change-Id: Idfbcd6c2e40fbbc1a325dbe43950284404642fc8 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.apt')
-rw-r--r--org.eclipse.jdt.compiler.apt/.classpath1
-rw-r--r--org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jdt.compiler.apt/build.properties8
-rw-r--r--org.eclipse.jdt.compiler.apt/lib/java9api.jarbin0 -> 25089 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt/pom.xml21
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Archive.java4
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java672
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileObject.java4
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java188
-rw-r--r--org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/ModuleLocationHandler.java246
10 files changed, 877 insertions, 269 deletions
diff --git a/org.eclipse.jdt.compiler.apt/.classpath b/org.eclipse.jdt.compiler.apt/.classpath
index 22f30643cb..f9ab0b3e57 100644
--- a/org.eclipse.jdt.compiler.apt/.classpath
+++ b/org.eclipse.jdt.compiler.apt/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="lib" path="lib/java9api.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
diff --git a/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF b/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF
index 7889ff9f42..32050d710e 100644
--- a/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.compiler.apt/META-INF/MANIFEST.MF
@@ -12,3 +12,5 @@ Export-Package: org.eclipse.jdt.internal.compiler.apt.dispatch;x-friends:="org.e
org.eclipse.jdt.internal.compiler.apt.util;x-friends:="org.eclipse.jdt.apt.pluggable.core",
org.eclipse.jdt.internal.compiler.lookup;x-friends:="org.eclipse.jdt.apt.pluggable.core"
Import-Package: org.eclipse.jdt.internal.compiler.tool;resolution:=optional
+Bundle-ClassPath: lib/java9api.jar,
+ .
diff --git a/org.eclipse.jdt.compiler.apt/build.properties b/org.eclipse.jdt.compiler.apt/build.properties
index c0fba21c9b..958fe58146 100644
--- a/org.eclipse.jdt.compiler.apt/build.properties
+++ b/org.eclipse.jdt.compiler.apt/build.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2005, 2007 IBM Corporation and others.
+# Copyright (c) 2005, 2017 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -12,11 +12,11 @@ customBuildCallbacks=customBuildCallbacks.xml
bin.includes = .,\
META-INF/,\
about.html,\
- compiler_apt_fragment.properties
-
+ compiler_apt_fragment.properties,\
+ lib/java9api.jar
src.includes = about.html
jars.compile.order = .
output.. = bin/
source.. = src/
-
+jars.extra.classpath = lib/java9api.jar
diff --git a/org.eclipse.jdt.compiler.apt/lib/java9api.jar b/org.eclipse.jdt.compiler.apt/lib/java9api.jar
new file mode 100644
index 0000000000..fd56ad100e
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt/lib/java9api.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt/pom.xml b/org.eclipse.jdt.compiler.apt/pom.xml
index e8b2e30672..8b9ef7e34f 100644
--- a/org.eclipse.jdt.compiler.apt/pom.xml
+++ b/org.eclipse.jdt.compiler.apt/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2016 Eclipse Foundation and others.
+ Copyright (c) 2012, 2017 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -23,6 +23,25 @@
<build>
<plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-compiler-plugin</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <configuration>
+ <compilerArgs>
+ <args>-endorseddirs</args>
+ <args>${basedir}/lib</args>
+ </compilerArgs>
+ <!-- Use this form for Tycho 23 or greater -->
+ <log>xml</log>
+ <logDirectory>${project.build.directory}/compilelogs</logDirectory>
+ <showWarnings>true</showWarnings>
+ <excludeResources>
+ <exclude>**/package.html</exclude>
+ </excludeResources>
+ <useProjectSettings>false</useProjectSettings>
+ </configuration>
+ </plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Archive.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Archive.java
index 8b46bbb4fc..3f8da7c636 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Archive.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Archive.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2016 IBM Corporation and others.
+ * Copyright (c) 2006, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -75,7 +75,7 @@ public class Archive {
}
}
- public ArchiveFileObject getArchiveFileObject(String fileName, Charset charset) {
+ public ArchiveFileObject getArchiveFileObject(String fileName, String module, Charset charset) {
return new ArchiveFileObject(this.file, fileName, charset);
}
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java
index 4f287645bf..76d1b62df7 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java
@@ -22,20 +22,27 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
+import java.util.Objects;
import java.util.ResourceBundle;
+import java.util.ServiceLoader;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.zip.ZipException;
+import javax.lang.model.SourceVersion;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
@@ -43,14 +50,25 @@ import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
+import org.eclipse.jdt.internal.compiler.apt.util.JrtFileSystem.JrtFileObject;
+import org.eclipse.jdt.internal.compiler.apt.util.ModuleLocationHandler.LocationContainer;
+import org.eclipse.jdt.internal.compiler.apt.util.ModuleLocationHandler.LocationWrapper;
+import org.eclipse.jdt.internal.compiler.apt.util.ModuleLocationHandler.ModuleLocationWrapper;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
+import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
import org.eclipse.jdt.internal.compiler.batch.Main;
import org.eclipse.jdt.internal.compiler.batch.Main.ResourceBundleFactory;
+import org.eclipse.jdt.internal.compiler.batch.ModuleFinder;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
import org.eclipse.jdt.internal.compiler.env.AccessRule;
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.compiler.parser.Parser;
+import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
+import org.eclipse.jdt.internal.compiler.util.Util;
/**
* Implementation of the Standard Java File Manager
@@ -61,27 +79,30 @@ public class EclipseFileManager implements StandardJavaFileManager {
static final int HAS_BOOTCLASSPATH = 2;
static final int HAS_ENDORSED_DIRS = 4;
static final int HAS_PROCESSORPATH = 8;
+ static final int HAS_PROC_MODULEPATH = 16;
Map<File, Archive> archivesCache;
Charset charset;
Locale locale;
- Map<String, Iterable<? extends File>> locations;
+ ModuleLocationHandler locationHandler;
final Map<Location, URLClassLoader> classloaders;
int flags;
+ boolean isOnJvm9;
+ File jrtHome;
+ JrtFileSystem jrtSystem;
public ResourceBundle bundle;
public EclipseFileManager(Locale locale, Charset charset) {
this.locale = locale == null ? Locale.getDefault() : locale;
this.charset = charset == null ? Charset.defaultCharset() : charset;
- this.locations = new HashMap<>();
+ this.locationHandler = new ModuleLocationHandler();
this.classloaders = new HashMap<>();
this.archivesCache = new HashMap<>();
+ this.isOnJvm9 = isRunningJvm9();
try {
- this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
- Iterable<? extends File> defaultClasspath = getDefaultClasspath();
- this.setLocation(StandardLocation.CLASS_PATH, defaultClasspath);
- this.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, defaultClasspath);
+ initialize(Util.getJavaHome());
} catch (IOException e) {
+ e.printStackTrace();
// ignore
}
try {
@@ -90,13 +111,27 @@ public class EclipseFileManager implements StandardJavaFileManager {
System.out.println("Missing resource : " + Main.bundleName.replace('.', '/') + ".properties for locale " + locale); //$NON-NLS-1$//$NON-NLS-2$
}
}
+ protected void initialize(File javahome) throws IOException {
+ if (this.isOnJvm9) {
+ this.jrtSystem = new JrtFileSystem(javahome);
+ this.archivesCache.put(javahome, this.jrtSystem);
+ this.jrtHome = javahome;
+ this.locationHandler.newSystemLocation(StandardLocation.SYSTEM_MODULES, this.jrtSystem);
+ } else {
+ this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
+ }
+ Iterable<? extends File> defaultClasspath = getDefaultClasspath();
+ this.setLocation(StandardLocation.CLASS_PATH, defaultClasspath);
+ // No annotation module path by default
+ this.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, defaultClasspath);
+ }
/* (non-Javadoc)
* @see javax.tools.JavaFileManager#close()
*/
@Override
public void close() throws IOException {
- if (this.locations != null) this.locations.clear();
+ this.locationHandler.close();
for (Archive archive : this.archivesCache.values()) {
archive.close();
}
@@ -107,35 +142,18 @@ public class EclipseFileManager implements StandardJavaFileManager {
this.classloaders.clear();
}
- private void collectAllMatchingFiles(File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) {
- if (!isArchive(file)) {
- // we must have a directory
- File currentFile = new File(file, normalizedPackageName);
- if (!currentFile.exists()) return;
- String path;
- try {
- path = currentFile.getCanonicalPath();
- } catch (IOException e) {
- return;
- }
- if (File.separatorChar == '/') {
- if (!path.endsWith(normalizedPackageName)) return;
- } else if (!path.endsWith(normalizedPackageName.replace('/', File.separatorChar))) return;
- File[] files = currentFile.listFiles();
- if (files != null) {
- // this was a directory
- for (File f : files) {
- if (f.isDirectory() && recurse) {
- collectAllMatchingFiles(file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector);
- } else {
- final Kind kind = getKind(f);
- if (kinds.contains(kind)) {
- collector.add(new EclipseFileObject(normalizedPackageName + f.getName(), f.toURI(), kind, this.charset));
- }
+ private void collectAllMatchingFiles(Location location, File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) {
+ if (file.equals(this.jrtHome)) {
+ if (location instanceof ModuleLocationWrapper) {
+ List<JrtFileObject> list = this.jrtSystem.list((ModuleLocationWrapper) location, normalizedPackageName, kinds, recurse, this.charset);
+ for (JrtFileObject fo : list) {
+ Kind kind = getKind(getExtension(fo.entryName));
+ if (kinds.contains(kind)) {
+ collector.add(fo);
}
}
}
- } else {
+ } else if (isArchive(file)) {
Archive archive = this.getArchive(file);
if (archive == Archive.UNKNOWN_ARCHIVE) return;
String key = normalizedPackageName;
@@ -151,8 +169,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
for (String[] entry : types) {
final Kind kind = getKind(getExtension(entry[0]));
if (kinds.contains(kind)) {
- // TODO BETA_JAVA9 - entry[1] contains the module, use it.
- collector.add(archive.getArchiveFileObject(packageName + entry[0], this.charset));
+ collector.add(archive.getArchiveFileObject(packageName + entry[0], entry[1], this.charset));
}
}
}
@@ -164,8 +181,34 @@ public class EclipseFileManager implements StandardJavaFileManager {
for (String[] entry : types) {
final Kind kind = getKind(getExtension(entry[0]));
if (kinds.contains(kind)) {
- // TODO BETA_JAVA9 - entry[1] contains the module, use it.
- collector.add(archive.getArchiveFileObject(key + entry[0], this.charset));
+ collector.add(archive.getArchiveFileObject(key + entry[0], entry[1], this.charset));
+ }
+ }
+ }
+ }
+ } else {
+ // we must have a directory
+ File currentFile = new File(file, normalizedPackageName);
+ if (!currentFile.exists()) return;
+ String path;
+ try {
+ path = currentFile.getCanonicalPath();
+ } catch (IOException e) {
+ return;
+ }
+ if (File.separatorChar == '/') {
+ if (!path.endsWith(normalizedPackageName)) return;
+ } else if (!path.endsWith(normalizedPackageName.replace('/', File.separatorChar))) return;
+ File[] files = currentFile.listFiles();
+ if (files != null) {
+ // this was a directory
+ for (File f : files) {
+ if (f.isDirectory() && recurse) {
+ collectAllMatchingFiles(location, file, normalizedPackageName + '/' + f.getName(), kinds, recurse, collector);
+ } else {
+ final Kind kind = getKind(f);
+ if (kinds.contains(kind)) {
+ collector.add(new EclipseFileObject(normalizedPackageName + f.getName(), f.toURI(), kind, this.charset));
}
}
}
@@ -223,6 +266,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public ClassLoader getClassLoader(Location location) {
+ validateNonModuleLocation(location);
Iterable<? extends File> files = getLocation(location);
if (files == null) {
// location is unknown
@@ -342,6 +386,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
+ validateNonModuleLocation(location);
Iterable<? extends File> files = getLocation(location);
if (files == null) {
throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
@@ -361,7 +406,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
Archive archive = getArchive(file);
if (archive != Archive.UNKNOWN_ARCHIVE) {
if (archive.contains(normalizedFileName)) {
- return archive.getArchiveFileObject(normalizedFileName, this.charset);
+ return archive.getArchiveFileObject(normalizedFileName, null, this.charset);
}
}
}
@@ -385,6 +430,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
@Override
public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling)
throws IOException {
+ validateOutputLocation(location);
Iterable<? extends File> files = getLocation(location);
if (files == null) {
throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
@@ -405,6 +451,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
+ validateNonModuleLocation(location);
if (kind != Kind.CLASS && kind != Kind.SOURCE) {
throw new IllegalArgumentException("Invalid kind : " + kind);//$NON-NLS-1$
}
@@ -428,7 +475,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
Archive archive = getArchive(file);
if (archive != Archive.UNKNOWN_ARCHIVE) {
if (archive.contains(normalizedFileName)) {
- return archive.getArchiveFileObject(normalizedFileName, this.charset);
+ return archive.getArchiveFileObject(normalizedFileName, null, this.charset);
}
}
}
@@ -442,6 +489,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling)
throws IOException {
+ validateOutputLocation(location);
if (kind != Kind.CLASS && kind != Kind.SOURCE) {
throw new IllegalArgumentException("Invalid kind : " + kind);//$NON-NLS-1$
}
@@ -554,8 +602,14 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public Iterable<? extends File> getLocation(Location location) {
- if (this.locations == null) return null;
- return this.locations.get(location.getName());
+ if (location instanceof LocationWrapper) {
+ return getFiles(((LocationWrapper) location).paths);
+ }
+ LocationWrapper loc = this.locationHandler.getLocation(location, ""); //$NON-NLS-1$
+ if (loc == null) {
+ return null;
+ }
+ return getFiles(loc.getPaths());
}
private Iterable<? extends File> getOutputDir(String string) {
@@ -577,123 +631,193 @@ public class EclipseFileManager implements StandardJavaFileManager {
@Override
public boolean handleOption(String current, Iterator<String> remaining) {
try {
- if ("-bootclasspath".equals(current)) {//$NON-NLS-1$
- if (remaining.hasNext()) {
- final Iterable<? extends File> bootclasspaths = getPathsFrom(remaining.next());
- if (bootclasspaths != null) {
- Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
- if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0
- && (this.flags & EclipseFileManager.HAS_EXT_DIRS) == 0) {
- // override default bootclasspath
- setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspaths);
- } else if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) != 0) {
- // endorseddirs have been processed first
- setLocation(StandardLocation.PLATFORM_CLASS_PATH,
- concatFiles(iterable, bootclasspaths));
- } else {
- // extdirs have been processed first
- setLocation(StandardLocation.PLATFORM_CLASS_PATH,
- prependFiles(iterable, bootclasspaths));
+ switch(current) {
+ case "-bootclasspath": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> bootclasspaths = getPathsFrom(remaining.next());
+ if (bootclasspaths != null) {
+ Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
+ if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0
+ && (this.flags & EclipseFileManager.HAS_EXT_DIRS) == 0) {
+ // override default bootclasspath
+ setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspaths);
+ } else if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) != 0) {
+ // endorseddirs have been processed first
+ setLocation(StandardLocation.PLATFORM_CLASS_PATH,
+ concatFiles(iterable, bootclasspaths));
+ } else {
+ // extdirs have been processed first
+ setLocation(StandardLocation.PLATFORM_CLASS_PATH,
+ prependFiles(iterable, bootclasspaths));
+ }
}
+ this.flags |= EclipseFileManager.HAS_BOOTCLASSPATH;
+ return true;
+ } else {
+ throw new IllegalArgumentException();
}
- this.flags |= EclipseFileManager.HAS_BOOTCLASSPATH;
- return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-classpath".equals(current) || "-cp".equals(current)) {//$NON-NLS-1$//$NON-NLS-2$
- if (remaining.hasNext()) {
+ case "--system": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> classpaths = getPathsFrom(remaining.next());
+ if (classpaths != null) {
+ Iterable<? extends File> iterable = getLocation(StandardLocation.SYSTEM_MODULES);
+ if (iterable != null) {
+ setLocation(StandardLocation.SYSTEM_MODULES,
+ concatFiles(iterable, classpaths));
+ } else {
+ setLocation(StandardLocation.SYSTEM_MODULES, classpaths);
+ }
+ }
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "--upgrade-module-path": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> classpaths = getPathsFrom(remaining.next());
+ if (classpaths != null) {
+ Iterable<? extends File> iterable = getLocation(StandardLocation.UPGRADE_MODULE_PATH);
+ if (iterable != null) {
+ setLocation(StandardLocation.UPGRADE_MODULE_PATH,
+ concatFiles(iterable, classpaths));
+ } else {
+ setLocation(StandardLocation.UPGRADE_MODULE_PATH, classpaths);
+ }
+ }
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "-classpath": //$NON-NLS-1$
+ case "-cp": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> classpaths = getPathsFrom(remaining.next());
+ if (classpaths != null) {
+ Iterable<? extends File> iterable = getLocation(StandardLocation.CLASS_PATH);
+ if (iterable != null) {
+ setLocation(StandardLocation.CLASS_PATH,
+ concatFiles(iterable, classpaths));
+ } else {
+ setLocation(StandardLocation.CLASS_PATH, classpaths);
+ }
+ if ((this.flags & EclipseFileManager.HAS_PROCESSORPATH) == 0) {
+ setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
+ } else if ((this.flags & EclipseFileManager.HAS_PROC_MODULEPATH) == 0) {
+ if (this.isOnJvm9)
+ setLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, classpaths);
+ }
+ }
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "--module-path": //$NON-NLS-1$
+ case "-p": //$NON-NLS-1$
final Iterable<? extends File> classpaths = getPathsFrom(remaining.next());
if (classpaths != null) {
- Iterable<? extends File> iterable = getLocation(StandardLocation.CLASS_PATH);
+ Iterable<? extends File> iterable = getLocation(StandardLocation.MODULE_PATH);
if (iterable != null) {
- setLocation(StandardLocation.CLASS_PATH,
- concatFiles(iterable, classpaths));
+ setLocation(StandardLocation.MODULE_PATH, concatFiles(iterable, classpaths));
} else {
- setLocation(StandardLocation.CLASS_PATH, classpaths);
+ setLocation(StandardLocation.MODULE_PATH, classpaths);
}
if ((this.flags & EclipseFileManager.HAS_PROCESSORPATH) == 0) {
setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
+ } else if ((this.flags & EclipseFileManager.HAS_PROC_MODULEPATH) == 0) {
+ if (this.isOnJvm9)
+ setLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, classpaths);
}
}
return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-encoding".equals(current)) {//$NON-NLS-1$
- if (remaining.hasNext()) {
- this.charset = Charset.forName(remaining.next());
- return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-sourcepath".equals(current)) {//$NON-NLS-1$
- if (remaining.hasNext()) {
- final Iterable<? extends File> sourcepaths = getPathsFrom(remaining.next());
- if (sourcepaths != null) setLocation(StandardLocation.SOURCE_PATH, sourcepaths);
- return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-extdirs".equals(current)) {//$NON-NLS-1$
- if (remaining.hasNext()) {
- Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
- setLocation(StandardLocation.PLATFORM_CLASS_PATH,
- concatFiles(iterable, getExtdirsFrom(remaining.next())));
- this.flags |= EclipseFileManager.HAS_EXT_DIRS;
- return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-endorseddirs".equals(current)) {//$NON-NLS-1$
- if (remaining.hasNext()) {
- Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
- setLocation(StandardLocation.PLATFORM_CLASS_PATH,
- prependFiles(iterable, getEndorsedDirsFrom(remaining.next())));
- this.flags |= EclipseFileManager.HAS_ENDORSED_DIRS;
- return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-d".equals(current)) { //$NON-NLS-1$
- if (remaining.hasNext()) {
- final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
- if (outputDir != null) {
- setLocation(StandardLocation.CLASS_OUTPUT, outputDir);
+ case "-encoding": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ this.charset = Charset.forName(remaining.next());
+ return true;
+ } else {
+ throw new IllegalArgumentException();
}
- return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-s".equals(current)) { //$NON-NLS-1$
- if (remaining.hasNext()) {
- final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
- if (outputDir != null) {
- setLocation(StandardLocation.SOURCE_OUTPUT, outputDir);
+ case "-sourcepath": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> sourcepaths = getPathsFrom(remaining.next());
+ if (sourcepaths != null) setLocation(StandardLocation.SOURCE_PATH, sourcepaths);
+ return true;
+ } else {
+ throw new IllegalArgumentException();
}
- return true;
- } else {
- throw new IllegalArgumentException();
- }
- }
- if ("-processorpath".equals(current)) {//$NON-NLS-1$
- if (remaining.hasNext()) {
- final Iterable<? extends File> processorpaths = getPathsFrom(remaining.next());
- if (processorpaths != null) {
- setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, processorpaths);
+ case "--module-source-path": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> sourcepaths = getPathsFrom(remaining.next());
+ if (sourcepaths != null && this.isOnJvm9)
+ setLocation(StandardLocation.MODULE_SOURCE_PATH, sourcepaths);
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "-extdirs": //$NON-NLS-1$
+ if (this.isOnJvm9) {
+ throw new IllegalArgumentException();
+ }
+ if (remaining.hasNext()) {
+ Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
+ setLocation(StandardLocation.PLATFORM_CLASS_PATH,
+ concatFiles(iterable, getExtdirsFrom(remaining.next())));
+ this.flags |= EclipseFileManager.HAS_EXT_DIRS;
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "-endorseddirs": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
+ setLocation(StandardLocation.PLATFORM_CLASS_PATH,
+ prependFiles(iterable, getEndorsedDirsFrom(remaining.next())));
+ this.flags |= EclipseFileManager.HAS_ENDORSED_DIRS;
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "-d": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
+ if (outputDir != null) {
+ setLocation(StandardLocation.CLASS_OUTPUT, outputDir);
+ }
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "-s": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
+ if (outputDir != null) {
+ setLocation(StandardLocation.SOURCE_OUTPUT, outputDir);
+ }
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "-processorpath": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> processorpaths = getPathsFrom(remaining.next());
+ if (processorpaths != null) {
+ setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, processorpaths);
+ }
+ this.flags |= EclipseFileManager.HAS_PROCESSORPATH;
+ return true;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ case "--processor-module-path": //$NON-NLS-1$
+ if (remaining.hasNext()) {
+ final Iterable<? extends File> processorpaths = getPathsFrom(remaining.next());
+ if (processorpaths != null && this.isOnJvm9) {
+ setLocation(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH, processorpaths);
+ this.flags |= EclipseFileManager.HAS_PROC_MODULEPATH;
+ }
+ return true;
+ } else {
+ throw new IllegalArgumentException();
}
- this.flags |= EclipseFileManager.HAS_PROCESSORPATH;
- return true;
- } else {
- throw new IllegalArgumentException();
- }
}
} catch (IOException e) {
// ignore
@@ -706,7 +830,12 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public boolean hasLocation(Location location) {
- return this.locations != null && this.locations.containsKey(location.getName());
+ try {
+ return getLocationForModule(location, "") != null; //$NON-NLS-1$
+ } catch (IOException e) {
+ // nothing to do
+ }
+ return false;
}
/* (non-Javadoc)
@@ -714,6 +843,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
*/
@Override
public String inferBinaryName(Location location, JavaFileObject file) {
+ validateNonModuleLocation(location);
String name = file.getName();
JavaFileObject javaFileObject = null;
int index = name.lastIndexOf('.');
@@ -762,7 +892,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse)
throws IOException {
-
+ validateNonModuleLocation(location);
Iterable<? extends File> allFilesInLocations = getLocation(location);
if (allFilesInLocations == null) {
throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
@@ -771,7 +901,7 @@ public class EclipseFileManager implements StandardJavaFileManager {
ArrayList<JavaFileObject> collector = new ArrayList<>();
String normalizedPackageName = normalized(packageName);
for (File file : allFilesInLocations) {
- collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector);
+ collectAllMatchingFiles(location, file, normalizedPackageName, kinds, recurse, collector);
}
return collector;
}
@@ -802,26 +932,26 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
return list;
}
-
+ private boolean isRunningJvm9() {
+ return (SourceVersion.latest().compareTo(SourceVersion.RELEASE_8) > 0);
+ }
/* (non-Javadoc)
* @see javax.tools.StandardJavaFileManager#setLocation(javax.tools.JavaFileManager.Location, java.lang.Iterable)
*/
@Override
- public void setLocation(Location location, Iterable<? extends File> path) throws IOException {
- if (path != null) {
- if (location.isOutputLocation()) {
- // output location
- int count = 0;
- for (Iterator<? extends File> iterator = path.iterator(); iterator.hasNext(); ) {
- iterator.next();
- count++;
- }
- if (count != 1) {
- throw new IllegalArgumentException("output location can only have one path");//$NON-NLS-1$
- }
+ public void setLocation(Location location, Iterable<? extends File> files) throws IOException {
+ if (location.isOutputLocation()) {
+ // output location
+ int count = 0;
+ for (Iterator<? extends File> iterator = files.iterator(); iterator.hasNext(); ) {
+ iterator.next();
+ count++;
+ }
+ if (count != 1) {
+ throw new IllegalArgumentException("output location can only have one path");//$NON-NLS-1$
}
- this.locations.put(location.getName(), path);
}
+ this.locationHandler.setLocation(location, "", getPaths(files)); //$NON-NLS-1$
}
public void setLocale(Locale locale) {
@@ -1110,4 +1240,226 @@ public class EclipseFileManager implements StandardJavaFileManager {
}
return MessageFormat.format(message, (Object[]) arguments);
}
+ private Iterable<? extends File> getFiles(final Iterable<? extends Path> paths) {
+ if (paths == null)
+ return null;
+ return () -> new Iterator<File>() {
+ Iterator<? extends Path> original = paths.iterator();
+ @Override
+ public boolean hasNext() {
+ return this.original.hasNext();
+ }
+ @Override
+ public File next() {
+ return this.original.next().toFile();
+ }
+ };
+ }
+ private Iterable<? extends Path> getPaths(final Iterable<? extends File> files) {
+ if (files == null)
+ return null;
+ return () -> new Iterator<Path>() {
+ Iterator<? extends File> original = files.iterator();
+ @Override
+ public boolean hasNext() {
+ return this.original.hasNext();
+ }
+ @Override
+ public Path next() {
+ return this.original.next().toPath();
+ }
+ };
+ }
+
+ private void validateFileObject(FileObject file) {
+ // FIXME: fill-up
+ }
+ private void validateModuleLocation(Location location, String modName) {
+ Objects.requireNonNull(location);
+ if (modName == null) {
+ throw new IllegalArgumentException("module must not be null"); //$NON-NLS-1$
+ }
+ if (this.isOnJvm9) {
+ if (!location.isModuleOrientedLocation() && !location.isOutputLocation()) {
+ throw new IllegalArgumentException("location is module related :" + location.getName()); //$NON-NLS-1$
+ }
+ }
+ }
+ private void validateNonModuleLocation(Location location) {
+ Objects.requireNonNull(location);
+ if (this.isOnJvm9) {
+ if (location.isModuleOrientedLocation() && location.isOutputLocation()) {
+ throw new IllegalArgumentException("location is module related :" + location.getName()); //$NON-NLS-1$
+ }
+ }
+ }
+ private void validateOutputLocation(Location location) {
+ Objects.requireNonNull(location);
+ if (!location.isOutputLocation()) {
+ throw new IllegalArgumentException("location is not output location :" + location.getName()); //$NON-NLS-1$
+ }
+ }
+ @Override
+ public Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) {
+ return getJavaFileObjectsFromPaths(Arrays.asList(paths));
+ }
+
+ @Override
+ public Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(Iterable<? extends Path> paths) {
+ return getJavaFileObjectsFromFiles(getFiles(paths));
+ }
+
+ @Override
+ public Iterable<? extends Path> getLocationAsPaths(Location location) {
+ if (location instanceof LocationWrapper) {
+ return ((LocationWrapper) location).paths;
+ }
+ LocationWrapper loc = this.locationHandler.getLocation(location);
+ if (loc == null) {
+ return null;
+ }
+ return loc.getPaths();
+ }
+
+ @Override
+ public void setLocationFromPaths(Location location, Collection<? extends Path> paths) throws IOException {
+ setLocation(location, getFiles(paths));
+ if (location == StandardLocation.MODULE_PATH) {
+ // FIXME: same for module source path?
+ Map<String, String> options = new HashMap<>();
+ // FIXME: Find a way to get the options from the EclipseCompiler and pass it to the parser.
+ // FIXME: need to be the latest and not hardcoded value
+ options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9);
+ options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9);
+ options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9);
+ CompilerOptions compilerOptions = new CompilerOptions(options);
+ ProblemReporter problemReporter =
+ new ProblemReporter(
+ DefaultErrorHandlingPolicies.proceedWithAllProblems(),
+ compilerOptions,
+ new DefaultProblemFactory());
+ for (Path path : paths) {
+ List<Classpath> mp = ModuleFinder.findModules(path.toFile(), null,
+ new Parser(problemReporter, true), null, true);
+ for (Classpath cp : mp) {
+ Collection<String> moduleNames = cp.getModuleNames(null);
+ for (String string : moduleNames) {
+ Path p = Paths.get(cp.getPath());
+ setLocationForModule(StandardLocation.MODULE_PATH, string, Collections.singletonList(p));
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean contains(Location location, FileObject fo) throws IOException {
+ validateFileObject(fo);
+ Iterable<? extends File> files = getLocation(location);
+ if (files == null) {
+ throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
+ }
+ for (File file : files) {
+ if (file.isDirectory()) {
+ if (fo instanceof EclipseFileObject) {
+ Path filepath = ((EclipseFileObject) fo).f.toPath();
+ if (filepath.startsWith(Paths.get(file.toURI()).toAbsolutePath())) {
+ return true;
+ }
+ }
+ } else if (isArchive(file)) {
+ if (fo instanceof ArchiveFileObject) {
+ Archive archive = getArchive(file);
+ if (archive != Archive.UNKNOWN_ARCHIVE) {
+ if (archive.contains(((ArchiveFileObject) fo ).entryName)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Location getLocationForModule(Location location, String moduleName) throws IOException {
+ validateModuleLocation(location, moduleName);
+ return this.locationHandler.getLocation(location, moduleName);
+ }
+
+ @Override
+ public Location getLocationForModule(Location location, JavaFileObject fo) {
+ validateModuleLocation(location, ""); //$NON-NLS-1$
+ Path path = null;
+ if (fo instanceof ArchiveFileObject) {
+ path = ((ArchiveFileObject) fo).file.toPath();
+ return this.locationHandler.getLocation(location, path);
+ } else if (fo instanceof EclipseFileObject) {
+ path = ((EclipseFileObject) fo).f.toPath();
+ try {
+ path = path.toRealPath();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ LocationContainer container = this.locationHandler.getLocation(location);
+ while (path != null) {
+ Location loc = container.get(path);
+ if (loc != null)
+ return loc;
+ path = path.getParent();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
+ // FIXME: Need special handling in case of module class loaders.
+ return ServiceLoader.load(service, getClassLoader(location));
+ }
+
+ @Override
+ public String inferModuleName(Location location) throws IOException {
+ if (location instanceof ModuleLocationWrapper) {
+ ModuleLocationWrapper wrapper = (ModuleLocationWrapper) location;
+ return wrapper.modName;
+ }
+ return null;
+ }
+
+ @Override
+ public Iterable<Set<Location>> listLocationsForModules(Location location) {
+ validateModuleLocation(location, ""); //$NON-NLS-1$
+ return this.locationHandler.listLocationsForModules(location);
+ }
+
+ @Override
+ public Path asPath(FileObject file) {
+ validateFileObject(file);
+ EclipseFileObject eclFile = (EclipseFileObject) file;
+ if (eclFile.f != null) {
+ return eclFile.f.toPath();
+ }
+ return null;
+ }
+
+ @Override
+ public void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths) throws IOException {
+ validateModuleLocation(location, moduleName);
+ this.locationHandler.setLocation(location, moduleName, paths);
+ if (location == StandardLocation.MODULE_SOURCE_PATH) {
+ LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT, moduleName);
+ if (wrapper == null) {
+ wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT, ""); //$NON-NLS-1$
+ if (wrapper != null) {
+ Iterator<? extends Path> iterator = wrapper.paths.iterator();
+ if (iterator.hasNext()) {
+ // Per module output location is always a singleton list
+ Path path = iterator.next().resolve(moduleName);
+ this.locationHandler.setLocation(StandardLocation.CLASS_OUTPUT, moduleName, Collections.singletonList(path));
+ }
+ }
+ }
+ }
+ }
}
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileObject.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileObject.java
index e72f450caa..ac0c637e19 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileObject.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileObject.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 IBM Corporation and others.
+ * Copyright (c) 2006, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -37,7 +37,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
* Implementation of a Java file object that corresponds to a file on the file system
*/
public class EclipseFileObject extends SimpleJavaFileObject {
- private File f;
+ File f;
private Charset charset;
private boolean parentsExist; // parent directories exist
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java
index 56e5708b67..ccc41133ec 100644
--- a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/JrtFileSystem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016, 2017 IBM Corporation.
+ * Copyright (c) 2015, 2017 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -22,142 +22,128 @@ import java.io.Reader;
import java.io.Writer;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.nio.charset.Charset;
-import java.nio.file.DirectoryStream;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
-import java.nio.file.FileVisitor;
import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import java.util.zip.ZipException;
+import javax.tools.JavaFileObject;
+
+import org.eclipse.jdt.internal.compiler.apt.util.ModuleLocationHandler.ModuleLocationWrapper;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.env.IModule;
+import org.eclipse.jdt.internal.compiler.util.JRTUtil;
public class JrtFileSystem extends Archive {
private static URI JRT_URI = URI.create("jrt:/"); //$NON-NLS-1$
- private static final String BOOT_MODULE = "jrt-fs.jar"; //$NON-NLS-1$
-
- private static final String MODULES_SUBDIR = "/modules"; //$NON-NLS-1$
+ static final String BOOT_MODULE = "jrt-fs.jar"; //$NON-NLS-1$
- private static final String DEFAULT_PACKAGE = ""; //$NON-NLS-1$
-
- private Set<String> typesCache = null;
+ public HashMap<String, Path> modulePathMap;
+ Path modules;
+ private java.nio.file.FileSystem jrtfs;
public JrtFileSystem(File file) throws ZipException, IOException {
this.file = file;
initialize();
}
- private void initialize() throws IOException {
+ public void initialize() throws IOException {
// initialize packages
- this.packagesCache = new Hashtable<>();
- this.typesCache = new HashSet<>();
- if (!this.file.getName().equals(BOOT_MODULE)) return;
- java.nio.file.FileSystem fs = FileSystems.getFileSystem(JRT_URI);
- Iterable<java.nio.file.Path> roots = fs.getRootDirectories();
- for (java.nio.file.Path path : roots) {
- try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(path)) {
- for (final java.nio.file.Path subdir: stream) {
- if (subdir.toString().equals(MODULES_SUBDIR)) {
- Files.walkFileTree(subdir, new FileVisitor<java.nio.file.Path>() {
+ this.modulePathMap = new HashMap<>();
+ URL jrtPath = null;
+
+ if (this.file.exists()) {
+ jrtPath = Paths.get(this.file.toPath().toString(), "lib", JRTUtil.JRT_FS_JAR).toUri().toURL(); //$NON-NLS-1$
+ try (URLClassLoader loader = new URLClassLoader(new URL[] { jrtPath })) {
+ HashMap<String, ?> env = new HashMap<>();
+ this.jrtfs = FileSystems.newFileSystem(JRT_URI, env, loader);
+ this.modules = this.jrtfs.getPath("/modules"); //$NON-NLS-1$
+ }
+ } else {
+ return;
+ }
- @Override
- public FileVisitResult preVisitDirectory(java.nio.file.Path entry, BasicFileAttributes attrs)
- throws IOException {
- int count = entry.getNameCount();
- if (count < 2) return FileVisitResult.CONTINUE;
- return FileVisitResult.CONTINUE;
- }
+ org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(this.file,
+ new org.eclipse.jdt.internal.compiler.util.JRTUtil.JrtFileVisitor<Path>() {
- @Override
- public FileVisitResult visitFile(java.nio.file.Path entry, BasicFileAttributes attrs) throws IOException {
- int count = entry.getNameCount();
- if (entry == subdir || count < 3) return FileVisitResult.CONTINUE;
- if (count == 3) {
- cacheTypes(DEFAULT_PACKAGE, entry.getName(2).toString(), entry.getName(1).toString());
- } else {
- cacheTypes(entry.subpath(2, count - 1).toString(),
- entry.getName(count - 1).toString(), entry.getName(1).toString());
- }
- return FileVisitResult.CONTINUE;
- }
+ @Override
+ public FileVisitResult visitPackage(Path dir, Path mod, BasicFileAttributes attrs)
+ throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult visitFileFailed(java.nio.file.Path entry, IOException exc) throws IOException {
- return FileVisitResult.CONTINUE;
- }
+ @Override
+ public FileVisitResult visitFile(Path f, Path mod, BasicFileAttributes attrs)
+ throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult postVisitDirectory(java.nio.file.Path entry, IOException exc) throws IOException {
- return FileVisitResult.CONTINUE;
- }
- });
- }
- }
- } catch (Exception e) {
- throw new IOException(e.getMessage());
+ @Override
+ public FileVisitResult visitModule(Path mod) throws IOException {
+ JrtFileSystem.this.modulePathMap.put(mod.getFileName().toString(), mod);
+ return FileVisitResult.CONTINUE;
}
- }
- }
-
- public ArchiveFileObject getArchiveFileObject(String fileName, Charset charset) {
- return new JrtFileObject(this.file, fileName, null, charset);
+ }, JRTUtil.NOTIFY_MODULES);
}
-
+
+ public List<JrtFileObject> list(ModuleLocationWrapper location, String packageName,
+ Set<JavaFileObject.Kind> kinds, boolean recurse, Charset charset) {
+ String module = location.modName;
+ Path mPath = this.modules.resolve(module);
+ Path resolve = mPath.resolve(packageName);
+ java.util.List<Path> files = null;
+ try (Stream<Path> p = Files.list(resolve)) {
+ files = p.filter((path) -> {
+ if (Files.isDirectory(path))
+ return false;
+ else
+ return true;
+ }).collect(Collectors.toList());
+ } catch (IOException e) {
+ // ignore
+ }
+ List<JrtFileObject> result = new ArrayList<>();
+ for (Path p: files) {
+ result.add(new JrtFileObject(this.file, p, module, charset));
+ }
+ return result;
+ }
@Override
- public boolean contains(String entryName) {
- return this.typesCache.contains(entryName);
+ public ArchiveFileObject getArchiveFileObject(String fileName, String module, Charset charset) {
+ return new JrtFileObject(this.file, this.modules.resolve(module).resolve(fileName), module, charset);
}
- protected void cacheTypes(String packageName, String typeName, String module) {
- int length = packageName.length();
- if (length > 0 && packageName.charAt(packageName.length() - 1) != '/') {
- packageName = packageName + '/';
- }
- ArrayList<String[]> types = this.packagesCache.get(packageName);
- if (typeName == null) return;
- if (types == null) {
- types = new ArrayList<>();
- types.add(new String[]{typeName, module});
- this.packagesCache.put(packageName, types);
- } else {
- types.add(new String[]{typeName, module});
- }
- this.typesCache.add(packageName + typeName);
- }
@Override
- public List<String[]> getTypes(String packageName) {
- // package name is expected to ends with '/'
- if (this.packagesCache == null) {
- try {
- this.initialize();
- } catch(IOException e) {
- return Collections.<String[]>emptyList();
- }
- }
- return this.packagesCache.get(packageName);
+ public boolean contains(String entryName) {
+ // FIXME
+ return false;
}
-
+
@Override
public String toString() {
return "JRT: " + (this.file == null ? "UNKNOWN_ARCHIVE" : this.file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
}
class JrtFileObject extends ArchiveFileObject {
- IModule module = null; // FIXME(SHMOD): always null?? https://bugs.eclipse.org/517059
- private JrtFileObject(File file, String fileName, IModule module, Charset charset) {
- super(file, fileName, charset);
- this.module = module;
+ String module;
+ Path path;
+ private JrtFileObject(File file, Path path, String module, Charset charset) {
+ super(file, path.toString(), charset);
+ this.path = path;
}
@Override
@@ -169,7 +155,9 @@ public class JrtFileSystem extends Archive {
protected ClassFileReader getClassReader() {
ClassFileReader reader = null;
try {
- reader = ClassFileReader.readFromJrt(this.file, this.module, this.entryName);
+ byte[] content = JRTUtil.getClassfileContent(this.file, this.entryName, this.module);
+ if (content == null) return null;
+ return new ClassFileReader(content, this.entryName.toCharArray());
} catch (ClassFormatException e) {
e.printStackTrace();
} catch (IOException e) {
@@ -186,12 +174,12 @@ public class JrtFileSystem extends Archive {
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
try {
return Util.getCharContents(this, ignoreEncodingErrors,
- org.eclipse.jdt.internal.compiler.util.JRTUtil.getClassfileContent(this.file, this.entryName, new String(this.module.name())),
+ org.eclipse.jdt.internal.compiler.util.JRTUtil.getClassfileContent(this.file, this.entryName, this.module),
this.charset.name());
} catch (ClassFormatException e) {
e.printStackTrace();
+ return null;
}
- return null;
}
/* (non-Javadoc)
@@ -207,7 +195,7 @@ public class JrtFileSystem extends Archive {
*/
@Override
public String getName() {
- return this.entryName;
+ return this.path.toString();
}
/* (non-Javadoc)
@@ -215,7 +203,7 @@ public class JrtFileSystem extends Archive {
*/
@Override
public InputStream openInputStream() throws IOException {
- return org.eclipse.jdt.internal.compiler.util.JRTUtil.getContentFromJrt(this.file, this.entryName, null);
+ return Files.newInputStream(this.path);
}
/* (non-Javadoc)
diff --git a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/ModuleLocationHandler.java b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/ModuleLocationHandler.java
new file mode 100644
index 0000000000..eee15f6b1c
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/ModuleLocationHandler.java
@@ -0,0 +1,246 @@
+package org.eclipse.jdt.internal.compiler.apt.util;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.tools.JavaFileManager.Location;
+import javax.tools.StandardLocation;
+
+import org.eclipse.jdt.internal.compiler.batch.ClasspathJrt;
+
+public class ModuleLocationHandler {
+
+ Map<Location, LocationContainer> containers;
+
+ ModuleLocationHandler() {
+ this.containers = new HashMap<>();
+ }
+
+ public void newSystemLocation(Location loc, ClasspathJrt cp) throws IOException {
+ SystemLocationContainer systemLocationWrapper = new SystemLocationContainer(StandardLocation.SYSTEM_MODULES, cp);
+ this.containers.put(loc, systemLocationWrapper);
+ }
+ public void newSystemLocation(Location loc, JrtFileSystem jrt) throws IOException {
+ SystemLocationContainer systemLocationWrapper = new SystemLocationContainer(StandardLocation.SYSTEM_MODULES, jrt);
+ this.containers.put(loc, systemLocationWrapper);
+ }
+
+ public LocationWrapper getLocation(Location loc, String moduleName) {
+ if (loc instanceof LocationWrapper) {
+ loc = ((LocationWrapper) loc).loc;
+ }
+ LocationContainer forwarder = this.containers.get(loc);
+ if (forwarder != null) {
+ return forwarder.get(moduleName);
+ }
+ return null;
+ }
+
+ public Location getLocation(Location loc, Path path) {
+ LocationContainer forwarder = this.containers.get(loc);
+ if (forwarder != null) {
+ return forwarder.get(path);
+ }
+ return null;
+ }
+ public LocationContainer getLocation(Location location) {
+ return this.containers.get(location);
+ }
+ public void setLocation(Location location, Iterable<? extends Path> paths) {
+ LocationContainer container = this.containers.get(location);
+ if (container == null) {
+ container = new LocationContainer(location);
+ this.containers.put(location, container);
+ }
+ container.setPaths(paths);
+ }
+ public void setLocation(Location location, String moduleName, Iterable<? extends Path> paths) {
+ LocationWrapper wrapper = null;
+ LocationContainer container = this.containers.get(location);
+ if (container != null) {
+ wrapper = container.get(moduleName);
+ } else {
+ container = new LocationContainer(location);
+ this.containers.put(location, container);
+ }
+ if (wrapper == null) {
+ // module name can't be null
+ // TODO: Check unnamed modules can have their own module specific path - probably not
+ if (moduleName.equals("")) { //$NON-NLS-1$
+ wrapper = new LocationWrapper(location, location.isOutputLocation(), paths);
+ } else {
+ wrapper = new ModuleLocationWrapper(location, moduleName, location.isOutputLocation(), paths);
+ for (Path path : paths) {
+ container.put(path, wrapper);
+ }
+ }
+ } else {
+ wrapper.setPaths(paths);
+ }
+ container.put(moduleName, wrapper);
+ }
+ public Iterable<Set<Location>> listLocationsForModules(Location location) {
+ LocationContainer locationContainer = this.containers.get(location);
+ if (locationContainer == null) {
+ return Collections.emptyList();
+ }
+ Set<Location> set = new HashSet<>(locationContainer.locationNames.values());
+ List<Set<Location>> singletonList = Collections.singletonList(set);
+ return singletonList;
+ }
+
+ class LocationContainer extends LocationWrapper {
+
+ Map<String, LocationWrapper> locationNames;
+ Map<Path, LocationWrapper> locationPaths;
+ LocationContainer(Location loc) {
+ super();
+ this.loc = loc;
+ this.locationNames = new HashMap<>();
+ this.locationPaths = new HashMap<>();
+ }
+
+ LocationWrapper get(String moduleName) {
+ return this.locationNames.get(moduleName);
+ }
+
+ void put(String moduleName, LocationWrapper impl) {
+ this.locationNames.put(moduleName, impl);
+ this.paths = null;
+ }
+
+ void put(Path path, LocationWrapper impl) {
+ this.locationPaths.put(path, impl);
+ this.paths = null;
+ }
+
+ Location get(Path path) {
+ return this.locationPaths.get(path);
+ }
+
+ @Override
+ void setPaths(Iterable<? extends Path> paths) {
+ super.setPaths(paths);
+ this.clear();
+ }
+ @Override
+ Iterable<? extends Path> getPaths() {
+ if (this.paths != null)
+ return this.paths;
+ return this.locationPaths.keySet();
+ }
+
+ public void clear() {
+ this.locationNames.clear();
+ this.locationPaths.clear();
+ }
+ }
+
+ class SystemLocationContainer extends LocationContainer {
+
+ public SystemLocationContainer(Location loc, JrtFileSystem jrt) throws IOException {
+ super(loc);
+ jrt.initialize();
+ HashMap<String, Path> modulePathMap = jrt.modulePathMap;
+ Set<String> keySet = modulePathMap.keySet();
+ for (String mod : keySet) {
+ Path path = jrt.file.toPath();
+ ModuleLocationWrapper wrapper = new ModuleLocationWrapper(loc, mod, false,
+ Collections.singletonList(path));
+ this.locationNames.put(mod, wrapper);
+ this.locationPaths.put(path, wrapper);
+ }
+ }
+ public SystemLocationContainer(Location loc, ClasspathJrt cp) throws IOException {
+ this(loc, new JrtFileSystem(cp.file));
+ }
+ }
+
+ class LocationWrapper implements Location {
+
+ Location loc;
+ boolean output;
+ List<? extends Path> paths;
+ LocationWrapper() {
+ }
+ public LocationWrapper(Location loc, boolean output, Iterable<? extends Path> paths) {
+ this.loc = loc;
+ this.output = output;
+ setPaths(paths);
+ }
+
+ @Override
+ public String getName() {
+ return this.loc.getName();
+ }
+
+ @Override
+ public boolean isOutputLocation() {
+ return this.output;
+ }
+
+ Iterable<? extends Path> getPaths() {
+ return this.paths;
+ }
+
+ void setPaths(Iterable<? extends Path> paths) {
+ if (paths == null) {
+ this.paths = null;
+ } else {
+ List<Path> newPaths = new ArrayList<>();
+ for (Path file : paths) {
+ newPaths.add(file);
+ }
+ this.paths = Collections.unmodifiableList(newPaths);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return this.loc.toString() + "[]"; //$NON-NLS-1$
+ }
+ }
+
+ class ModuleLocationWrapper extends LocationWrapper {
+ String modName;
+
+ public ModuleLocationWrapper(Location loc, String mod, boolean output, Iterable<? extends Path> paths) {
+ super(loc, output, paths);
+ this.modName = mod;
+ }
+
+ @Override
+ public String getName() {
+ return this.loc.getName() + "[" + this.modName + "]"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public boolean isOutputLocation() {
+ return this.output;
+ }
+
+ @Override
+ Iterable<? extends Path> getPaths() {
+ return this.paths;
+ }
+
+ @Override
+ public String toString() {
+ return this.loc.toString() + "[" + this.modName + "]"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+ }
+ public void close() {
+ Collection<LocationContainer> values = this.containers.values();
+ for (LocationContainer locationContainer : values) {
+ locationContainer.clear();
+ }
+ }
+}

Back to the top