public ClassLoader getClassLoader() { // returns CompilingClassLoader try { return (ClassLoader) ReflectionUtils.invokeMethod2(moduleSpaceHost, "getClassLoader"); } catch (Throwable e) { throw ReflectionUtils.propagate(e); } }
public DispatchIdOracle getDispatchIdOracle(Object delegate) throws Exception { if (dispatchIdOracle == null) { final Object dispatchIdOracleImpl = ReflectionUtils.invokeMethod2(delegate, "getDispatchIdOracle"); dispatchIdOracle = new DispatchIdOracleImpl(dispatchIdOracleImpl); } return dispatchIdOracle; }
public void dispose() { if (moduleSpaceHost != null) { // clear static caches ClassLoader devClassLoader = getDevClassLoader(); try { Class<?> clazz = devClassLoader.loadClass("com.google.gwt.i18n.rebind.ClearStaticData"); ReflectionUtils.invokeMethod2(clazz, "clear"); } catch (Throwable e) { } try { Class<?> clazz = devClassLoader.loadClass("com.google.gwt.uibinder.rebind.model.OwnerFieldClass"); Map<?, ?> map = (Map<?, ?>) ReflectionUtils.getFieldObject(clazz, "FIELD_CLASSES"); map.clear(); } catch (Throwable e) { } // remove parent of CompilingClassLoader if (parentClassLoader != null) { ClassLoader classLoader = getClassLoader(); ReflectionUtils.setField(classLoader, "parent", null); } // clear "loadedModulesCaches" in com.google.gwt.dev.cfg.ModuleDefLoader try { Class<?> moduleDefLoader = devClassLoader.loadClass("com.google.gwt.dev.cfg.ModuleDefLoader"); Map<?, ?> loadedModulesCaches = (Map<?, ?>) ReflectionUtils.getFieldObject(moduleDefLoader, "loadedModulesCaches"); loadedModulesCaches.clear(); } catch (Throwable e) { } /*// clear "threadLocalLogger" in com.google.gwt.dev.shell.ModuleSpace try { Class<?> classModuleSpace = devClassLoader.loadClass("com.google.gwt.dev.shell.ModuleSpace"); ThreadLocal<?> threadLocalLogger = (ThreadLocal<?>) ReflectionUtils.getFieldObject(classModuleSpace, "threadLocalLogger"); threadLocalLogger.set(null); } catch (Throwable e) { } // shutdown com.google.gwt.dev.javac.PersistentUnitCache try { Class<?> classUnitCacheFactory = devClassLoader.loadClass("com.google.gwt.dev.javac.UnitCacheFactory"); Object cacheInstance = ReflectionUtils.getFieldObject(classUnitCacheFactory, "instance"); if (cacheInstance != null) { Method shutdownMethod = ReflectionUtils.getMethodBySignature(cacheInstance.getClass(), "shutdown()"); if (shutdownMethod != null) { shutdownMethod.invoke(cacheInstance); } } ReflectionUtils.setField(classUnitCacheFactory, "instance", null); } catch (Throwable e) { } // Call and remove GWT related java.lang.ApplicationShutdownHooks try { Class<?> hooksClass = ClassLoader.getSystemClassLoader().loadClass("java.lang.ApplicationShutdownHooks"); Field hooksField = ReflectionUtils.getFieldByName(hooksClass, "hooks"); @SuppressWarnings("unchecked") Map<Thread, ?> hooks = (Map<Thread, ?>) hooksField.get(null); List<Thread> threads = ImmutableList.copyOf(hooks.keySet()); for (Thread thread : threads) { ClassLoader contextClassLoader = thread.getContextClassLoader(); if (contextClassLoader == devClassLoader) { thread.setContextClassLoader(ClassLoader.getSystemClassLoader()); thread.run(); hooks.remove(thread); } } } catch (Throwable e) { e.printStackTrace(); } // close com.google.gwt.dev.util.DiskCache try { Class<?> classDiskCache = devClassLoader.loadClass("com.google.gwt.dev.util.DiskCache"); Object cacheInstance = ReflectionUtils.getFieldObject(classDiskCache, "INSTANCE"); ReflectionUtils.invokeMethod(cacheInstance, "close()"); } catch (Throwable e) { } // find embedded Guava Finalizer and clear reference of our "dev" URLClassLoader try { Thread[] threads = getAllThreads(); for (Thread thread : threads) { if (thread != null && thread.getContextClassLoader() == devClassLoader) { thread.setContextClassLoader(null); } } } catch (Throwable e) { }*/ } // if (browserShell != null) { browserShell.dispose(); } logSupport.dispose(); moduleSpaceHost = null; impl = null; projectClassLoader = null; dispatchIdOracle = null; }