Author: mes
Date: 2011-01-24 21:15:41 -0800 (Mon, 24 Jan 2011)
New Revision: 23596

Modified:
   
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/CyPluginAdapterImpl.java
   
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/PluginManager.java
   
core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
   core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
   
core3/plugin-impl/trunk/src/test/java/org/cytoscape/plugin/internal/CyPluginAdapterImplTest.java
Log:
added CySwingApplication to api and removed great swaths of unused code

Modified: 
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/CyPluginAdapterImpl.java
===================================================================
--- 
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/CyPluginAdapterImpl.java
        2011-01-25 05:15:18 UTC (rev 23595)
+++ 
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/CyPluginAdapterImpl.java
        2011-01-25 05:15:41 UTC (rev 23596)
@@ -14,6 +14,7 @@
 import org.cytoscape.model.subnetwork.CyRootNetworkFactory;
 import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.session.CySessionManager;
+import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.view.model.CyNetworkViewFactory;
 import org.cytoscape.view.model.CyNetworkViewManager;
 import org.cytoscape.view.presentation.RenderingEngineFactory;
@@ -40,6 +41,7 @@
        private final CyNetworkViewFactory cyNetworkViewFactory;
        private final CyRootNetworkFactory cyRootNetworkFactory;
        private final CySessionManager cySessionManager;
+       private final CySwingApplication cySwingApplication;
        private final RenderingEngineFactory presentationFactory;
        private final TaskManager taskManager;
        private final VisualMappingManager visualMappingManager;
@@ -60,6 +62,7 @@
                            CyNetworkViewFactory cyNetworkViewFactory,
                            CyRootNetworkFactory cyRootNetworkFactory,
                            CySessionManager cySessionManager,
+                           CySwingApplication cySwingApplication,
                            RenderingEngineFactory presentationFactory,
                            TaskManager taskManager,
                            VisualMappingManager visualMappingManager,
@@ -75,6 +78,7 @@
                this.cyNetworkViewFactory = cyNetworkViewFactory;
                this.cyRootNetworkFactory = cyRootNetworkFactory;
                this.cySessionManager = cySessionManager;
+               this.cySwingApplication = cySwingApplication;
                this.presentationFactory = presentationFactory;
                this.taskManager = taskManager;
                this.visualMappingManager = visualMappingManager;
@@ -112,4 +116,6 @@
        public CyNetworkViewManager getCyNetworkViewManager() { return 
networkViewManager; }
 
        public CyApplicationManager getCyApplicationManager() { return 
applicationManager; }
+
+       public CySwingApplication getCySwingApplication() { return 
cySwingApplication; }
 }

Modified: 
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/PluginManager.java
===================================================================
--- 
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/PluginManager.java
      2011-01-25 05:15:18 UTC (rev 23595)
+++ 
core3/plugin-impl/trunk/src/main/java/org/cytoscape/plugin/internal/PluginManager.java
      2011-01-25 05:15:41 UTC (rev 23596)
@@ -284,9 +284,7 @@
                        logger.info("Creating directories for "
                                        + tempDir.getAbsolutePath());
                        if (!tempDir.mkdirs()) {
-                               
-                               System.out.println("Failed to create directory 
--- "+ tempDir.getAbsolutePath());
-                               //Cytoscape.exit(-1);
+                               logger.warn("Failed to create directory --- "+ 
tempDir.getAbsolutePath());
                        }
                }
 
@@ -711,7 +709,6 @@
                }
                // don't need to register if we have the info object
                InstallablePlugin insp = new InstallablePlugin(p);
-               //loadURLPlugins(ToLoad, false);
 
                if (duplicateLoadError) {
                        insp.uninstall();
@@ -721,108 +718,6 @@
 
        }
 
