[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-CVS ] plugins/ProjectViewer/projectviewer
From:       Marcelo Vanzin <vanza () users ! sourceforge ! net>
Date:       2006-06-30 5:19:20
Message-ID: E1FwBPd-0005G7-EE () mail ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/jedit/plugins/ProjectViewer/projectviewer
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14961/projectviewer

Modified Files:
	ProjectManager.java ProjectPlugin.java ProjectViewer.java 
Log Message:
- fix a bug that has been haunting me for a looooooooong time (damn class loaders...)

Index: ProjectManager.java
===================================================================
RCS file: /cvsroot/jedit/plugins/ProjectViewer/projectviewer/ProjectManager.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- ProjectManager.java	26 Jun 2006 01:11:11 -0000	1.50
+++ ProjectManager.java	30 Jun 2006 05:19:18 -0000	1.51
@@ -121,10 +121,10 @@
 		}
 
 		// Loads listeners from other plugins
-		EditPlugin[] plugins = jEdit.getPlugins();
-		for (int i = 0; i < plugins.length; i++) {
-			addProjectListeners(plugins[i].getPluginJAR());
-		}
+		//EditPlugin[] plugins = jEdit.getPlugins();
+		//for (int i = 0; i < plugins.length; i++) {
+			//addProjectListeners(plugins[i].getPluginJAR());
+		//}
 	} //}}}
 
 	//{{{ Instance variables
@@ -442,15 +442,15 @@
 	 *	Adds the plugin's declared project listeners to the list of project
 	 *	listeners to be added to a project when it's activated.
 	 */
-	public void addProjectListeners(PluginJAR jar) {
-		if (jar.getPlugin() == null) return;
+	public int addProjectListeners(PluginJAR jar) {
+		if (jar.getPlugin() == null) return 0;
 		String list = jEdit.getProperty("plugin.projectviewer." +
 						jar.getPlugin().getClassName() + ".prj-listeners");
 		Collection aList = PVActions.listToObjectCollection(list, jar, ProjectListener.class);
 		if (aList != null && aList.size() > 0) {
 			listeners.addAll(aList);
 			// Add the listeners to loaded projects
-			if (aList.size() > 0 && projects.size() > 0)
+			if (projects.size() > 0)
 			for (Iterator i = projects.values().iterator(); i.hasNext(); ) {
 				Entry e = (Entry) i.next();
 				if (e.isLoaded) {
@@ -459,7 +459,9 @@
 					}
 				}
 			}
+			return aList.size();
 		}
+		return 0;
 	} //}}}
 
 	//{{{ +removeProjectListeners(PluginJAR) : void

Index: ProjectViewer.java
===================================================================
RCS file: /cvsroot/jedit/plugins/ProjectViewer/projectviewer/ProjectViewer.java,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -d -r1.109 -r1.110
--- ProjectViewer.java	30 Jun 2006 02:40:46 -0000	1.109
+++ ProjectViewer.java	30 Jun 2006 05:19:18 -0000	1.110
@@ -178,15 +178,17 @@
 	 *	have been declared by the given plugin using properties. For global
 	 *	listeners, "view" should be null.
 	 */
