Author: mes
Date: 2010-02-02 12:54:52 -0800 (Tue, 02 Feb 2010)
New Revision: 19141
Modified:
cytoscape/trunk/src/cytoscape/CytoscapeInit.java
cytoscape/trunk/src/cytoscape/plugin/JarUtil.java
cytoscape/trunk/src/cytoscape/plugin/PluginManager.java
Log:
More error handling for plugin loading. We are now catching much more and
hopefully failing a bit more gracefully when something goes wrong with plugin
loading.
Modified: cytoscape/trunk/src/cytoscape/CytoscapeInit.java
===================================================================
--- cytoscape/trunk/src/cytoscape/CytoscapeInit.java 2010-02-02 20:29:04 UTC
(rev 19140)
+++ cytoscape/trunk/src/cytoscape/CytoscapeInit.java 2010-02-02 20:54:52 UTC
(rev 19141)
@@ -57,6 +57,12 @@
import cytoscape.logger.CyLogger;
import cytoscape.logger.LogLevel;
import cytoscape.plugin.PluginManager;
+import cytoscape.plugin.DownloadableInfo;
+import cytoscape.plugin.PluginInfo;
+import cytoscape.plugin.ThemeInfo;
+import cytoscape.plugin.ManagerException;
+import cytoscape.plugin.Category;
+import cytoscape.plugin.PluginStatus;
import cytoscape.util.FileUtil;
import cytoscape.util.NestedNetworkViewUpdater;
import cytoscape.util.shadegrown.WindowUtilities;
@@ -117,6 +123,8 @@
// Error message
private static String ErrorMsg = "";
+ private PluginManager mgr;
+
/**
* Creates a new CytoscapeInit object.
*/
@@ -153,16 +161,12 @@
// Instantiate a NestedNetworkViewUpdater
nestedNetworkViewUpdater = new
NestedNetworkViewUpdater();
- // get the manager so it can test for webstart before
menus are
- // created (little hacky)
- PluginManager.getPluginManager();
+ initPluginManager();
// see if we are in headless mode
// show splash screen, if appropriate
- /*
- * Initialize as GUI mode
- */
+ // Initialize as GUI mode
if ((initParams.getMode() == CyInitParams.GUI)
|| (initParams.getMode() ==
CyInitParams.EMBEDDED_WINDOW)) {
final ImageIcon image = new
ImageIcon(this.getClass()
@@ -180,9 +184,7 @@
// Register the logger dialog as a log handler
logger.addLogHandler(LoggerDialog.getLoggerDialog(), LogLevel.LOG_DEBUG);
- /*
- * Create Desktop. This includes Vizmapper GUI
initialization.
- */
+ // Create Desktop. This includes Vizmapper GUI
initialization.
Cytoscape.getDesktop();
// set the wait cursor
@@ -196,71 +198,10 @@
logger.info("init mode: " + initParams.getMode());
- PluginManager mgr = PluginManager.getPluginManager();
-
- try {
- logger.info("Updating plugins...");
- mgr.delete();
- } catch (cytoscape.plugin.ManagerException me) {
- logger.warn("Error updating plugins:
"+me.getMessage(), me);
- }
-
- mgr.install();
-
logger.info("loading plugins....");
+ loadPlugins();
- /*
- * TODO smart plugin loading. If there are multiple of
the same
- * plugin (this will only work in the .cytoscape
directory) load the
- * newest version first. Should be able to examine the
directories
- * for this information. All installed plugins are
named like
- * 'MyPlugin-1.0' currently this isn't necessary as old
version are
- * not kept around
- */
- List<String> InstalledPlugins = new ArrayList<String>();
- // load from those listed on the command line
- InstalledPlugins.addAll(initParams.getPlugins());
-
- // Get all directories where plugins have been installed
- // going to have to be a little smart...themes contain
their plugins
- // in subdirectories
- List<cytoscape.plugin.DownloadableInfo>
MgrInstalledPlugins =
mgr.getDownloadables(cytoscape.plugin.PluginStatus.CURRENT);
-
- for (cytoscape.plugin.DownloadableInfo dInfo :
MgrInstalledPlugins) {
- if
(dInfo.getCategory().equals(cytoscape.plugin.Category.CORE.getCategoryText()))
- continue;
-
- switch (dInfo.getType()) { // TODO get rid of
switches
- case PLUGIN:
-
InstalledPlugins.add(((cytoscape.plugin.PluginInfo) dInfo)
-
.getInstallLocation());
-
- break;
-
- case THEME:
-
- cytoscape.plugin.ThemeInfo
tInfo = (cytoscape.plugin.ThemeInfo) dInfo;
-
- for
(cytoscape.plugin.PluginInfo plugin : tInfo.getPlugins()) {
-
InstalledPlugins.add(plugin.getInstallLocation());
- }
-
- break;
- }
- }
-
- mgr.loadPlugins(InstalledPlugins);
-
- List<Throwable> pluginLoadingErrors =
mgr.getLoadingErrors();
-
- for (Throwable t : pluginLoadingErrors) {
- logger.warn("Plugin loading error:
"+t.toString(),t);
- }
-
- mgr.clearErrorList();
-
logger.info("loading session...");
-
boolean sessionLoaded = false;
if ((initParams.getMode() == CyInitParams.GUI)
|| (initParams.getMode() ==
CyInitParams.EMBEDDED_WINDOW)) {
@@ -612,7 +553,7 @@
.toArray(new String[] { }),
(String[])
initParams.getEdgeAttributeFiles()
.toArray(new String[] { }));
- } catch (Exception ex) {
+ } catch (Throwable ex) {
logger.error("failure loading specified attributes:
"+ex.getMessage(), ex);
}
}
@@ -620,4 +561,76 @@
private void initVizmapper() {
Cytoscape.getDesktop().getVizMapperUI().initVizmapperGUI();
}
+
+ /**
+ * This is separated from the rest of the plugin manager because by
getting
+ * the manager early, it can test for webstart before menus are
created.
+ * This is a little hacky.
+ */
+ private void initPluginManager() {
+ try {
+ mgr = PluginManager.getPluginManager();
+ } catch (Throwable tp) {
+ logger.warn("Failed to start plugin manager.", tp);
+ }
+ }
+
+ private void loadPlugins() {
+ try {
+ try {
+ logger.info("Updating plugins...");
+ mgr.delete();
+ } catch (ManagerException me) {
+ logger.warn("Error updating plugins:
"+me.getMessage(), me);
+ }
+
+ mgr.install();
+
+ //
+ // TODO smart plugin loading. If there are multiple of
the same
+ // plugin (this will only work in the .cytoscape
directory) load the
+ // newest version first. Should be able to examine the
directories
+ // for this information. All installed plugins are
named like
+ // 'MyPlugin-1.0' currently this isn't necessary as old
version are
+ // not kept around
+ //
+ List<String> installedPlugins = new ArrayList<String>();
+
+ // load from those listed on the command line
+ installedPlugins.addAll(initParams.getPlugins());
+
+ // Get all directories where plugins have been installed
+ // going to have to be a little smart...themes contain
their plugins
+ // in subdirectories
+ for (DownloadableInfo dInfo :
mgr.getDownloadables(PluginStatus.CURRENT)) {
+ if
(dInfo.getCategory().equals(Category.CORE.getCategoryText()))
+ continue;
+
+ // TODO get rid of switches
+ switch (dInfo.getType()) {
+ case PLUGIN:
+
installedPlugins.add(((PluginInfo) dInfo).getInstallLocation());
+
+ break;
+
+ case THEME:
+ ThemeInfo tInfo = (ThemeInfo)
dInfo;
+ for (PluginInfo plugin :
tInfo.getPlugins())
+
installedPlugins.add(plugin.getInstallLocation());
+
+ break;
+ }
+ }
+
+ mgr.loadPlugins(installedPlugins);
+
+ for (Throwable t : mgr.getLoadingErrors())
+ logger.warn("Plugin loading error:
"+t.toString(),t);
+
+ mgr.clearErrorList();
+
+ } catch (Exception e) {
+ logger.error("Plugin system initialization error:
"+e.toString(),e);
+ }
+ }
}
Modified: cytoscape/trunk/src/cytoscape/plugin/JarUtil.java
===================================================================
--- cytoscape/trunk/src/cytoscape/plugin/JarUtil.java 2010-02-02 20:29:04 UTC
(rev 19140)
+++ cytoscape/trunk/src/cytoscape/plugin/JarUtil.java 2010-02-02 20:54:52 UTC
(rev 19141)
@@ -85,11 +85,10 @@
break;
case ZIP:
- List<ZipEntry> Entries = ZipUtil
- .getAllFiles(fileName,
MATCH_JAR_REGEXP);
+ List<ZipEntry> Entries = ZipUtil.getAllFiles(fileName,
MATCH_JAR_REGEXP);
if (Entries.size() <= 0) {
- String[] FilePath = fileName.split("/");
- fileName = FilePath[FilePath.length - 1];
+ String[] filePath = fileName.split("/");
+ fileName = filePath[filePath.length - 1];
throw new IOException( fileName +
" does not contain any
jar files or is not a zip file.");
}
@@ -125,8 +124,8 @@
}
}
- } catch (Throwable t) {
- throw new IOException(t);
+ } catch (Exception e) {
+ throw new IOException(e);
}
return pluginClassName;
Modified: cytoscape/trunk/src/cytoscape/plugin/PluginManager.java
===================================================================
--- cytoscape/trunk/src/cytoscape/plugin/PluginManager.java 2010-02-02
20:29:04 UTC (rev 19140)
+++ cytoscape/trunk/src/cytoscape/plugin/PluginManager.java 2010-02-02
20:54:52 UTC (rev 19141)
@@ -405,14 +405,12 @@
// TODO would be better to fix how initializedPlugins are tracked...
private void cleanCurrentList() {
- List<DownloadableInfo> CurrentList = this
- .getDownloadables(PluginStatus.CURRENT);
+ List<DownloadableInfo> CurrentList =
getDownloadables(PluginStatus.CURRENT);
for (DownloadableInfo info : CurrentList) {
if (info.getType().equals(DownloadableType.PLUGIN)) {
PluginInfo pInfo = (PluginInfo) info;
if
(!initializedPlugins.containsKey(pInfo.getPluginClassName())) {
- pluginTracker
-
.removeDownloadable(info, PluginStatus.CURRENT);
+ pluginTracker.removeDownloadable(info,
PluginStatus.CURRENT);
}
}
}
@@ -422,8 +420,7 @@
* Sets all plugins on the "install" list to "current"
*/
public void install() {
- for (DownloadableInfo info : this
- .getDownloadables(PluginStatus.INSTALL)) {
+ for (DownloadableInfo info :
getDownloadables(PluginStatus.INSTALL)) {
install(info);
}
}
@@ -779,9 +776,10 @@
}
}
}
- } catch (MalformedURLException mue) {
- // mue.printStackTrace();
- loadingErrors.add(mue);
+ // Catching Throwable because Errors (e.g.
NoClassDefFoundError) could
+ // cause Cytoscape to crash, which plugins should
definitely not do.
+ } catch (Throwable t) {
+ loadingErrors.add(new PluginException("problem
loading plugin: "+currentPlugin,t));
}
}
// now load the plugins in the appropriate manner
@@ -816,8 +814,10 @@
for (URL url : urls) {
try {
addClassPath(url);
- } catch (Exception e) {
- loadingErrors.add(new IOException("Classloader
Error: " + url));
+ // Catching Throwable because Errors (e.g.
NoClassDefFoundError) could
+ // cause Cytoscape to crash, which plugins should
definitely not do.
+ } catch (Throwable t) {
+ loadingErrors.add(new
PluginException("Classloader Error: " + url, t));
}
}
@@ -897,15 +897,10 @@
if (totalPlugins == 0) {
logger.info("No plugin found in
specified jar - assuming it's a library.");
}
- } catch (IOException ioe) {
- // ioe.printStackTrace();
- loadingErrors.add(ioe);
- } catch (ClassNotFoundException cne) {
- // cne.printStackTrace();
- loadingErrors.add(cne);
- } catch (PluginException pe) {
- // pe.printStackTrace();
- loadingErrors.add(pe);
+ // Catching Throwable because Errors (e.g.
NoClassDefFoundError) could
+ // cause Cytoscape to crash, which plugins should
definitely not do.
+ } catch (Throwable t) {
+ loadingErrors.add(new PluginException("problem
loading plugin URL: " + urls[i], t));
}
}
}
@@ -921,12 +916,10 @@
try {
Class rclass = Class.forName(resource);
loadPlugin(rclass, null, true);
- } catch (ClassNotFoundException cne) {
- // cne.printStackTrace();
- loadingErrors.add(cne);
- } catch (PluginException pe) {
- // pe.printStackTrace();
- loadingErrors.add(pe);
+ // Catching Throwable because Errors (e.g.
NoClassDefFoundError) could
+ // cause Cytoscape to crash, which plugins should
definitely not do.
+ } catch (Throwable t) {
+ loadingErrors.add(new PluginException("problem
loading plugin resource: " + resource, t));
}
}
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.