-       /**
-        * Parses the plugin input strings and transforms them into the 
appropriate
-        * URLs or resource names. The method first checks to see if the
-        */
-       public void loadPlugins(List<String> p) {
-               
-               Set<String> PluginsSeen = new HashSet<String>();
-
-               // Parse the plugin strings and determine whether they're urls,
-               // files, directories, class names, or manifest file names.
-               for (String currentPlugin : p) {
-                       try {
-                               if (PluginsSeen.contains(currentPlugin))
-                                       continue;
-
-                               if (currentPlugin.contains(".cytoscape")) {
-                                       logger.info(currentPlugin);
-                               }
-
-                               File f = new File(currentPlugin);
-
-                               // If the file name ends with .jar add it to 
the list as a url.
-                               if (currentPlugin.endsWith(".jar")) {
-                                       PluginsSeen.add(f.getAbsolutePath());
-
-                                       // If the name doesn't match a url, 
turn it into one.
-                                       if 
(!currentPlugin.matches(FileUtil.urlPattern)) {
-                                               logger.info(" - file: " + 
f.getAbsolutePath());
-                                               
pluginURLs.add(jarURL(f.getAbsolutePath()));
-                                       } else {
-                                               logger.info(" - url: " + 
f.getAbsolutePath());
-                                               
pluginURLs.add(jarURL(currentPlugin));
-                                       }
-                               } else if (!f.exists()) {
-                                       // If the file doesn't exists, assume
-                                       // that it's a resource plugin.
-                                       logger.info(" - classpath: " + 
currentPlugin);
-                                       resourcePlugins.add(currentPlugin);
-                               } else if (f.isDirectory()) {
-                                       // If the file is a directory, load
-                                       // all of the jars in the directory.
-                                       logger.info(" - directory: " + 
f.getAbsolutePath());
-
-                                       for (String fileName : f.list()) {
-                                               if (!fileName.endsWith(".jar")) 
{
-                                                       continue;
-                                               }
-                                               
PluginsSeen.add(f.getAbsolutePath()
-                                                               + 
System.getProperty("file.separator")
-                                                               + fileName);
-                                               
pluginURLs.add(jarURL(f.getAbsolutePath()
-                                                               + 
System.getProperty("file.separator")
-                                                               + fileName));
-                                       }
-                               } else {
-                                       // Assume the file is a manifest (i.e. 
list of jar names)
-                                       // and make urls out of them.
-                                       logger.info(" - file manifest: "
-                                                       + f.getAbsolutePath());
-
-                                       String text = 
FileUtil.getInputString(currentPlugin);
-
-                                       String[] allLines = text.split(System
-                                                       
.getProperty("line.separator"));
-                                       for (String pluginLoc : allLines) {
-                                               if (pluginLoc.endsWith(".jar")) 
{
-                                                       
PluginsSeen.add(pluginLoc);
-                                                       if 
(pluginLoc.matches(FileUtil.urlPattern)) {
-                                                               
pluginURLs.add(jarURL(pluginLoc));
-                                                       } else {
-                                                               // TODO this 
should have a better error
-                                                               // perhaps, 
throw an exception??
-                                                               
logger.warn("Plugin location specified in "
-                                                                               
                + currentPlugin
-                                                                               
                + " is not a valid url: "
-                                                                               
                + pluginLoc
-                                                                               
                + " -- NOT adding it.");
-                                                               
loadingErrors.add(new PluginException(
-                                                                               
"Plugin location specified in "
-                                                                               
                + currentPlugin
-                                                                               
                + " is not a valid url: "
-                                                                               
                + pluginLoc
-                                                                               
                + " -- NOT adding it."));
-                                                       }
-                                               }
-                                       }
-                               }
-                       // 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
-               loadURLPlugins(pluginURLs, true);
-               loadResourcePlugins(resourcePlugins);
-
-               cleanCurrentList();
-               if (duplicateLoadError)
-                       addDuplicateError();
-       }
-
        private void addDuplicateError() {
                String Msg = "The following plugins were not loaded due to 
duplicate class definitions:\n";
                for (String dup : duplicateClasses)
@@ -831,203 +726,6 @@
                loadingErrors.add(new DuplicatePluginClassException(Msg));
        }
 
-       /**
-        * Load all plugins by using the given URLs loading them all on one
-        * URLClassLoader, then interating through each Jar file looking for 
classes
-        * that are CytoscapePlugins
-        */
-       private void loadURLPlugins(List<URL> pluginUrls, boolean register) {
-               
-               
-               System.out.println("\nPluginManager.loadURLPlugins()....\n");
-               
-               
-               URL[] urls = new URL[pluginUrls.size()];
-               pluginUrls.toArray(urls);
-
-               duplicateClasses = new ArrayList<String>();
-               duplicateLoadError = false;
-
-               for (URL url : urls) {
-                       try {
-                               addClassPath(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));
-                       }
-               }
-
-               // the creation of the class loader automatically loads the 
plugins
-               classLoader = (URLClassLoader) 
ClassLoader.getSystemClassLoader();
-
-               // iterate through the given jar files and find classes that are
-               // assignable from CytoscapePlugin
-               for (int i = 0; i < urls.length; ++i) {
-                       
-               }
-               
-               /*      
-                       try {
-                               logger.info("attempting to load plugin url: 
"+urls[i]);
-
-                               JarURLConnection jc = (JarURLConnection) urls[i]
-                                               .openConnection();
-                               // Ensure we are reading the real content from 
urls[i],
-                               // and not some out-of-date cached content:
-                               jc.setUseCaches(false);
-                               JarFile jar = jc.getJarFile();
-
-                               // if the jar file is null, do nothing
-                               if (jar == null) {
-                                       continue;
-                               }
-
-                               // try to get class name from the manifest file
-                               String className = 
JarUtil.getPluginClass(jar.getName(),
-                                               PluginInfo.FileType.JAR);
-
-                               if (className != null) {
-                                       Class pc = getPluginClass(className);
-
-                                       if (pc != null) {
-                                               logger.info("Loading from 
manifest");
-                                               loadPlugin(pc, jar, register);
-                                               continue;
-                                       }
-                               }
-                       
-                               // new-school failed, so revert to old school. 
Search through
-                               // the jar entries
-                               Enumeration entries = jar.entries();
-
-                               if (entries == null) {
-                                       loadingErrors.add(new 
PluginException("Jar file "
-                                                       + jar.getName()
-                                                       + " has no entries, 
skipped loading."));
-                                       logger.warn("Jar file "
-                                                       + jar.getName()
-                                                       + " has no entries, 
skipped loading.");
-                                       continue;
-                               }
-
-                               int totalPlugins = 0;
-                               while (entries.hasMoreElements()) {
-                                       // get the entry
-                                       String entry = 
entries.nextElement().toString();
-
-                                       if (entry.endsWith("class")) {
-                                               // convert the entry to an 
assignable class name
-                                               entry = 
entry.replaceAll("\\.class$", "");
-                                               // A regex to match the two 
known types of file
-                                               // separators. We can't use 
File.separator because
-                                               // the system the jar was 
created on is not
-                                               // necessarily the same is the 
one it is running on.
-                                               entry = 
entry.replaceAll("/|\\\\", ".");
-
-                                               Class pc = 
getPluginClass(entry);
-                                               if (pc == null) {
-                                                       continue;
-                                               }
-                                               totalPlugins++;
-                                               loadPlugin(pc, jar, register);
-                                               break;
-                                       }
-                               }
-                               if (totalPlugins == 0) {
-                                       logger.info("No plugin found in 
specified jar - assuming it's a library.");
-                               }
-                       // 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));
-                       }
-               }
-               */
-       }
-
-       // these are jars that *may or may not* extend CytoscapePlugin but may 
be
-       // used by jars that do
-       private void loadResourcePlugins(List<String> resourcePlugins) {
-               // attempt to load resource plugins
-               for (String resource : resourcePlugins) {
-                       logger.info("attempting to load plugin resourse: " + 
resource);
-
-                       // try to get the class
-                       try {
-                               Class rclass = Class.forName(resource);
-                               loadPlugin(rclass, null, true);
-                       // 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));
-                       }
-               }
-       }
-
-       private void loadPlugin(Class plugin, JarFile jar, boolean register)
-                       throws PluginException {
-               if (CytoscapePlugin.class.isAssignableFrom(plugin)
-                               && !loadedPlugins.contains(plugin.getName())) {
-
-                       Object obj = CytoscapePlugin.loadPlugin(plugin);
-                       if (obj != null) {
-                               loadedPlugins.add(plugin.getName());
-                               if (register) {
-                                       register((CytoscapePlugin) obj, jar);
-                               }
-                       }
-
-               } else if (loadedPlugins.contains(plugin.getName())) {
-                       duplicateClasses.add(plugin.getName());
-                       duplicateLoadError = true;
-               }
-       }
-
-       /**
-        * Determines whether the class with a particular name extends
-        * CytoscapePlugin by attempting to load the class first.
-        * 
-        * @param name
-        *            the name of the putative plugin class
-        */
-       private Class getPluginClass(String name) throws ClassNotFoundException,
-                       NoClassDefFoundError {
-               Class c = classLoader.loadClass(name);
-               if (CytoscapePlugin.class.isAssignableFrom(c))
-                       return c;
-               else
-                       return null;
-       }
-
-       // creates a URL object from a jar file name
-       private static URL jarURL(String urlString) throws 
MalformedURLException {
-               String uString;
-               if (urlString.matches(FileUtil.urlPattern)) {
-                       uString = "jar:" + urlString + "!/";
-               } else {
-                       uString = "jar:file:" + urlString + "!/";
-               }
-               return new URL(uString);
-       }
-
-       /**
-        * This will be used to add plugin jars' URL to the System Loader's
-        * classpath.
-        * 
-        * @param url
-        * @throws NoSuchMethodException
-        * @throws IllegalAccessException
-        * @throws InvocationTargetException
-        */
-       private void addClassPath(URL url) throws NoSuchMethodException,
-                       IllegalAccessException, InvocationTargetException {
-               Method method = URLClassLoader.class.getDeclaredMethod("addURL",
-                               new Class[] { URL.class });
-               method.setAccessible(true);
-               method.invoke(ClassLoader.getSystemClassLoader(), new Object[] 
{ url });
-       }
-
        
        public void setCyPluginAdapter(CyPluginAdapter adapter){
                this.adapter = adapter;

Modified: 
core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
--- 
core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
  2011-01-25 05:15:18 UTC (rev 23595)
+++ 
core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context-osgi.xml
  2011-01-25 05:15:41 UTC (rev 23596)
@@ -52,6 +52,10 @@
                interface="org.cytoscape.session.CySessionManager">
        </osgi:reference>
 
+       <osgi:reference id="cySwingApplicationRef" 
+               interface="org.cytoscape.application.swing.CySwingApplication">
+       </osgi:reference>
+
        <osgi:reference id="presentationFactoryRef" 
                
interface="org.cytoscape.view.presentation.RenderingEngineFactory">
        </osgi:reference>

Modified: 
core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml   
    2011-01-25 05:15:18 UTC (rev 23595)
+++ 
core3/plugin-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml   
    2011-01-25 05:15:41 UTC (rev 23596)
@@ -29,6 +29,7 @@
                <constructor-arg ref="cyNetworkViewFactoryRef" />
                <constructor-arg ref="cyRootNetworkFactoryRef" />
                <constructor-arg ref="cySessionManagerRef" />
+               <constructor-arg ref="cySwingApplicationRef" />
                <constructor-arg ref="presentationFactoryRef" />
                <constructor-arg ref="taskManagerRef" />
                <constructor-arg ref="visualMappingManagerRef" />

Modified: 
core3/plugin-impl/trunk/src/test/java/org/cytoscape/plugin/internal/CyPluginAdapterImplTest.java
===================================================================
--- 
core3/plugin-impl/trunk/src/test/java/org/cytoscape/plugin/internal/CyPluginAdapterImplTest.java
    2011-01-25 05:15:18 UTC (rev 23595)
+++ 
core3/plugin-impl/trunk/src/test/java/org/cytoscape/plugin/internal/CyPluginAdapterImplTest.java
    2011-01-25 05:15:41 UTC (rev 23596)
@@ -7,6 +7,7 @@
 import org.cytoscape.model.subnetwork.CyRootNetworkFactory;
 import org.cytoscape.session.CyApplicationManager;
 import org.cytoscape.session.CySessionManager;
+import org.cytoscape.application.swing.CySwingApplication;
 //import org.cytoscape.view.layout.CyLayouts;
 import org.cytoscape.view.model.CyNetworkViewFactory;
 import org.cytoscape.view.model.CyNetworkViewManager;
@@ -31,6 +32,7 @@
                CyNetworkViewFactory cyNetworkViewFactory = 
mock(CyNetworkViewFactory.class);
                CyRootNetworkFactory cyRootNetworkFactory = 
mock(CyRootNetworkFactory.class);
                CySessionManager cySessionManager = 
mock(CySessionManager.class);
+               CySwingApplication cySwingApplication = 
mock(CySwingApplication.class);
                RenderingEngineFactory presentationFactory = 
mock(RenderingEngineFactory.class);
                TaskManager taskManager = mock(TaskManager.class);
                VisualMappingManager visualMappingManager = 
mock(VisualMappingManager.class);
@@ -46,6 +48,7 @@
                cyNetworkViewFactory,
                cyRootNetworkFactory,
                cySessionManager,
+               cySwingApplication,
                presentationFactory,
                taskManager,
                visualMappingManager,

-- 
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.

Reply via email to