-	public static void addToolbarActions(PluginJAR jar) {
-		if (jar.getPlugin() == null) return;
+	public static int addToolbarActions(PluginJAR jar) {
+		if (jar.getPlugin() == null) return 0;
 		String list = jEdit.getProperty("plugin.projectviewer." +
 							jar.getPlugin().getClassName() + ".toolbar-actions");
 		Collection aList = PVActions.listToObjectCollection(list, jar, Action.class);
 		if (aList != null && aList.size() > 0) {
 			actions.addAll(aList);
 			actionsChanged();
+			return aList.size();
 		}
+		return 0;
 	} //}}}
 
 	//{{{ -_actionsChanged()_ : void
@@ -357,8 +359,8 @@
 	 *	have been declared by the given plugin using properties. For global
 	 *	listeners, "view" should be null.
 	 */
-	public static void addProjectViewerListeners(PluginJAR jar, View view) {
-		if (jar.getPlugin() == null) return;
+	public static int addProjectViewerListeners(PluginJAR jar, View view) {
+		if (jar.getPlugin() == null) return 0;
 		String list;
 		if (view == null) {
 			list = jEdit.getProperty("plugin.projectviewer." +
@@ -376,7 +378,9 @@
 			} else {
 				existing.addAll(aList);
 			}
+			return aList.size();
 		}
+		return 0;
 	} //}}}
 
 	//{{{ +_fireNodeMovedEvent(VPTNode, VPTGroup)_ : void

Index: ProjectPlugin.java
===================================================================
RCS file: /cvsroot/jedit/plugins/ProjectViewer/projectviewer/ProjectPlugin.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- ProjectPlugin.java	12 Dec 2005 04:33:47 -0000	1.42
+++ ProjectPlugin.java	30 Jun 2006 05:19:18 -0000	1.43
@@ -179,18 +179,63 @@
 	private void checkPluginUpdate(PluginUpdate msg) {
 		if (msg.getWhat() == PluginUpdate.LOADED) {
 			try {
-				ProjectViewer.addProjectViewerListeners(msg.getPluginJAR(), null);
-				ProjectManager.getInstance().addProjectListeners(msg.getPluginJAR());
-				ProjectViewer.addToolbarActions(msg.getPluginJAR());
-				VPTContextMenu.registerActions(msg.getPluginJAR());
-				ProjectPersistenceManager.loadNodeHandlers(msg.getPluginJAR());
+				int cnt = 0;
+				cnt += ProjectViewer.addProjectViewerListeners(msg.getPluginJAR(), null);
+				cnt += ProjectManager.getInstance().addProjectListeners(msg.getPluginJAR());
+				cnt += ProjectViewer.addToolbarActions(msg.getPluginJAR());
+				cnt += VPTContextMenu.registerActions(msg.getPluginJAR());
+				cnt += ProjectPersistenceManager.loadNodeHandlers(msg.getPluginJAR());
 
 				View[] v = jEdit.getViews();
 				for (int i = 0; i < v.length; i++) {
 					if (ProjectViewer.getViewer(v[i]) != null) {
-						ProjectViewer.addProjectViewerListeners(msg.getPluginJAR(), v[i]);
+						cnt += ProjectViewer.addProjectViewerListeners(msg.getPluginJAR(), v[i]);
 					}
 				}
+
+				if (cnt > 0) {
+					/*
+					This is ugly - I feel kinda dirty.
+					The reason for this here is kinda non-trivial: since PV
+					allows other plugins to extend its functionality, PV
+					creates references to classes that are loaded by those
+					other plugins.
+
+					The problem happens when that plugin is unloaded.
+					PV's class loader will *still*, in some way, keep
+					a reference to those classes - even when we get rid
+					of all objects that were loaded by the plugin's old
+					class loader, which should now be defunct. Since PV
+					doesn't depend on those plugins, jEdit doesn't
+					unload PV when unloading those plugins. So if those
+					plugins try to get some info from PV, they risk
+					getting ClassCastExceptions because the classes
+					will be different (same class, different class loader).
+
+					So what I'm doing here is, whenever a plugin registers
+					anything in PV, I create a "fake" dependency at runtime,
+					and tell jEdit to re-check PV's dependencies. This way,
+					the dependency is registered and jEdit will unload PV
+					when unloading the other plugin, making everything
+					work as it should.
+
+					If anyone has any idea of a better way to fix this,
+					I'd be more than thankful to use it!
+					*/
+
+					String root = "plugin.projectviewer.ProjectPlugin.depend.";
+					String klass = msg.getPluginJAR().getPlugin().getClassName();
+					cnt = 0;
+					while (jEdit.getProperty(root + cnt) != null)
+						cnt++;
+
+
+					jEdit.setProperty(root + cnt,
+						"optional plugin " + klass +  " " +
+						jEdit.getProperty("plugin." + klass + ".version")
+					);
+					getPluginJAR().checkDependencies();
+				}
 			} catch (Exception e) {
 				Log.log(Log.WARNING, this, "Error loading PV extension, error follows.");
 				Log.log(Log.ERROR, this, e);


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic