Revision: 19189
          http://sourceforge.net/p/gate/code/19189
Author:   markagreenwood
Date:     2016-04-03 18:29:01 +0000 (Sun, 03 Apr 2016)
Log Message:
-----------
a few more things aren't as badly broken as they were earlier although it's 
still a bit of a mess

Modified Paths:
--------------
    gate/branches/sawdust2/src/main/gate/CreoleRegister.java
    gate/branches/sawdust2/src/main/gate/Gate.java
    gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
    
gate/branches/sawdust2/src/main/gate/gui/creole/manager/AvailablePlugins.java

Modified: gate/branches/sawdust2/src/main/gate/CreoleRegister.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/CreoleRegister.java    2016-04-03 
16:38:15 UTC (rev 19188)
+++ gate/branches/sawdust2/src/main/gate/CreoleRegister.java    2016-04-03 
18:29:01 UTC (rev 19189)
@@ -70,17 +70,20 @@
 public interface CreoleRegister extends Map<String, ResourceData>, 
Serializable, CreoleListener
 {
   /** Get the list of CREOLE directory URLs. */
+  @Deprecated
   public Set<URL> getDirectories();
+  
+  public List<Plugin> getPlugins();
 
   /**
    * Given the class object for a class with {@link CreoleResource}
-   * annotations, register that class is if it was found in a scanned jar
+   * annotations, register that class as is if it was found in a scanned jar
    * file with no additional creole.xml information.
    *
    * This API is intended for use in embedded GATE applications where
    * the 'application' is created via the API. Components registered with this
-   *  API won't work in saved applications, but they can be added
-   *  to saved applications at runtime.
+   * API won't work in saved applications, but they can be added
+   * to saved applications at runtime.
    *
    * @param clazz Class object for class with CreoleResource annotations.
    */
@@ -89,13 +92,14 @@
   /** Register a single CREOLE directory. The <CODE>creole.xml</CODE>
     * file at the URL is parsed, and <CODE>CreoleData</CODE> objects added
     * to the register. If the directory URL has not yet been added it
-    * is now added. If any other plugins that nees top be loaded for this
+    * is now added. If any other plugins that needs to be loaded for this
     * plugin to load (specified by <CODE>REQUIRES</Code> elements in
     * <code>creole.xml</code>) will also be loaded.
     */
+  @Deprecated
   public void registerDirectories(URL directoryUrl) throws GateException;
   
-  public void registerPlugin(Plugin plugin) throws Exception;
+  public void registerPlugin(Plugin plugin) throws GateException;
   
   /**
    * Register a single CREOLE directory. The <CODE>creole.xml</CODE> file at 
the
@@ -107,6 +111,7 @@
    * be able to ignore dependencies when loading an xgapp where we know they
    * have already been resolved.
    */
+  @Deprecated
   public void registerDirectories(URL directoryUrl, boolean loadDependencies)
       throws GateException;
 
@@ -114,7 +119,10 @@
    * Removes a CREOLE directory from the set of loaded directories.
    * @param directory
    */
+  @Deprecated
   public void removeDirectory(URL directory);
+  
+  public void unregisterPlugin(Plugin plugin);
 
   /** Register resources that are built in to the GATE distribution.
     * These resources are described by the <TT>creole.xml</TT> file in

Modified: gate/branches/sawdust2/src/main/gate/Gate.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/Gate.java      2016-04-03 16:38:15 UTC 
(rev 19188)
+++ gate/branches/sawdust2/src/main/gate/Gate.java      2016-04-03 18:29:01 UTC 
(rev 19189)
@@ -16,11 +16,9 @@
 
 package gate;
 
-import gate.Plugin.Directory;
 import gate.config.ConfigDataProcessor;
 import gate.creole.CreoleRegisterImpl;
 import gate.creole.ResourceData;
-import gate.creole.metadata.CreoleResource;
 import gate.event.CreoleListener;
 import gate.gui.creole.manager.PluginUpdateManager;
 import gate.util.Benchmark;
@@ -31,11 +29,6 @@
 import gate.util.LuckyException;
 import gate.util.OptionsMap;
 import gate.util.Strings;
-import gate.util.asm.AnnotationVisitor;
-import gate.util.asm.ClassReader;
-import gate.util.asm.ClassVisitor;
-import gate.util.asm.Opcodes;
-import gate.util.asm.Type;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -47,9 +40,7 @@
 import java.net.InetAddress;
 import java.net.MalformedURLException;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.URLClassLoader;
 import java.net.URLConnection;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
@@ -58,22 +49,12 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
 
 import org.apache.log4j.Logger;
-import org.jdom.Attribute;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
 
-import gate.util.asm.commons.EmptyVisitor;
-
 /**
  * The class is responsible for initialising the GATE libraries, and providing
  * access to singleton utility objects, such as the GATE class loader, CREOLE
@@ -98,15 +79,8 @@
    */
   public static final int HASH_STH_SIZE = 4;
 
-  /** The list of builtin URLs to search for CREOLE resources. */
-  private static String builtinCreoleDirectoryUrls[] = {
-  // "http://derwent.dcs.shef.ac.uk/gate.ac.uk/creole/";
+  
 
-    // this has been moved to initCreoleRegister and made relative to
-    // the base URL returned by getUrl()
-    // "http://gate.ac.uk/creole/";
-    };
-
   /** The GATE URI used to interpret custom GATE tags */
   public static final String URI = "http://www.gate.ac.uk";;
 
@@ -392,20 +366,20 @@
     // pluginsHome is now set by initLocalPaths
     // File pluginsHome = new File(System.getProperty(GATE_HOME_PROPERTY_NAME),
     // "plugins");
-    /*File[] dirs = pluginsHome.listFiles();
+    File[] dirs = pluginsHome.listFiles();
     for(int i = 0; i < dirs.length; i++) {
       File creoleFile = new File(dirs[i], "creole.xml");
       if(creoleFile.exists()) {
         try {
           URL pluginURL = dirs[i].toURI().toURL();
-          addKnownPlugin(pluginURL);
+          addKnownPlugin(new Plugin.Directory(pluginURL));
         }
         catch(MalformedURLException mue) {
           // this should never happen
           throw new GateRuntimeException(mue);
         }
       }
-    }*/
+    }
     
     // register plugins installed in the user plugin directory
     /*File userPluginsHome = PluginUpdateManager.getUserPluginsHome();
@@ -451,8 +425,7 @@
       try {
         Iterator<Plugin> loadPluginsIter = getAutoloadPlugins().iterator();
         while(loadPluginsIter.hasNext()) {
-          //TODO this looks like it will break
-          
getCreoleRegister().registerDirectories(loadPluginsIter.next().getBaseURL());
+          getCreoleRegister().registerPlugin(loadPluginsIter.next());
         }
       }
       catch(GateException ge) {
@@ -464,25 +437,12 @@
   /** Initialise the CREOLE register. */
   public static void initCreoleRegister() throws GateException {
 
-    // register the builtin CREOLE directories
-    for(int i = 0; i < builtinCreoleDirectoryUrls.length; i++)
-      try {
-        creoleRegister.registerDirectories(new 
URL(builtinCreoleDirectoryUrls[i]));
-      }
-      catch(MalformedURLException e) {
-        throw new GateException(e);
-      }
-
     /*
      * We'll have to think about this. Right now it points to the creole inside
      * the jar/classpath so it's the same as registerBuiltins
      */
-    // // add the GATE base URL creole directory
-    // creoleRegister.addDirectory(Gate.getUrl("creole/"));
-    // creoleRegister.registerDirectories();
-    // register the resources that are actually in gate.jar
     creoleRegister.registerBuiltins();
-  } // initCreoleRegister
+  }
 
   /** Initialise the DataStore register. */
   public static void initDataStoreRegister() {
@@ -1282,11 +1242,9 @@
   public static void removeKnownPlugin(Plugin plugin) {
     //pluginURL = normaliseCreoleUrl(pluginURL);
     knownPlugins.remove(plugin);
-    //autoloadPlugins.remove(pluginURL);
+    autoloadPlugins.remove(plugin);
     
-    //TODO make this work :)
-    //creoleRegister.removeDirectory(pluginURL);
-    //pluginData.remove(pluginURL);
+    creoleRegister.unregisterPlugin(plugin);    
   }
 
   /**
@@ -1297,260 +1255,11 @@
    * @param pluginURL
    *          the URL to be removed.
    */
-  public static void removeAutoloadPlugin(URL pluginURL) {
-    /*pluginURL = normaliseCreoleUrl(pluginURL);
-    autoloadPlugins.remove(pluginURL);*/
-    //TODO this needs to work again
+  public static void removeAutoloadPlugin(Plugin plugin) {
+    autoloadPlugins.remove(plugin);
   }
-
+  
   /**
-   * Stores information about the contents of a CREOLE directory.
-   */
-  /*public static class DirectoryInfo {
-    
-    private String name, html;
-    
-    private boolean core, remote;
-    
-    public boolean isCorePlugin() {
-      return core;
-    }
-    
-    public boolean isRemotePlugin() {
-      return remote;
-    }
-    
-    public boolean isUserPlugin() {
-      File userPluginsHome = PluginUpdateManager.getUserPluginsHome();
-      return (userPluginsHome != null
-              && getUrl().toString()
-                      .startsWith(userPluginsHome.toURI().toString()));
-    }
-    
-    public String toHTMLString() {
-      return html;
-    }
-    
-    public DirectoryInfo(URL url) {
-      this(url, null);
-    }
-    
-    public DirectoryInfo(URL url, org.jdom.Document creoleDoc) {
-      this.url = normaliseCreoleUrl(url);
-      valid = true;
-      resourceInfoList = new ArrayList<ResourceInfo>();
-      // this may invalidate it if something goes wrong
-      parseCreole(creoleDoc);
-
-      remote = !this.url.getProtocol().equalsIgnoreCase("file");
-      
-      if (Gate.isSandboxed() || Gate.getPluginsHome() == null) {
-        core = false;
-      }
-      else {
-        core = !remote && 
(url.toString().startsWith(Gate.getPluginsHome().toURI().toString()));
-      }
-
-      html =
-              "<html><body>"
-                      + getName()
-                      + "<br><span style='font-size: 80%;'>"
-                      + (remote ? this.url.toString() : Files.fileFromURL(
-                              this.url).getAbsolutePath())
-                      + "</span></body></html>";
-    }
-
-    public String getName() {
-      if(name != null) return name;
-
-      // url.getPath() works for jar URLs; url.toURI().getPath() doesn't
-      // because jars aren't considered "hierarchical"
-      name = url.getPath();
-      if(name.endsWith("/")) {
-        name = name.substring(0, name.length() - 1);
-      }
-      int lastSlash = name.lastIndexOf("/");
-      if(lastSlash != -1) {
-        name = name.substring(lastSlash + 1);
-      }
-      try {
-        // convert to (relative) URI and extract path.  This will
-        // decode any %20 escapes in the name.
-        name = new URI(name).getPath();
-      } catch(URISyntaxException ex) {
-        // ignore, this should have been checked when adding the URL!
-      }
-      return name;
-    }
-    
-    
-    protected void parseCreole(org.jdom.Document creoleDoc) {
-
-      try {
-        if (creoleDoc == null) {
-          SAXBuilder builder = new SAXBuilder(false);
-          URL creoleFileURL = new URL(url, "creole.xml");
-          creoleDoc = builder.build(creoleFileURL);
-        }
-
-        final Map<String, ResourceInfo> resInfos = new LinkedHashMap<String, 
ResourceInfo>();
-        List<Element> jobsList = new ArrayList<Element>();
-        List<String> jarsToScan = new ArrayList<String>();
-        List<String> allJars = new ArrayList<String>();
-        jobsList.add(creoleDoc.getRootElement());
-        while(!jobsList.isEmpty()) {
-          Element currentElem = jobsList.remove(0);
-          if(currentElem.getName().equalsIgnoreCase("JAR")) {
-            @SuppressWarnings("unchecked")
-            List<Attribute> attrs = currentElem.getAttributes();
-            Iterator<Attribute> attrsIt = attrs.iterator();
-            while(attrsIt.hasNext()) {
-              Attribute attr = attrsIt.next();
-              if(attr.getName().equalsIgnoreCase("SCAN") && 
attr.getBooleanValue()) {
-                jarsToScan.add(currentElem.getTextTrim());
-                break;
-              }
-            }
-            allJars.add(currentElem.getTextTrim());
-          }
-          else if(currentElem.getName().equalsIgnoreCase("RESOURCE")) {
-            // we don't go deeper than resources so no recursion here
-            String resName = currentElem.getChildTextTrim("NAME");
-            String resClass = currentElem.getChildTextTrim("CLASS");
-            String resComment = currentElem.getChildTextTrim("COMMENT");
-            if(!resInfos.containsKey(resClass)) {
-              // create the handler
-              ResourceInfo rHandler =
-                new ResourceInfo(resName, resClass, resComment);
-              resInfos.put(resClass, rHandler);
-            }
-          }
-          else {
-            // this is some higher level element -> simulate recursion
-            // we want Depth-first-search so we need to add at the beginning
-            @SuppressWarnings("unchecked")
-            List<Element> newJobsList = new 
ArrayList<Element>(currentElem.getChildren());
-            newJobsList.addAll(jobsList);
-            jobsList = newJobsList;
-          }
-        }
-
-        // now process the jar files with SCAN="true", looking for any extra
-        // CreoleResource annotated classes.
-        for(String jarFile : jarsToScan) {
-          URL jarUrl = new URL(url, jarFile);
-          scanJar(jarUrl, resInfos);
-        }
-
-        // see whether any of the ResourceInfo objects are still incomplete
-        // (don't have a name)
-        List<ResourceInfo> incompleteResInfos = new ArrayList<ResourceInfo>();
-        for(ResourceInfo ri : resInfos.values()) {
-          if(ri.getResourceName() == null) {
-            incompleteResInfos.add(ri);
-          }
-        }
-
-        if(!incompleteResInfos.isEmpty()) {
-          fillInResInfos(incompleteResInfos, allJars);
-        }
-
-        // if any of the resource infos still don't have a name, take it from
-        // the class name.
-        for(ResourceInfo ri : incompleteResInfos) {
-          if(ri.getResourceName() == null) {
-            ri.resourceName = ri.resourceClassName.substring(
-                    ri.resourceClassName.lastIndexOf('.') + 1);
-          }
-        }
-
-        // finally, we have the complete list of ResourceInfos
-        resourceInfoList.addAll(resInfos.values());
-      }
-      catch(IOException ioe) {
-        valid = false;
-        log.error("Problem while parsing plugin " + url.toExternalForm() + 
"!\n"
-          + ioe.toString() + "\nPlugin not available!");
-      }
-      catch(JDOMException jde) {
-        valid = false;
-        log.error("Problem while parsing plugin " + url.toExternalForm() + 
"!\n"
-          + jde.toString() + "\nPlugin not available!");
-      }
-    }
-
-    protected void scanJar(URL jarUrl, Map<String, ResourceInfo> resInfos) 
throws IOException {
-      JarInputStream jarInput = new JarInputStream(jarUrl.openStream(), false);
-      JarEntry entry = null;
-      while((entry = jarInput.getNextJarEntry()) != null) {
-        String entryName = entry.getName();
-        if(entryName != null && entryName.endsWith(".class")) {
-          final String className = entryName.substring(0,
-                   entryName.length() - 6).replace('/', '.');
-          if(!resInfos.containsKey(className)) {
-            ClassReader classReader = new ClassReader(jarInput);
-            ResourceInfo resInfo = new ResourceInfo(null, className, null);
-            ResourceInfoVisitor visitor = new ResourceInfoVisitor(resInfo);
-
-            classReader.accept(visitor, ClassReader.SKIP_CODE |
-                ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
-            if(visitor.isCreoleResource()) {
-              resInfos.put(className, resInfo);
-            }
-          }
-        }
-      }
-
-      jarInput.close();
-    }
-
-    protected void fillInResInfos(List<ResourceInfo> incompleteResInfos,
-              List<String> allJars) throws IOException {
-      // now create a temporary class loader with all the JARs (scanned or
-      // not), so we can look up all the referenced classes in the normal
-      // way and read their CreoleResource annotations (if any).
-      URL[] jarUrls = new URL[allJars.size()];
-      for(int i = 0; i < jarUrls.length; i++) {
-        jarUrls[i] = new URL(url, allJars.get(i));
-      }
-      ClassLoader tempClassLoader = new URLClassLoader(jarUrls,
-                Gate.class.getClassLoader());
-      for(ResourceInfo ri : incompleteResInfos) {
-        String classFile = ri.getResourceClassName().replace('.', '/')
-                + ".class";
-        InputStream classStream = 
tempClassLoader.getResourceAsStream(classFile);
-        if(classStream != null) {
-          ClassReader classReader = new ClassReader(classStream);
-          ClassVisitor visitor = new ResourceInfoVisitor(ri);
-          classReader.accept(visitor, ClassReader.SKIP_CODE |
-              ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
-          classStream.close();
-        }
-      }
-    }
-
-    public List<ResourceInfo> getResourceInfoList() {
-      return resourceInfoList;
-    }
-
-
-    public URL getUrl() {
-      return url;
-    }
-
-
-    public boolean isValid() {
-      return valid;
-    }
-
-    protected URL url;
-
-    protected boolean valid;
-
-    protected List<ResourceInfo> resourceInfoList;
-  }*/
-
-  /**
    * Stores information about a resource defined by a CREOLE directory. The
    * resource might not have been loaded in the system so not all information
    * normally provided by the {@link ResourceData} class is available. This is
@@ -1605,76 +1314,6 @@
   }
 
   /**
-   * ClassVisitor that uses information from a CreoleResource annotation on the
-   * visited class (if such exists) to fill in the name and comment in the
-   * corresponding ResourceInfo.
-   */
-  private static class ResourceInfoVisitor extends EmptyVisitor {
-    private ResourceInfo resInfo;
-
-    private boolean foundCreoleResource = false;
-
-    private boolean isAbstract = false;
-
-    public ResourceInfoVisitor(ResourceInfo resInfo) {
-      this.resInfo = resInfo;
-    }
-
-    public boolean isCreoleResource() {
-      return foundCreoleResource && !isAbstract;
-    }
-
-    /**
-     * Type descriptor for the CreoleResource annotation type.
-     */
-    private static final String CREOLE_RESOURCE_DESC =
-            Type.getDescriptor(CreoleResource.class);
-
-    /**
-     * Visit the class header, checking whether this is an abstract class or
-     * interface and setting the isAbstract flag appropriately.
-     */
-    @Override
-    public void visit(int version, int access, String name, String signature,
-            String superName, String[] interfaces) {
-      isAbstract = ((access &
-            (Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT)) != 0);
-    }
-
-    /**
-     * Visit an annotation on the class.
-     */
-    @Override
-    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
-      // we've found a CreoleResource annotation on this class
-      if(desc.equals(CREOLE_RESOURCE_DESC)) {
-        foundCreoleResource = true;
-        return new AnnotationVisitor(Opcodes.ASM5) {
-          @Override
-          public void visit(String name, Object value) {
-            if(name.equals("name") && resInfo.resourceName == null) {
-              resInfo.resourceName = (String)value;
-            }
-            else if(name.equals("comment") && resInfo.resourceComment == null) 
{
-              resInfo.resourceComment = (String)value;
-            }
-          }
-
-          @Override
-          public AnnotationVisitor visitAnnotation(String name,
-                    String desc) {
-            // don't want to recurse into AutoInstance annotations
-            return this;
-          }
-        };
-      }
-      else {
-        return super.visitAnnotation(desc, visible);
-      }
-    }
-  }
-
-  /**
    * The top level directory of the GATE installation.
    */
   protected static File gateHome;
@@ -1816,12 +1455,6 @@
   protected static List<Plugin> autoloadPlugins;
 
   /**
-   * Map from URL of directory to {@link DirectoryInfo}.
-   */
-  //protected static Map<URL, DirectoryInfo> pluginData;
-  //protected static Set<Plugin> pluginData;
-
-  /**
    * Flag for whether to use native serialization or xml serialization when
    * saving applications.
    */

Modified: gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java 
2016-04-03 16:38:15 UTC (rev 19188)
+++ gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java 
2016-04-03 18:29:01 UTC (rev 19189)
@@ -18,10 +18,7 @@
 
 import gate.Controller;
 import gate.CreoleRegister;
-import gate.Factory;
 import gate.Gate;
-import gate.Gate.ResourceInfo;
-import gate.Plugin.Directory;
 import gate.LanguageResource;
 import gate.Plugin;
 import gate.ProcessingResource;
@@ -39,8 +36,6 @@
 import gate.util.Out;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.AbstractList;
 import java.util.ArrayList;
@@ -58,17 +53,6 @@
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.log4j.Logger;
-import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
-import org.eclipse.aether.DefaultRepositorySystemSession;
-import org.eclipse.aether.RepositorySystem;
-import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
-import org.eclipse.aether.impl.DefaultServiceLocator;
-import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
-import org.eclipse.aether.spi.connector.transport.TransporterFactory;
-import org.eclipse.aether.transport.file.FileTransporterFactory;
-import org.eclipse.aether.transport.http.HttpTransporterFactory;
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
@@ -102,6 +86,8 @@
 
   /** The set of CREOLE directories (URLs). */
   protected Set<URL> directories;
+  
+  protected List<Plugin> plugins;
 
   /** The parser for the CREOLE directory files */
   protected transient SAXBuilder jdomBuilder = null;
@@ -129,6 +115,8 @@
     vrTypes = new LinkedList<String>();
     toolTypes = new HashSet<String>();
     applicationTypes = new HashSet<String>();
+    
+    plugins = new ArrayList<Plugin>();
 
     // construct a SAX parser for parsing the CREOLE directory files
     jdomBuilder = new SAXBuilder(false);
@@ -181,60 +169,34 @@
   @Override
   public Set<URL> getDirectories() {
     return Collections.unmodifiableSet(directories);
-  } // getDirectories
+  }
   
   @Override
-  public void registerPlugin(Plugin plugin) throws Exception {
-    //TODO narrow the excpetion list to GateException
+  public void registerPlugin(Plugin plugin) throws GateException {
     
-    //if (!directories.contains(directoryUrl)) {
-    Gate.addKnownPlugin(plugin);
+    if (!plugins.contains(plugin)) {
     
-    try {
-      parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(),
-        new URL(plugin.getBaseURL(),"creole.xml"), true);
-      log.info("CREOLE plugin loaded: " + plugin.getName());
-    }
-    catch(Throwable e) {
-      // it failed:
-      throw (new GateException("couldn't open creole.xml",e));
-    }
+      Gate.addKnownPlugin(plugin);
     
-    //directories.add(directoryUrl);
+      try {
+        parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(),
+          new URL(plugin.getBaseURL(),"creole.xml"), true);
+        log.info("CREOLE plugin loaded: " + plugin.getName());
+      }
+      catch(Throwable e) {
+        // it failed:
+        throw (new GateException("couldn't open creole.xml",e));
+      }
     
-    //firePluginLoaded(directoryUrl);
- // }
-  }
-  
-  public void registerPlugin(String group, String artifact, String version) 
throws Exception {
+      plugins.add(plugin);
     
-    Plugin plugin = new Plugin.Maven(group, artifact, version);
-    
-      //if (!directories.contains(directoryUrl)) {
-        Gate.addKnownPlugin(plugin);
-        
-        try {
-          parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(),
-            new URL(plugin.getBaseURL(),"creole.xml"), true);
-          log.info("CREOLE plugin loaded: " + plugin.getName());
-        }
-        catch(Throwable e) {
-          // it failed:
-          throw (new GateException("couldn't open creole.xml",e));
-        }
-        
-        //directories.add(directoryUrl);
-        
-        //firePluginLoaded(directoryUrl);
-     // }
-    
-    
+      firePluginLoaded(plugin);
+    }
   }
