protected ArrayList<FileSystem.Classpath> handleModulepath(String arg) { ArrayList<String> modulePaths = processModulePathEntries(arg); ArrayList<Classpath> result = new ArrayList<>(); if ((modulePaths != null && modulePaths.size() > 0)) { for (String path : modulePaths) { File file = new File(path); if (file.isDirectory()) { result.addAll( ModuleFinder.findModules(file, null, getNewParser(), this.options, true, this.releaseVersion)); } else { Classpath modulePath = ModuleFinder.findModule(file, null, getNewParser(), this.options, true, this.releaseVersion); if (modulePath != null) result.add(modulePath); } } } // TODO: What about chained jars from MANIFEST.MF? Check with spec return result; } protected ArrayList<FileSystem.Classpath> handleModuleSourcepath(String arg) {
switch (fileName) { case IModule.MODULE_INFO_CLASS: module = ModuleFinder.extractModuleFromClass(new File(file, fileName), modulePath); break; case IModule.MODULE_INFO_JAVA: module = ModuleFinder.extractModuleFromSource(new File(file, fileName), parser, modulePath); if (module == null) return null; String moduleDescPath = getModulePathForArchive(file); if (moduleDescPath != null) { module = extractModuleFromArchive(file, modulePath, moduleDescPath, release); module = IModule.createAutomatic(getFileName(file), file.isFile(), getManifest(file));
protected static void scanForModules(String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath, boolean thisAnAutomodule, List<FileSystem.Classpath> collector, final File file) { FileSystem.Classpath entry = FileSystem.getClasspath( file.getAbsolutePath(), null, !isModulepath, null, destinationPath == null ? null : (destinationPath + File.separator + file.getName()), options); if (entry != null) { IModule module = scanForModule(entry, file, parser, thisAnAutomodule); 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); } } } } } protected static IModule scanForModule(FileSystem.Classpath modulePath, final File file, Parser parser, boolean considerAutoModules) {
switch (fileName) { case IModule.MODULE_INFO_CLASS: module = ModuleFinder.extractModuleFromClass(new File(file, fileName), modulePath); break; case IModule.MODULE_INFO_JAVA: module = ModuleFinder.extractModuleFromSource(new File(file, fileName), parser, modulePath); if (module == null) return null; } else if (isJar(file)) { module = extractModuleFromJar(file, modulePath); module = IModule.createAutomatic(getFileName(file), file.isFile(), getManifest(file));
protected static FileSystem.Classpath findModule(final File file, String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath) { FileSystem.Classpath modulePath = FileSystem.getClasspath(file.getAbsolutePath(), null, !isModulepath, null, destinationPath == null ? null : (destinationPath + File.separator + file.getName()), options); if (modulePath != null) { scanForModule(modulePath, file, parser, isModulepath); } return modulePath; } protected static void scanForModules(String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath,
private static IModule extractModuleFromClass(File classfilePath, Classpath pathEntry) { ClassFileReader reader; try { reader = ClassFileReader.read(classfilePath); IModule module = getModule(reader); if (module != null) { return reader.getModuleDeclaration(); } return null; } catch (ClassFormatException | IOException e) { e.printStackTrace(); } return null; } private static IModule getModule(ClassFileReader classfile) {
List<Classpath> modules = ModuleFinder.findModules(dir, this.destinationPath, getNewParser(), this.options, false); for (Classpath classpath : modules) { result.add(classpath);
private void processAddonModuleOptions(FileSystem env) { Map<String, IPackageExport[]> exports = new HashMap<>(); for (String option : this.addonExports) { AddExport addExport = ModuleFinder.extractAddonExport(option); if (addExport != null) { String modName = addExport.sourceModuleName; String[] result = ModuleFinder.extractAddonRead(option); if (result != null && result.length == 2) { env.addModuleUpdate(result[0], m -> m.addReads(result[1].toCharArray()), UpdateKind.MODULE);
protected static FileSystem.Classpath findModule(final File file, String destinationPath, Parser parser, 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, release); if (modulePath != null) { scanForModule(modulePath, file, parser, isModulepath, release); } return modulePath; } protected static void scanForModules(String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath,
private static IModule extractModuleFromClass(File classfilePath, Classpath pathEntry) { ClassFileReader reader; try { reader = ClassFileReader.read(classfilePath); IModule module = getModule(reader); if (module != null) { return reader.getModuleDeclaration(); } return null; } catch (ClassFormatException | IOException e) { e.printStackTrace(); } return null; } private static IModule getModule(ClassFileReader classfile) {
List<Classpath> modules = ModuleFinder.findModules(dir, this.destinationPath, getNewParser(), this.options, false, this.releaseVersion); for (Classpath classpath : modules) { result.add(classpath);
private void processAddonModuleOptions(FileSystem env) { Map<String, IPackageExport[]> exports = new HashMap<>(); for (String option : this.addonExports) { IModule mod = ModuleFinder.extractAddonExport(option); if (mod != null) { String modName = new String(mod.name()); String[] result = ModuleFinder.extractAddonRead(option); if (result != null && result.length == 2) { env.addModuleUpdate(result[0], m -> m.addReads(result[1].toCharArray()), UpdateKind.MODULE);
protected static void scanForModules(String destinationPath, Parser parser, Map<String, String> options, boolean isModulepath, 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, release); if (entry != null) { 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, release); } } } } } protected static IModule scanForModule(FileSystem.Classpath modulePath, final File file, Parser parser, boolean considerAutoModules, String release) {
protected ArrayList<FileSystem.Classpath> handleModulepath(String arg) { ArrayList<String> modulePaths = processModulePathEntries(arg); ArrayList<Classpath> result = new ArrayList<>(); if ((modulePaths != null && modulePaths.size() > 0)) { for (String path : modulePaths) { File file = new File(path); if (file.isDirectory()) { result = (ArrayList<Classpath>) ModuleFinder.findModules(file, null, getNewParser(), this.options, true); } else { Classpath modulePath = ModuleFinder.findModule(file, null, getNewParser(), this.options, true); if (modulePath != null) result.add(modulePath); } } } // TODO: What about chained jars from MANIFEST.MF? Check with spec return result; } protected ArrayList<FileSystem.Classpath> handleModuleSourcepath(String arg) {
/** TESTS ONLY */ 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, null); if (iModule != null) this.moduleLocations.put(String.valueOf(iModule.name()), this.classpaths[i]); } } @Override
private static IModule extractModuleFromJar(File file, Classpath pathEntry) { ZipFile zipFile = null; try { zipFile = new ZipFile(file); ClassFileReader reader = ClassFileReader.read(zipFile, IModule.MODULE_INFO_CLASS); IModule module = getModule(reader); if (module != null) { return reader.getModuleDeclaration(); } return null; } catch (ClassFormatException | IOException e) { // Nothing to be done here } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { // Nothing much to do here } } } return null; } private static IModule extractModuleFromClass(File classfilePath, Classpath pathEntry) {
@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, this.releaseVersion); 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)); } } } } }
/** TESTS ONLY */ 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); if (iModule != null) this.moduleLocations.put(String.valueOf(iModule.name()), this.classpaths[i]); } } public void cleanup() {
IModule module = getModule(reader); if (module != null) { return reader.getModuleDeclaration();