public static void instantiateDownloaded(JLabel update) { // These are found in the downloadedListenerClasses list for (Class<?> clazz : downloadedListenerClasses) { ExternalListener instance; try { doUpdate(update, Messages.getString("NetworkTab.48") + " " + clazz.getSimpleName()); postInstall(clazz); LOGGER.debug("do inst of " + clazz.getSimpleName()); instance = (ExternalListener) clazz.newInstance(); doUpdate(update, instance.name() + " " + Messages.getString("NetworkTab.49")); registerListener(instance); if (PMS.get().getFrame() instanceof LooksFrame) { LooksFrame frame = (LooksFrame) PMS.get().getFrame(); if (!frame.getPt().appendPlugin(instance)) { LOGGER.warn("Plugin limit of 30 has been reached"); } } } catch (InstantiationException | IllegalAccessException e) { LOGGER.error("Error instantiating plugin", e); } } downloadedListenerClasses.clear(); }
private static void purgeCode(String mainClass, URL newUrl) { Class<?> clazz1 = null; for (Class<?> clazz : externalListenerClasses) { if (mainClass.equals(clazz.getCanonicalName())) { clazz1 = clazz; break; } } if (clazz1 == null) { return; } externalListenerClasses.remove(clazz1); ExternalListener remove = null; for (ExternalListener list : externalListeners) { if (list.getClass().equals(clazz1)) { remove = list; break; } } RendererConfiguration.resetAllRenderers(); if (remove != null) { externalListeners.remove(remove); remove.shutdown(); LooksFrame frame = (LooksFrame) PMS.get().getFrame(); frame.getPt().removePlugin(remove); } for (int i = 0; i < 3; i++) { System.gc(); } URLClassLoader cl = (URLClassLoader) clazz1.getClassLoader(); URL[] urls = cl.getURLs(); for (URL url : urls) { String mainClass1 = getMainClass(url); if (mainClass1 == null || !mainClass.equals(mainClass1)) { continue; } File f = url2file(url); File f1 = url2file(newUrl); if (f1 == null || f == null) { continue; } if (!f1.getName().equals(f.getName())) { addToPurgeFile(f); } } }