-  
-  //TODO put this back
 
   @Override
   public void registerComponent(Class<? extends Resource> resourceClass) 
throws GateException {
+    //TODO put this back
     /*URL creoleFileUrl = 
resourceClass.getResource("/gate/creole/CreoleRegisterImpl.class");
     Gate.addKnownPlugin(creoleFileUrl);
     Document doc = new Document();
@@ -271,115 +233,15 @@
   @Override
   public void registerDirectories(URL directoryUrl, boolean loadDependencies)
       throws GateException {
-    /*
- // directory URLs shouldn't include "creole.xml"
-    String urlName = directoryUrl.toExternalForm();
-    if(urlName.toLowerCase().endsWith("creole.xml")) { throw new GateException(
-      "CREOLE directory URLs should point to the parent location of "
-        + "the creole.xml file, not the file itself; bad URL was: " + 
urlName); }
-    // CREOLE URLs are directory URLs so they should end with "/"
-    String separator = "/";
-    if(!urlName.endsWith(separator)) {
-      urlName += separator;
-      try {
-        directoryUrl = new URL(urlName);
-      }
-      catch(MalformedURLException mue) {
-        throw new GateRuntimeException(mue);
-      }
-    }
-    // normalise to remove any /../ path components
+    
     try {
-      directoryUrl = new URL(directoryUrl, ".");
-      urlName = directoryUrl.toExternalForm();
+      Plugin plugin = new Plugin.Directory(directoryUrl);
+    
+      registerPlugin(plugin);
     }
-    catch(MalformedURLException mue) {
-      throw new GateRuntimeException(mue);
+    catch (Exception e) {
+      throw new GateException("Faailed to load plugin",e);
     }
-    // create a URL for the creole.xml file, based on the directory URL
-    URL directoryXmlFileUrl = directoryUrl;
-    try {
-      directoryXmlFileUrl = new URL(urlName + "creole.xml");
-    }
-    catch(MalformedURLException e) {
-      throw (new GateException("bad creole.xml URL, based on " + urlName));
-    }
-
-    // creole stream
-    InputStream creoleStream = null;
-
-    // lets check if it is an old plugin name
-    try {
-      creoleStream = directoryXmlFileUrl.openStream();
-    }
-    catch(IOException ioe) {
-
-      // if this happens
-      // locating last separator
-      int indexOfSeparator = urlName.lastIndexOf('/', urlName.length() - 2);
-
-      // plugin name
-      String pluginName =
-        urlName.substring(indexOfSeparator + 1, urlName.length() - 1);
-
-      if(pluginNamesMappings != null && 
pluginNamesMappings.containsKey(pluginName)) {
-        String newPluginName = pluginNamesMappings.get(pluginName);
-
-        urlName =
-          urlName.substring(0, indexOfSeparator + 1) + newPluginName + "/";
-
-        try {
-          log.warn("Trying to use new plugin name for " + pluginName);
-          directoryUrl = new URL(urlName);
-          directoryXmlFileUrl = new URL(directoryUrl, "creole.xml");
-          creoleStream = directoryXmlFileUrl.openStream();
-          log.warn("Please note that plugin names have changed. "
-            + "Please correct your application to rename " + pluginName
-            + " to " + newPluginName);
-        }
-        catch(IOException e) {
-          throw new GateException("couldn't open creole.xml: " + e.toString());
-        }
-      } else {
-        throw new GateException("couldn't find:" + directoryUrl);
-      }
-    }
-
-    // if already present do nothing
-    if(!directories.contains(directoryUrl)) {
-      // add it to the list of known directories
-      Gate.addKnownPlugin(directoryUrl);
-      
-      // parse the directory file
-      try {
-        parseDirectory(creoleStream, directoryUrl,
-          directoryXmlFileUrl, loadDependencies);
-        log.info("CREOLE plugin loaded: " + urlName);
-      }
-      catch(Throwable e) {
-        // it failed:
-        throw (new GateException("couldn't open creole.xml",e));
-      }
-      
-      directories.add(directoryUrl);
-      
-      firePluginLoaded(directoryUrl);
-    }*/
-    
-    Plugin plugin = new Plugin.Directory(directoryUrl);
-    
-    //if (!directories.contains(directoryUrl)) {
-      Gate.addKnownPlugin(plugin);
-      
-      try {
-        parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(),
-          new URL(plugin.getBaseURL(),"creole.xml"), true);
-        log.info("CREOLE plugin loaded: " + plugin.getName());
-      }
-      catch(Throwable e) {
-        // it failed:
-        throw (new GateException("couldn't open creole.xml",e));
-      }
   }
   
   /** Register a single CREOLE directory. The <CODE>creole.xml</CODE>
@@ -393,23 +255,6 @@
   public void registerDirectories(URL directoryUrl) throws GateException {
     registerDirectories(directoryUrl, true);    
   }
-
-  /*protected void parseDirectory(InputStream directoryStream, URL 
directoryUrl,
-    URL creoleFileUrl, boolean loadDependencies) throws GateException {
-    try {
-      Document jdomDoc =
-              jdomBuilder.build(directoryStream, 
creoleFileUrl.toExternalForm());
-      parseDirectory(jdomDoc, directoryUrl, creoleFileUrl, loadDependencies);
-    }
-    catch (IOException ioe) {
-      throw (new GateException(ioe));
-  }
-  catch(JDOMException je) {
-    if(DEBUG) je.printStackTrace(Err.getPrintWriter());
-    throw (new GateException(je));
-  }
-    
-  }*/
   
   /**
    * Parse a directory file (represented as an open stream), adding resource
@@ -585,7 +430,7 @@
   public void removeDirectory(URL directory) {
     int prCount = 0;
     
-    //TODO make this work again
+    //TODO make this work again, would it be easier to store plugins in a map 
from name to plugin to get easier access?
     /*
     if(directories.remove(directory)) {
       DirectoryInfo dInfo = Gate.getDirectoryInfo(directory);
@@ -1205,9 +1050,9 @@
   
   private transient List<PluginListener> pluginListeners = new 
CopyOnWriteArrayList<PluginListener>();
   
-  protected void firePluginLoaded(URL url) {
+  protected void firePluginLoaded(Plugin plugin) {
     for (PluginListener listener : pluginListeners) {
-      listener.pluginLoaded(url);
+      listener.pluginLoaded(plugin.getBaseURL());
     }
   }
   
@@ -1345,4 +1190,15 @@
     }
   }
 
+  @Override
+  public List<Plugin> getPlugins() {
+    return Collections.unmodifiableList(plugins);
+  }
+
+  @Override
+  public void unregisterPlugin(Plugin plugin) {
+    // TODO Auto-generated method stub
+    
+  }
+
 } // class CreoleRegisterImpl

Modified: 
gate/branches/sawdust2/src/main/gate/gui/creole/manager/AvailablePlugins.java
===================================================================
--- 
gate/branches/sawdust2/src/main/gate/gui/creole/manager/AvailablePlugins.java   
    2016-04-03 16:38:15 UTC (rev 19188)
+++ 
gate/branches/sawdust2/src/main/gate/gui/creole/manager/AvailablePlugins.java   
    2016-04-03 18:29:01 UTC (rev 19189)
@@ -605,7 +605,7 @@
       }
       if(!load && loaded) {
         // set autoload to false
-        Gate.removeAutoloadPlugin(aPluginURL.getBaseURL());
+        Gate.removeAutoloadPlugin(aPluginURL);
       }
     }
     

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785471&iu=/4140
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to