diff options
Diffstat (limited to 'org.eclipse.jdt.core/batch/org/eclipse/jdt/internal')
6 files changed, 289 insertions, 52 deletions
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 37bb0a0564..6e1eb3af8e 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 @@ -15,32 +15,37 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.jdt.core.compiler.CharOperation; 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.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.util.JRTUtil; import org.eclipse.jdt.internal.compiler.util.Util; -public class ClasspathJep247 extends ClasspathLocation { +public class ClasspathJep247 extends ClasspathJrt { private java.nio.file.FileSystem fs = null; private String compliance = null; private String releaseInHex = null; private String[] subReleases = null; private Path releasePath = null; - private File file = null; private Set<String> packageCache; + File jdkHome; + String modulePath = null; public ClasspathJep247(File jdkHome, String release, AccessRuleSet accessRuleSet) { - super(accessRuleSet, null); + super(jdkHome, false, accessRuleSet, null); this.compliance = release; - this.file = jdkHome; + this.jdkHome = jdkHome; + this.file = new File(new File(jdkHome, "lib"), "jrt-fs.jar"); //$NON-NLS-1$ //$NON-NLS-2$ } @Override public List<Classpath> fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) { @@ -83,15 +88,6 @@ public class ClasspathJep247 extends ClasspathLocation { } return null; } - @Override - public boolean hasAnnotationFileFor(String qualifiedTypeName) { - return false; - } - @Override - public char[][][] findTypeNames(final String qualifiedPackageName, String moduleName) { - // TODO: Revisit - return null; - } @Override public void initialize() throws IOException { @@ -99,7 +95,7 @@ public class ClasspathJep247 extends ClasspathLocation { return; } this.releaseInHex = Integer.toHexString(Integer.parseInt(this.compliance)); - Path filePath = this.file.toPath().resolve("lib").resolve("ct.sym"); //$NON-NLS-1$ //$NON-NLS-2$ + 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; @@ -118,9 +114,73 @@ public class ClasspathJep247 extends ClasspathLocation { 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$ } + super.initialize(); + } + @Override + public void loadModules() { + if (CompilerOptions.releaseToJDKLevel(this.compliance) <= ClassFileConstants.JDK1_8) { + return; + } + 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$ + 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) { + 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 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; + } + + @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(cache.keySet()); + } } + @Override void acceptModule(ClassFileReader reader) { - // Nothing to do + if (reader != null) { + IModule moduleDecl = reader.getModuleDeclaration(); + if (moduleDecl != null) { + Map<String, IModule> cache = ModulesCache.get(this.modulePath); + if (cache == null) { + ModulesCache.put(this.modulePath, cache = new HashMap<String,IModule>()); + } + cache.put(String.valueOf(moduleDecl.name()), moduleDecl); + } + } } protected void addToPackageCache(String packageName, boolean endsWithSep) { if (this.packageCache.contains(packageName)) @@ -178,11 +238,6 @@ public class ClasspathJep247 extends ClasspathLocation { return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); } @Override - public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { - // TOOD: Revisit - return false; - } - @Override public void reset() { try { super.reset(); @@ -224,8 +279,4 @@ public class ClasspathJep247 extends ClasspathLocation { return BINARY; } - @Override - public IModule getModule() { - return null; - } } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java index d7de9a9b43..64e28bb6e6 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java @@ -45,7 +45,7 @@ public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry public File file; protected ZipFile annotationZipFile; protected boolean closeZipFileAtEnd; - private static HashMap<String, Map<String,IModule>> ModulesCache = new HashMap<>(); + protected static HashMap<String, Map<String,IModule>> ModulesCache = new HashMap<>(); public final Set<String> moduleNamesCache; //private Set<String> packageCache; protected List<String> annotationPaths; diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathMultiReleaseJar.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathMultiReleaseJar.java new file mode 100644 index 0000000000..41756884ec --- /dev/null +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathMultiReleaseJar.java @@ -0,0 +1,172 @@ +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.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.zip.ZipEntry; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationDecorator; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IBinaryType; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class ClasspathMultiReleaseJar extends ClasspathJar { + private java.nio.file.FileSystem fs = null; + Path releasePath = null; + String compliance = null; + + public ClasspathMultiReleaseJar(File file, boolean closeZipFileAtEnd, + AccessRuleSet accessRuleSet, String destinationPath, String compliance) { + super(file, closeZipFileAtEnd, accessRuleSet, destinationPath); + this.compliance = compliance; + } + @Override + public void initialize() throws IOException { + super.initialize(); + URI t = this.file.toURI(); + if (this.file.exists()) { + 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<>(); + try { + this.fs = FileSystems.newFileSystem(uri, env); + } catch (IOException e) { + // return + } + } + this.releasePath = this.fs.getPath("/", "META-INF", "versions", this.compliance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (!Files.exists(this.releasePath)) { + this.releasePath = null; + } + } + } + @SuppressWarnings("rawtypes") + @Override + public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { + if (this.releasePath == null) { + return super.getModulesDeclaringPackage(qualifiedPackageName, moduleName); + } + if (this.packageCache != null) + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + + this.packageCache = new HashSet<>(41); + this.packageCache.add(Util.EMPTY_STRING); + + for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + String fileName = ((ZipEntry) e.nextElement()).getName(); + addToPackageCache(fileName, false); + } + try { + if (this.releasePath != null && Files.exists(this.releasePath)) { + // go through the packages + try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(this.releasePath)) { + for (final java.nio.file.Path subdir: stream) { + 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 visitFile(java.nio.file.Path f, BasicFileAttributes attrs) + throws IOException { + Path p = ClasspathMultiReleaseJar.this.releasePath.relativize(f); + addToPackageCache(p.toString(), false); + 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 (Exception e) { + e.printStackTrace(); + // move on; + } + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + } + @Override + public NameEnvironmentAnswer findClass(char[] binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) return null; // most common case + if (this.releasePath != null) { + try { + Path p = this.releasePath.resolve(qualifiedBinaryFileName); + byte[] content = Files.readAllBytes(p); + IBinaryType reader = null; + if (content != null) { + reader = new ClassFileReader(content, qualifiedBinaryFileName.toCharArray()); + } + if (reader != null) { + char[] modName = this.module == null ? null : this.module.name(); + if (reader instanceof ClassFileReader) { + ClassFileReader classReader = (ClassFileReader) reader; + if (classReader.moduleName == null) + classReader.moduleName = modName; + else + modName = classReader.moduleName; + } + String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); + searchPaths: + if (this.annotationPaths != null) { + String qualifiedClassName = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length()-SuffixConstants.EXTENSION_CLASS.length()-1); + for (String annotationPath : this.annotationPaths) { + try { + if (this.annotationZipFile == null) { + this.annotationZipFile = ExternalAnnotationDecorator.getAnnotationZipFile(annotationPath, null); + } + reader = ExternalAnnotationDecorator.create(reader, annotationPath, qualifiedClassName, this.annotationZipFile); + + if (reader.getExternalAnnotationStatus() == ExternalAnnotationStatus.TYPE_IS_ANNOTATED) { + break searchPaths; + } + } catch (IOException e) { + // don't let error on annotations fail class reading + } + } + // location is configured for external annotations, but no .eea found, decorate in order to answer NO_EEA_FILE: + reader = new ExternalAnnotationDecorator(reader, null); + } + if (this.accessRuleSet == null) + return new NameEnvironmentAnswer(reader, null, modName); + return new NameEnvironmentAnswer(reader, + this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()), + modName); + } + } catch (IOException | ClassFormatException e) { + // treat as if class file is missing + } + } + return super.findClass(binaryFileName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, asBinaryOnly); + } +} 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 ae2c63a02a..492067b88c 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 @@ -179,7 +179,7 @@ protected FileSystem(String[] classpathNames, String[] initialFileNames, String this.classpaths = new Classpath[classpathSize]; int counter = 0; for (int i = 0; i < classpathSize; i++) { - Classpath classpath = getClasspath(classpathNames[i], encoding, null, null); + Classpath classpath = getClasspath(classpathNames[i], encoding, null, null, null); try { classpath.initialize(); for (String moduleName : classpath.getModuleNames(limitModules)) @@ -244,10 +244,10 @@ protected FileSystem(Classpath[] paths, String[] initialFileNames, boolean annot this(paths, initialFileNames, annotationsFromClasspath, null); } public static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet) { - return getClasspath(classpathName, encoding, false, accessRuleSet, null, null); + return getClasspath(classpathName, encoding, false, accessRuleSet, null, null, null); } -public static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet, Map<String, String> options) { - return getClasspath(classpathName, encoding, false, accessRuleSet, null, options); +public static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet, Map<String, String> options, String release) { + return getClasspath(classpathName, encoding, false, accessRuleSet, null, options, release); } public static Classpath getJrtClasspath(String jdkHome, String encoding, AccessRuleSet accessRuleSet, Map<String, String> options) { return new ClasspathJrt(new File(convertPathSeparators(jdkHome)), true, accessRuleSet, null); @@ -257,7 +257,7 @@ public static Classpath getOlderSystemRelease(String jdkHome, String release, Ac } public static Classpath getClasspath(String classpathName, String encoding, boolean isSourceOnly, AccessRuleSet accessRuleSet, - String destinationPath, Map<String, String> options) { + String destinationPath, Map<String, String> options, String release) { Classpath result = null; File file = new File(convertPathSeparators(classpathName)); if (file.isDirectory()) { @@ -298,7 +298,10 @@ public static Classpath getClasspath(String classpathName, String encoding, JRT_CLASSPATH_CACHE.put(file, result); } } else { - result = new ClasspathJar(file, true, accessRuleSet, null); + result = + (release == null) ? + new ClasspathJar(file, true, accessRuleSet, null) : + new ClasspathMultiReleaseJar(file, true, accessRuleSet, destinationPath, release); } } } else if (format == Util.JMOD_FILE) { @@ -370,7 +373,7 @@ private void initializeKnownFileNames(String[] initialFileNames) { public void scanForModules(Parser parser) { for (int i = 0, max = this.classpaths.length; i < max; i++) { File file = new File(this.classpaths[i].getPath()); - IModule iModule = ModuleFinder.scanForModule(this.classpaths[i], file, parser, false); + IModule iModule = ModuleFinder.scanForModule(this.classpaths[i], file, parser, false, null); if (iModule != null) this.moduleLocations.put(String.valueOf(iModule.name()), this.classpaths[i]); } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java index d65835471d..b2b6c5e932 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -1632,7 +1632,9 @@ protected void addNewEntry(ArrayList<FileSystem.Classpath> paths, String current customEncoding, isSourceOnly, accessRuleSet, - destPath, this.options); + destPath, + this.options, + this.releaseVersion); if (currentClasspath != null) { paths.add(currentClasspath); } else if (currentClasspathName.length() != 0) { @@ -3531,9 +3533,9 @@ protected ArrayList<FileSystem.Classpath> handleModulepath(String arg) { File file = new File(path); if (file.isDirectory()) { result.addAll( - ModuleFinder.findModules(file, null, getNewParser(), this.options, true)); + ModuleFinder.findModules(file, null, getNewParser(), this.options, true, this.releaseVersion)); } else { - Classpath modulePath = ModuleFinder.findModule(file, null, getNewParser(), this.options, true); + Classpath modulePath = ModuleFinder.findModule(file, null, getNewParser(), this.options, true, this.releaseVersion); if (modulePath != null) result.add(modulePath); } @@ -3559,7 +3561,7 @@ protected ArrayList<FileSystem.Classpath> handleModuleSourcepath(String arg) { // 1. Create FileSystem.Classpath for each module // 2. Iterator each module in case of directory for source files and add to this.fileNames - List<Classpath> modules = ModuleFinder.findModules(dir, this.destinationPath, getNewParser(), this.options, false); + List<Classpath> modules = ModuleFinder.findModules(dir, this.destinationPath, getNewParser(), this.options, false, this.releaseVersion); for (Classpath classpath : modules) { result.add(classpath); Path modLocation = Paths.get(classpath.getPath()).toAbsolutePath(); @@ -3607,7 +3609,7 @@ protected ArrayList<FileSystem.Classpath> handleClasspath(ArrayList<String> clas String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ if ((classProp == null) || (classProp.length() == 0)) { addPendingErrors(this.bind("configure.noClasspath")); //$NON-NLS-1$ - final Classpath classpath = FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null, this.options);//$NON-NLS-1$ + final Classpath classpath = FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null, this.options, this.releaseVersion);//$NON-NLS-1$ if (classpath != null) { initial.add(classpath); } @@ -3617,7 +3619,7 @@ protected ArrayList<FileSystem.Classpath> handleClasspath(ArrayList<String> clas while (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); FileSystem.Classpath currentClasspath = FileSystem - .getClasspath(token, customEncoding, null, this.options); + .getClasspath(token, customEncoding, null, this.options, this.releaseVersion); if (currentClasspath != null) { initial.add(currentClasspath); } else if (token.length() != 0) { @@ -3697,7 +3699,7 @@ protected ArrayList<FileSystem.Classpath> handleEndorseddirs(ArrayList<String> e FileSystem.Classpath classpath = FileSystem.getClasspath( current[j].getAbsolutePath(), - null, null, this.options); + null, null, this.options, this.releaseVersion); if (classpath != null) { result.add(classpath); } @@ -3758,7 +3760,7 @@ protected ArrayList<FileSystem.Classpath> handleExtdirs(ArrayList<String> extdir FileSystem.Classpath classpath = FileSystem.getClasspath( current[j].getAbsolutePath(), - null, null, this.options); + null, null, this.options, this.releaseVersion); if (classpath != null) { result.add(classpath); } diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java index 0ef53adfc0..1d48b3d0b2 100644 --- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java +++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.StringTokenizer; import java.util.jar.JarFile; import java.util.jar.Manifest; +import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.eclipse.jdt.internal.compiler.CompilationResult; @@ -35,45 +36,46 @@ import org.eclipse.jdt.internal.compiler.util.Util; public class ModuleFinder { - public static List<FileSystem.Classpath> findModules(File f, String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath) { + public static List<FileSystem.Classpath> findModules(File f, String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath, String release) { List<FileSystem.Classpath> collector = new ArrayList<>(); - scanForModules(destinationPath, parser, options, isModulepath, false, collector, f); + scanForModules(destinationPath, parser, options, isModulepath, false, collector, f, release); return collector; } protected static FileSystem.Classpath findModule(final File file, String destinationPath, Parser parser, - Map<String, String> options, boolean isModulepath) { + Map<String, String> options, boolean isModulepath, String release) { FileSystem.Classpath modulePath = FileSystem.getClasspath(file.getAbsolutePath(), null, !isModulepath, null, - destinationPath == null ? null : (destinationPath + File.separator + file.getName()), options); + destinationPath == null ? null : (destinationPath + File.separator + file.getName()), options, release); if (modulePath != null) { - scanForModule(modulePath, file, parser, isModulepath); + scanForModule(modulePath, file, parser, isModulepath, release); } return modulePath; } protected static void scanForModules(String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath, - boolean thisAnAutomodule, List<FileSystem.Classpath> collector, final File file) { + boolean thisAnAutomodule, List<FileSystem.Classpath> collector, final File file, String release) { FileSystem.Classpath entry = FileSystem.getClasspath( file.getAbsolutePath(), null, !isModulepath, null, destinationPath == null ? null : (destinationPath + File.separator + file.getName()), - options); + options, + release); if (entry != null) { - IModule module = scanForModule(entry, file, parser, thisAnAutomodule); + IModule module = scanForModule(entry, file, parser, thisAnAutomodule, release); if (module != null) { collector.add(entry); } else { if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { - scanForModules(destinationPath, parser, options, isModulepath, isModulepath, collector, f); + scanForModules(destinationPath, parser, options, isModulepath, isModulepath, collector, f, release); } } } } } - protected static IModule scanForModule(FileSystem.Classpath modulePath, final File file, Parser parser, boolean considerAutoModules) { + protected static IModule scanForModule(FileSystem.Classpath modulePath, final File file, Parser parser, boolean considerAutoModules, String release) { IModule module = null; if (file.isDirectory()) { String[] list = file.list(new FilenameFilter() { @@ -106,7 +108,7 @@ public class ModuleFinder { } else { String moduleDescPath = getModulePathForArchive(file); if (moduleDescPath != null) { - module = extractModuleFromArchive(file, modulePath, moduleDescPath); + module = extractModuleFromArchive(file, modulePath, moduleDescPath, release); } } if (considerAutoModules && module == null && !(modulePath instanceof ClasspathJrt)) { @@ -224,10 +226,17 @@ public class ModuleFinder { } return null; } - private static IModule extractModuleFromArchive(File file, Classpath pathEntry, String path) { + private static IModule extractModuleFromArchive(File file, Classpath pathEntry, String path, String release) { ZipFile zipFile = null; try { zipFile = new ZipFile(file); + if (release != null) { + String releasePath = "META-INF/versions/" + release + "/" + path; //$NON-NLS-1$ //$NON-NLS-2$ + ZipEntry entry = zipFile.getEntry(releasePath); + if (entry != null) { + path = releasePath; + } + } ClassFileReader reader = ClassFileReader.read(zipFile, path); IModule module = getModule(reader); if (module != null) { |