Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2019-02-09 11:02:37 +0000
committerJay Arthanareeswaran2019-02-09 12:52:04 +0000
commiteb7091dd7a1af3c2178982ad67c4c20f57903bf6 (patch)
tree8536870c373d51379efdabab027cc72e812dc3f7
parent9f5da34738535d49d74b7d9c9bdb9335c49ffa24 (diff)
downloadeclipse.jdt.core-eb7091dd7a1af3c2178982ad67c4c20f57903bf6.tar.gz
eclipse.jdt.core-eb7091dd7a1af3c2178982ad67c4c20f57903bf6.tar.xz
eclipse.jdt.core-eb7091dd7a1af3c2178982ad67c4c20f57903bf6.zip
Bug 540922: [12] ct.sym file has been restructured again for older
releases Extract the changes related to JDK 12 to a new class and keep the older ClaspathJep247 untouched. Change-Id: I0e02d0bc513209977abf70e2c4f5546bc2868326 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java2
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java213
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java307
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java15
4 files changed, 396 insertions, 141 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
index c154ac8281..b86cbdc216 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
@@ -4352,7 +4352,7 @@ public void testBug521362_emptyFile() {
true);
}
public void testReleaseOption22() {
- if (!isJRE11Plus) return;
+ if (isJRE11Plus || isJRE12Plus) return;
runConformTest(
new String[] {
"p/X.java",
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java
index e4f98782ff..408f946fcb 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java
@@ -1,10 +1,14 @@
/*******************************************************************************
- * Copyright (c) 2018 IBM Corporation.
+ * Copyright (c) 2018, 2019 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -22,14 +26,11 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
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 java.util.function.Function;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
@@ -52,9 +53,8 @@ public class ClasspathJep247 extends ClasspathJrt {
protected String[] subReleases = null;
protected Path releasePath = null;
protected Set<String> packageCache;
- Map<String, IModule> modules;
- File jdkHome;
- String modulePath = null;
+ protected File jdkHome;
+ protected String modulePath = null;
public ClasspathJep247(File jdkHome, String release, AccessRuleSet accessRuleSet) {
super(jdkHome, false, accessRuleSet, null);
@@ -82,26 +82,12 @@ public class ClasspathJep247 extends ClasspathJrt {
byte[] content = null;
qualifiedBinaryFileName = qualifiedBinaryFileName.replace(".class", ".sig"); //$NON-NLS-1$ //$NON-NLS-2$
if (this.subReleases != null && this.subReleases.length > 0) {
- done: for (String rel : this.subReleases) {
- if (moduleName == null) {
- Path p = this.fs.getPath(rel);
- try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(p)) {
- for (final java.nio.file.Path subdir: stream) {
- Path f = this.fs.getPath(rel, subdir.getFileName().toString(), qualifiedBinaryFileName);
- if (Files.exists(f)) {
- content = JRTUtil.safeReadBytes(f);
- if (content != null)
- break done;
- }
- }
- }
- } else {
- Path p = this.fs.getPath(rel, moduleName, qualifiedBinaryFileName);
- if (Files.exists(p)) {
- content = JRTUtil.safeReadBytes(p);
- if (content != null)
- break;
- }
+ for (String rel : this.subReleases) {
+ Path p = this.fs.getPath(rel, qualifiedBinaryFileName);
+ if (Files.exists(p)) {
+ content = JRTUtil.safeReadBytes(p);
+ if (content != null)
+ break;
}
}
} else {
@@ -144,17 +130,6 @@ public class ClasspathJep247 extends ClasspathJrt {
if (!Files.exists(this.fs.getPath(this.releaseInHex))) {
throw new IllegalArgumentException("release " + this.compliance + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$
}
- List<String> sub = new ArrayList<>();
- try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(this.releasePath)) {
- for (final java.nio.file.Path subdir: stream) {
- String rel = subdir.getFileName().toString();
- if (rel.contains(this.releaseInHex))
- sub.add(rel);
- }
- this.subReleases = sub.toArray(new String[sub.size()]);
- } catch (IOException e) {
- //e.printStackTrace();
- }
super.initialize();
}
@Override
@@ -164,89 +139,52 @@ public class ClasspathJep247 extends ClasspathJrt {
super.loadModules();
return;
}
- final Path modPath = this.fs.getPath(this.releaseInHex);
-// if (!Files.exists(modPath)) {
-// throw new IllegalArgumentException("release " + this.compliance + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$
-// }
+ final Path modPath = this.fs.getPath(this.releaseInHex + "-modules"); //$NON-NLS-1$
+ if (!Files.exists(modPath)) {
+ throw new IllegalArgumentException("release " + this.compliance + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$
+ }
this.modulePath = this.file.getPath() + "|" + modPath.toString(); //$NON-NLS-1$
- this.modules = ModulesCache.get(this.modulePath);
- if (this.modules == null) {
- try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(this.releasePath)) {
+ Map<String, IModule> cache = ModulesCache.get(this.modulePath);
+ if (cache == null) {
+ try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(modPath)) {
for (final java.nio.file.Path subdir: stream) {
- String rel = subdir.getFileName().toString();
- if (!rel.contains(this.releaseInHex)) {
- continue;
- }
- Files.walkFileTree(subdir, Collections.EMPTY_SET, 2, new FileVisitor<java.nio.file.Path>() {
+ Files.walkFileTree(subdir, new FileVisitor<java.nio.file.Path>() {
- @Override
- public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs)
- throws IOException {
- return FileVisitResult.CONTINUE;
- }
+ @Override
+ public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs)
+ throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException {
- if (attrs.isDirectory() || f.getNameCount() < 3)
+ @Override
+ public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException {
+ byte[] content = null;
+ if (Files.exists(f)) {
+ content = JRTUtil.safeReadBytes(f);
+ if (content == null)
+ return FileVisitResult.CONTINUE;
+ ClasspathJep247.this.acceptModule(content);
+ ClasspathJep247.this.moduleNamesCache.add(f.getFileName().toString());
+ }
return FileVisitResult.CONTINUE;
- byte[] content = null;
- if (Files.exists(f)) {
- content = JRTUtil.safeReadBytes(f);
- if (content == null)
- return FileVisitResult.CONTINUE;
- Path m = f.subpath(1, f.getNameCount() - 1);
- ClasspathJep247.this.acceptModule(m.getFileName().toString(), content);
- ClasspathJep247.this.moduleNamesCache.add(m.getFileName().toString());
}
- return FileVisitResult.SKIP_SIBLINGS;
- }
- @Override
- public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException {
- return FileVisitResult.CONTINUE;
- }
+ @Override
+ public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
- return FileVisitResult.CONTINUE;
- }
- });
+ @Override
+ public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+ });
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
- this.moduleNamesCache.addAll(this.modules.keySet());
- }
- }
- @Override
- public Collection<String> getModuleNames(Collection<String> limitModule, Function<String, IModule> getModule) {
- return selectModules(this.moduleNamesCache, limitModule, getModule);
- }
- @Override
- public IModule getModule(char[] moduleName) {
- if (this.modules != null) {
- return this.modules.get(String.valueOf(moduleName));
- }
- return null;
- }
- void acceptModule(String name, byte[] content) {
- if (content == null)
- return;
-
- if (this.modules != null) {
- if (this.modules.containsKey(name))
- return;
- }
-
- ClassFileReader reader = null;
- try {
- reader = new ClassFileReader(content, IModule.MODULE_INFO_CLASS.toCharArray());
- } catch (ClassFormatException e) {
- e.printStackTrace();
- }
- if (reader != null) {
- acceptModule(reader);
+ this.moduleNamesCache.addAll(cache.keySet());
}
}
@Override
@@ -259,10 +197,11 @@ public class ClasspathJep247 extends ClasspathJrt {
if (reader != null) {
IModule moduleDecl = reader.getModuleDeclaration();
if (moduleDecl != null) {
- if (this.modules == null) {
- ModulesCache.put(this.modulePath, this.modules = new HashMap<String,IModule>());
+ Map<String, IModule> cache = ModulesCache.get(this.modulePath);
+ if (cache == null) {
+ ModulesCache.put(this.modulePath, cache = new HashMap<String,IModule>());
}
- this.modules.put(String.valueOf(moduleDecl.name()), moduleDecl);
+ cache.put(String.valueOf(moduleDecl.name()), moduleDecl);
}
}
}
@@ -279,46 +218,46 @@ public class ClasspathJep247 extends ClasspathJrt {
this.packageCache = new HashSet<>(41);
this.packageCache.add(Util.EMPTY_STRING);
+ List<String> sub = new ArrayList<>();
try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(this.releasePath)) {
for (final java.nio.file.Path subdir: stream) {
String rel = subdir.getFileName().toString();
- if (!rel.contains(this.releaseInHex)) {
+ if (rel.contains(this.releaseInHex)) {
+ sub.add(rel);
+ } else {
continue;
}
- try (DirectoryStream<java.nio.file.Path> stream2 = Files.newDirectoryStream(subdir)) {
- for (final java.nio.file.Path subdir2: stream2) {
- Files.walkFileTree(subdir2, new FileVisitor<java.nio.file.Path>() {
- @Override
- public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) throws IOException {
- if (dir.getNameCount() <= 2)
- return FileVisitResult.CONTINUE;
- Path relative = dir.subpath(2, dir.getNameCount());
- addToPackageCache(relative.toString(), false);
- return FileVisitResult.CONTINUE;
- }
+ Files.walkFileTree(subdir, new FileVisitor<java.nio.file.Path>() {
+ @Override
+ public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) throws IOException {
+ if (dir.getNameCount() <= 1)
+ return FileVisitResult.CONTINUE;
+ Path relative = dir.subpath(1, dir.getNameCount());
+ addToPackageCache(relative.toString(), false);
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException {
- return FileVisitResult.CONTINUE;
- }
+ @Override
+ public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException {
- return FileVisitResult.CONTINUE;
- }
+ @Override
+ public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
- @Override
- public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
- return FileVisitResult.CONTINUE;
- }
- });
+ @Override
+ public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
}
- }
+ });
}
} catch (IOException e) {
e.printStackTrace();
// Rethrow
}
+ this.subReleases = sub.toArray(new String[sub.size()]);
return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName));
}
@Override
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java
new file mode 100644
index 0000000000..4ae242da81
--- /dev/null
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java
@@ -0,0 +1,307 @@
+/*******************************************************************************
+ * Copyright (c) 2019 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v20.html
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.compiler.batch;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.DirectoryStream;
+import java.nio.file.FileSystemNotFoundException;
+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.attribute.BasicFileAttributes;
+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.function.Function;
+
+import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
+import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
+import org.eclipse.jdt.internal.compiler.env.IModule;
+import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
+import org.eclipse.jdt.internal.compiler.util.JRTUtil;
+import org.eclipse.jdt.internal.compiler.util.Util;
+
+public class ClasspathJep247Jdk12 extends ClasspathJep247 {
+
+ Map<String, IModule> modules;
+
+ public ClasspathJep247Jdk12(File jdkHome, String release, AccessRuleSet accessRuleSet) {
+ super(jdkHome, release, accessRuleSet);
+ }
+ @Override
+ public List<Classpath> fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
+ return null;
+ }
+ @Override
+ public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) {
+ return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false);
+ }
+ @Override
+ public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) {
+ if (!isPackage(qualifiedPackageName, moduleName))
+ return null; // most common case
+
+ try {
+ ClassFileReader reader = null;
+ byte[] content = null;
+ qualifiedBinaryFileName = qualifiedBinaryFileName.replace(".class", ".sig"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (this.subReleases != null && this.subReleases.length > 0) {
+ done: for (String rel : this.subReleases) {
+ if (moduleName == null) {
+ Path p = this.fs.getPath(rel);
+ try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(p)) {
+ for (final java.nio.file.Path subdir: stream) {
+ Path f = this.fs.getPath(rel, subdir.getFileName().toString(), qualifiedBinaryFileName);
+ if (Files.exists(f)) {
+ content = JRTUtil.safeReadBytes(f);
+ if (content != null)
+ break done;
+ }
+ }
+ }
+ } else {
+ Path p = this.fs.getPath(rel, moduleName, qualifiedBinaryFileName);
+ if (Files.exists(p)) {
+ content = JRTUtil.safeReadBytes(p);
+ if (content != null)
+ break;
+ }
+ }
+ }
+ } else {
+ content = JRTUtil.safeReadBytes(this.fs.getPath(this.releaseInHex, qualifiedBinaryFileName));
+ }
+ if (content != null) {
+ reader = new ClassFileReader(content, qualifiedBinaryFileName.toCharArray());
+ return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), null);
+ }
+ } catch(ClassFormatException e) {
+ // Continue
+ } catch (IOException e) {
+ // continue
+ }
+ return null;
+ }
+
+ @Override
+ public void initialize() throws IOException {
+ if (this.compliance == null) {
+ return;
+ }
+ if (this.fs != null) {
+ super.initialize();
+ return;
+ }
+ this.releaseInHex = Integer.toHexString(Integer.parseInt(this.compliance)).toUpperCase();
+ Path filePath = this.jdkHome.toPath().resolve("lib").resolve("ct.sym"); //$NON-NLS-1$ //$NON-NLS-2$
+ URI t = filePath.toUri();
+ if (!Files.exists(filePath)) {
+ return;
+ }
+ URI uri = URI.create("jar:file:" + t.getRawPath()); //$NON-NLS-1$
+ try {
+ this.fs = FileSystems.getFileSystem(uri);
+ } catch(FileSystemNotFoundException fne) {
+ // Ignore and move on
+ }
+ if (this.fs == null) {
+ HashMap<String, ?> env = new HashMap<>();
+ this.fs = FileSystems.newFileSystem(uri, env);
+ }
+ this.releasePath = this.fs.getPath("/"); //$NON-NLS-1$
+ if (!Files.exists(this.fs.getPath(this.releaseInHex))) {
+ throw new IllegalArgumentException("release " + this.compliance + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ List<String> sub = new ArrayList<>();
+ try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(this.releasePath)) {
+ for (final java.nio.file.Path subdir: stream) {
+ String rel = subdir.getFileName().toString();
+ if (rel.contains(this.releaseInHex))
+ sub.add(rel);
+ }
+ this.subReleases = sub.toArray(new String[sub.size()]);
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+ super.initialize();
+ }
+ @Override
+ public void loadModules() {
+ // Modules below level 8 are not dealt with here. Leave it to ClasspathJrt
+ if (this.jdklevel <= ClassFileConstants.JDK1_8) {
+ super.loadModules();
+ return;
+ }
+ final Path modPath = this.fs.getPath(this.releaseInHex);
+ this.modulePath = this.file.getPath() + "|" + modPath.toString(); //$NON-NLS-1$
+ this.modules = ModulesCache.get(this.modulePath);
+ if (this.modules == null) {
+ try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(this.releasePath)) {
+ for (final java.nio.file.Path subdir: stream) {
+ String rel = subdir.getFileName().toString();
+ if (!rel.contains(this.releaseInHex)) {
+ continue;
+ }
+ Files.walkFileTree(subdir, Collections.EMPTY_SET, 2, new FileVisitor<java.nio.file.Path>() {
+
+ @Override
+ public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs)
+ throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException {
+ if (attrs.isDirectory() || f.getNameCount() < 3)
+ return FileVisitResult.CONTINUE;
+ byte[] content = null;
+ if (Files.exists(f)) {
+ content = JRTUtil.safeReadBytes(f);
+ if (content == null)
+ return FileVisitResult.CONTINUE;
+ Path m = f.subpath(1, f.getNameCount() - 1);
+ ClasspathJep247Jdk12.this.acceptModule(m.getFileName().toString(), content);
+ ClasspathJep247Jdk12.this.moduleNamesCache.add(m.getFileName().toString());
+ }
+ return FileVisitResult.SKIP_SIBLINGS;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ } else {
+ this.moduleNamesCache.addAll(this.modules.keySet());
+ }
+ }
+ @Override
+ public Collection<String> getModuleNames(Collection<String> limitModule, Function<String, IModule> getModule) {
+ return selectModules(this.moduleNamesCache, limitModule, getModule);
+ }
+ @Override
+ public IModule getModule(char[] moduleName) {
+ if (this.modules != null) {
+ return this.modules.get(String.valueOf(moduleName));
+ }
+ return null;
+ }
+ void acceptModule(String name, byte[] content) {
+ if (content == null)
+ return;
+
+ if (this.modules != null) {
+ if (this.modules.containsKey(name))
+ return;
+ }
+
+ ClassFileReader reader = null;
+ try {
+ reader = new ClassFileReader(content, IModule.MODULE_INFO_CLASS.toCharArray());
+ } catch (ClassFormatException e) {
+ e.printStackTrace();
+ }
+ if (reader != null) {
+ acceptModule(reader);
+ }
+ }
+ @Override
+ void acceptModule(ClassFileReader reader) {
+ // Modules below level 8 are not dealt with here. Leave it to ClasspathJrt
+ if (this.jdklevel <= ClassFileConstants.JDK1_8) {
+ super.acceptModule(reader);
+ return;
+ }
+ if (reader != null) {
+ IModule moduleDecl = reader.getModuleDeclaration();
+ if (moduleDecl != null) {
+ if (this.modules == null) {
+ ModulesCache.put(this.modulePath, this.modules = new HashMap<String,IModule>());
+ }
+ this.modules.put(String.valueOf(moduleDecl.name()), moduleDecl);
+ }
+ }
+ }
+ @Override
+ public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) {
+ // Ignore moduleName as this has nothing to do with modules (as of now)
+ if (this.packageCache != null)
+ return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName));
+
+ this.packageCache = new HashSet<>(41);
+ this.packageCache.add(Util.EMPTY_STRING);
+ try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(this.releasePath)) {
+ for (final java.nio.file.Path subdir: stream) {
+ String rel = subdir.getFileName().toString();
+ if (!rel.contains(this.releaseInHex)) {
+ continue;
+ }
+ try (DirectoryStream<java.nio.file.Path> stream2 = Files.newDirectoryStream(subdir)) {
+ for (final java.nio.file.Path subdir2: stream2) {
+ Files.walkFileTree(subdir2, new FileVisitor<java.nio.file.Path>() {
+ @Override
+ public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) throws IOException {
+ if (dir.getNameCount() <= 2)
+ return FileVisitResult.CONTINUE;
+ Path relative = dir.subpath(2, dir.getNameCount());
+ addToPackageCache(relative.toString(), false);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ // Rethrow
+ }
+ return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName));
+ }
+}
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
index 4cb97d919c..2e82e50c08 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contribution for
@@ -164,11 +168,14 @@ public class FileSystem implements IModuleAwareNameEnvironment, SuffixConstants
Set<String> knownFileNames;
protected boolean annotationsFromClasspath; // should annotation files be read from the classpath (vs. explicit separate path)?
private static HashMap<File, Classpath> JRT_CLASSPATH_CACHE = null;
-
protected Map<String,Classpath> moduleLocations = new HashMap<>();
/** Tasks resulting from --add-reads or --add-exports command line options. */
Map<String,UpdatesByKind> moduleUpdates = new HashMap<>();
+ static final boolean isJRE12Plus;
+ static {
+ isJRE12Plus = CompilerOptions.VERSION_12.equals(System.getProperty("java.specification.version")); //$NON-NLS-1$
+ }
/*
classPathNames is a collection is Strings representing the full path of each class path
@@ -258,7 +265,9 @@ public static Classpath getJrtClasspath(String jdkHome, String encoding, AccessR
return new ClasspathJrt(new File(convertPathSeparators(jdkHome)), true, accessRuleSet, null);
}
public static Classpath getOlderSystemRelease(String jdkHome, String release, AccessRuleSet accessRuleSet) {
- return new ClasspathJep247(new File(convertPathSeparators(jdkHome)), release, accessRuleSet);
+ return isJRE12Plus ?
+ new ClasspathJep247Jdk12(new File(convertPathSeparators(jdkHome)), release, accessRuleSet) :
+ new ClasspathJep247(new File(convertPathSeparators(jdkHome)), release, accessRuleSet);
}
public static Classpath getClasspath(String classpathName, String encoding,
boolean isSourceOnly, AccessRuleSet accessRuleSet,

Back to the top