@Override public void close() throws IOException { this.locationHandler.close(); for (Archive archive : this.archivesCache.values()) { archive.close(); } this.archivesCache.clear(); for (URLClassLoader cl : this.classloaders.values()) { cl.close(); } this.classloaders.clear(); }
private void deriveOutputLocationForModules(String moduleName, Collection<? extends Path> paths) { LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT, moduleName); if (wrapper == null) { // First get from our internally known location for legacy/unnamed location wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT, ""); //$NON-NLS-1$ if (wrapper == null) { wrapper = this.locationHandler.getLocation(StandardLocation.CLASS_OUTPUT); } if (wrapper != null) { Iterator<? extends Path> iterator = wrapper.paths.iterator(); if (iterator.hasNext()) { try { // 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)); } catch(Exception e) { e.printStackTrace(); } } } } } private void deriveSourceOutputLocationForModules(String moduleName, Collection<? extends Path> paths) {
@Override public Iterable<Set<Location>> listLocationsForModules(Location location) { validateModuleLocation(location, ""); //$NON-NLS-1$ return this.locationHandler.listLocationsForModules(location); }
@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 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.locationHandler.setLocation(location, "", getPaths(files)); //$NON-NLS-1$ }
public EclipseFileManager(Locale locale, Charset charset) { this.locale = locale == null ? Locale.getDefault() : locale; this.charset = charset == null ? Charset.defaultCharset() : charset; this.locationHandler = new ModuleLocationHandler(); this.classloaders = new HashMap<>(); this.archivesCache = new HashMap<>(); this.isOnJvm9 = isRunningJvm9(); try { initialize(Util.getJavaHome()); } catch (IOException e) { e.printStackTrace(); // ignore } try { this.bundle = ResourceBundleFactory.getBundle(this.locale); } catch(MissingResourceException e) { 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 {
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); }
@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; }
private void deriveSourceOutputLocationForModules(String moduleName, Collection<? extends Path> paths) { LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.SOURCE_OUTPUT, moduleName); if (wrapper == null) { // First get from our internally known location for legacy/unnamed location wrapper = this.locationHandler.getLocation(StandardLocation.SOURCE_OUTPUT, ""); //$NON-NLS-1$ if (wrapper == null) { wrapper = this.locationHandler.getLocation(StandardLocation.SOURCE_OUTPUT); } if (wrapper != null) { Iterator<? extends Path> iterator = wrapper.paths.iterator(); if (iterator.hasNext()) { try { // Per module output location is always a singleton list Path path = iterator.next().resolve(moduleName); this.locationHandler.setLocation(StandardLocation.SOURCE_OUTPUT, moduleName, Collections.singletonList(path)); } catch(Exception e) { e.printStackTrace(); } } } } } @Override
@Override public Location getLocationForModule(Location location, String moduleName) throws IOException { validateModuleLocation(location, moduleName); Location result = this.locationHandler.getLocation(location, moduleName); if (result == null && location == StandardLocation.CLASS_OUTPUT) { LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.MODULE_SOURCE_PATH, moduleName); deriveOutputLocationForModules(moduleName, wrapper.paths); result = getLocationForModule(location, moduleName); } else if (result == null && location == StandardLocation.SOURCE_OUTPUT) { LocationWrapper wrapper = this.locationHandler.getLocation(StandardLocation.MODULE_SOURCE_PATH, moduleName); deriveSourceOutputLocationForModules(moduleName, wrapper.paths); result = getLocationForModule(location, moduleName); } return result; }
@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)); } } } } } }
@Override public Iterable<? extends File> getLocation(Location location) { 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()); }