Revision: 19188
http://sourceforge.net/p/gate/code/19188
Author: markagreenwood
Date: 2016-04-03 16:38:15 +0000 (Sun, 03 Apr 2016)
Log Message:
-----------
well it compiles and loading things seems to work from the API but you can't
remove anything and the GUI is a mess
Modified Paths:
--------------
gate/branches/sawdust2/src/main/gate/CreoleRegister.java
gate/branches/sawdust2/src/main/gate/Factory.java
gate/branches/sawdust2/src/main/gate/Gate.java
gate/branches/sawdust2/src/main/gate/creole/AbstractProcessingResource.java
gate/branches/sawdust2/src/main/gate/creole/CreoleAnnotationHandler.java
gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
gate/branches/sawdust2/src/main/gate/gui/MainFrame.java
gate/branches/sawdust2/src/main/gate/gui/creole/manager/AvailablePlugins.java
gate/branches/sawdust2/src/main/gate/gui/creole/manager/PluginUpdateManager.java
gate/branches/sawdust2/src/main/gate/util/GateClassLoader.java
gate/branches/sawdust2/src/main/gate/util/ant/ExpandCreoleXmls.java
Added Paths:
-----------
gate/branches/sawdust2/src/main/gate/Plugin.java
Modified: gate/branches/sawdust2/src/main/gate/CreoleRegister.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/CreoleRegister.java 2016-04-03
08:56:16 UTC (rev 19187)
+++ gate/branches/sawdust2/src/main/gate/CreoleRegister.java 2016-04-03
16:38:15 UTC (rev 19188)
@@ -95,6 +95,8 @@
*/
public void registerDirectories(URL directoryUrl) throws GateException;
+ public void registerPlugin(Plugin plugin) throws Exception;
+
/**
* 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.
Modified: gate/branches/sawdust2/src/main/gate/Factory.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/Factory.java 2016-04-03 08:56:16 UTC
(rev 19187)
+++ gate/branches/sawdust2/src/main/gate/Factory.java 2016-04-03 16:38:15 UTC
(rev 19188)
@@ -16,7 +16,6 @@
package gate;
-import gate.Gate.DirectoryInfo;
import gate.annotation.ImmutableAnnotationSetImpl;
import gate.creole.AbstractProcessingResource;
import gate.creole.AbstractResource;
@@ -72,7 +71,7 @@
// get the resource metadata
ResourceData resData = Gate.getCreoleRegister().get(resourceClassName);
if(resData == null) {
- Set<DirectoryInfo> plugins = Gate.getDirectoryInfo(resourceClassName);
+ Set<Plugin> plugins = Gate.getPlugins(resourceClassName);
StringBuilder msg = new StringBuilder();
msg.append("Couldn't get resource data for ").append(resourceClassName)
@@ -89,7 +88,7 @@
} else {
msg.append(resourceClassName).append(
" can be found in the following plugins\n ");
- for(DirectoryInfo dInfo : plugins) {
+ for(Plugin dInfo : plugins) {
msg.append(dInfo.getName()).append(", ");
}
@@ -181,7 +180,7 @@
// get the resource metadata
ResourceData resData = Gate.getCreoleRegister().get(resourceClassName);
if(resData == null) {
- Set<DirectoryInfo> plugins = Gate.getDirectoryInfo(resourceClassName);
+ Set<Plugin> plugins = Gate.getPlugins(resourceClassName);
StringBuilder msg = new StringBuilder();
msg.append("Couldn't get resource data for ").append(resourceClassName)
@@ -198,7 +197,7 @@
} else {
msg.append(resourceClassName).append(
" can be found in the following plugins\n ");
- for(DirectoryInfo dInfo : plugins) {
+ for(Plugin dInfo : plugins) {
msg.append(dInfo.getName()).append(", ");
}
Modified: gate/branches/sawdust2/src/main/gate/Gate.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/Gate.java 2016-04-03 08:56:16 UTC
(rev 19187)
+++ gate/branches/sawdust2/src/main/gate/Gate.java 2016-04-03 16:38:15 UTC
(rev 19188)
@@ -16,6 +16,7 @@
package gate;
+import gate.Plugin.Directory;
import gate.config.ConfigDataProcessor;
import gate.creole.CreoleRegisterImpl;
import gate.creole.ResourceData;
@@ -70,6 +71,7 @@
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
+
import gate.util.asm.commons.EmptyVisitor;
/**
@@ -205,9 +207,9 @@
if(classLoader == null)
classLoader = new GateClassLoader("Top-Level GATE ClassLoader",
Gate.class.getClassLoader());
if(creoleRegister == null) creoleRegister = new CreoleRegisterImpl();
- if(knownPlugins == null) knownPlugins = new ArrayList<URL>();
- if(autoloadPlugins == null) autoloadPlugins = new ArrayList<URL>();
- if(pluginData == null) pluginData = new HashMap<URL, DirectoryInfo>();
+ if(knownPlugins == null) knownPlugins = new HashSet<Plugin>();
+ if(autoloadPlugins == null) autoloadPlugins = new ArrayList<Plugin>();
+ //if(pluginData == null) pluginData = new HashSet<Plugin>();
// init the creole register
initCreoleRegister();
// init the data store register
@@ -367,8 +369,10 @@
// get the list of loadable plugins
// load loadable plugins
+ //TODO reinstate this bit
+
// process the known plugins list
- String knownPluginsPath =
+ /*String knownPluginsPath =
(String)getUserConfig().get(KNOWN_PLUGIN_PATH_KEY);
if(knownPluginsPath != null && knownPluginsPath.length() > 0) {
StringTokenizer strTok =
@@ -383,12 +387,12 @@
log.error("Plugin error: " + aKnownPluginPath + " is an invalid
URL!");
}
}
- }
+ }*/
// add all the installed plugins
// 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()) {
@@ -401,10 +405,10 @@
throw new GateRuntimeException(mue);
}
}
- }
+ }*/
// register plugins installed in the user plugin directory
- File userPluginsHome = PluginUpdateManager.getUserPluginsHome();
+ /*File userPluginsHome = PluginUpdateManager.getUserPluginsHome();
if (userPluginsHome != null && userPluginsHome.isDirectory()) {
for (File dir : userPluginsHome.listFiles()) {
File creoleFile = new File(dir, "creole.xml");
@@ -419,7 +423,7 @@
}
}
}
- }
+ }*/
// process the autoload plugins
String pluginPath = getUserConfig().getString(AUTOLOAD_PLUGIN_PATH_KEY);
@@ -438,15 +442,17 @@
String aDir = strTok.nextToken();
try {
URL aPluginURL = new URL(aDir);
- addAutoloadPlugin(aPluginURL);
+ Plugin plugin = new Plugin.Directory(aPluginURL);
+ addAutoloadPlugin(plugin);
}
catch(MalformedURLException mue) {
log.error("Cannot load " + aDir + " CREOLE repository.",mue);
}
try {
- Iterator<URL> loadPluginsIter = getAutoloadPlugins().iterator();
+ Iterator<Plugin> loadPluginsIter = getAutoloadPlugins().iterator();
while(loadPluginsIter.hasNext()) {
- getCreoleRegister().registerDirectories(loadPluginsIter.next());
+ //TODO this looks like it will break
+
getCreoleRegister().registerDirectories(loadPluginsIter.next().getBaseURL());
}
}
catch(GateException ge) {
@@ -1017,8 +1023,10 @@
throw new GateRuntimeException("Unable to access user plugin
directory!", ioe);
}
+ //TODO need to reinstate this
+
// update the values for knownPluginPath
- String knownPluginPath = "";
+ /*String knownPluginPath = "";
Iterator<URL> pluginIter = getKnownPlugins().iterator();
while(pluginIter.hasNext()) {
URL aPluginURL = pluginIter.next();
@@ -1040,17 +1048,17 @@
if(knownPluginPath.length() > 0) knownPluginPath += ";";
knownPluginPath += aPluginURL.toExternalForm();
}
- getUserConfig().put(KNOWN_PLUGIN_PATH_KEY, knownPluginPath);
+ getUserConfig().put(KNOWN_PLUGIN_PATH_KEY, knownPluginPath);*/
// update the autoload plugin list
- String loadPluginPath = "";
+ /*String loadPluginPath = "";
pluginIter = getAutoloadPlugins().iterator();
while(pluginIter.hasNext()) {
URL aPluginURL = pluginIter.next();
if(loadPluginPath.length() > 0) loadPluginPath += ";";
loadPluginPath += aPluginURL.toExternalForm();
}
- getUserConfig().put(AUTOLOAD_PLUGIN_PATH_KEY, loadPluginPath);
+ getUserConfig().put(AUTOLOAD_PLUGIN_PATH_KEY, loadPluginPath);*/
// the user's config file
// String configFileName = getUserConfigFileName();
@@ -1142,7 +1150,7 @@
*
* @return a {@link List} of {@link URL}s.
*/
- public static List<URL> getKnownPlugins() {
+ public static Set<Plugin> getKnownPlugins() {
return knownPlugins;
}
@@ -1152,10 +1160,9 @@
* @param pluginURL
* the URL for the new plugin.
*/
- public static void addKnownPlugin(URL pluginURL) {
- pluginURL = normaliseCreoleUrl(pluginURL);
- if(knownPlugins.contains(pluginURL)) return;
- knownPlugins.add(pluginURL);
+ public static void addKnownPlugin(Plugin plugin) {
+ if(knownPlugins.contains(plugin)) return;
+ knownPlugins.add(plugin);
}
/**
@@ -1190,7 +1197,7 @@
*
* @return a {@link List} of {@link URL}s.
*/
- public static List<URL> getAutoloadPlugins() {
+ public static List<Plugin> getAutoloadPlugins() {
return autoloadPlugins;
}
@@ -1201,13 +1208,13 @@
* @param pluginUrl
* the URL for the new plugin.
*/
- public static void addAutoloadPlugin(URL pluginUrl) {
- pluginUrl = normaliseCreoleUrl(pluginUrl);
- if(autoloadPlugins.contains(pluginUrl)) return;
+ public static void addAutoloadPlugin(Plugin plugin) {
+
+ if(autoloadPlugins.contains(plugin)) return;
// make sure it's known
- addKnownPlugin(pluginUrl);
+ addKnownPlugin(plugin);
// add it to autoload list
- autoloadPlugins.add(pluginUrl);
+ autoloadPlugins.add(plugin);
}
/**
@@ -1217,7 +1224,7 @@
* the URL for the directory in question.
* @return a {@link DirectoryInfo} value.
*/
- public static DirectoryInfo getDirectoryInfo(URL directory) {
+ /*public static DirectoryInfo getDirectoryInfo(URL directory) {
directory = normaliseCreoleUrl(directory);
if(!knownPlugins.contains(directory)) return null;
DirectoryInfo dInfo = pluginData.get(directory);
@@ -1226,9 +1233,9 @@
pluginData.put(directory, dInfo);
}
return dInfo;
- }
+ }*/
- public static DirectoryInfo getDirectoryInfo(URL directory,
org.jdom.Document creoleDoc) {
+ /*public static DirectoryInfo getDirectoryInfo(URL directory,
org.jdom.Document creoleDoc) {
directory = normaliseCreoleUrl(directory);
if(!knownPlugins.contains(directory)) return null;
DirectoryInfo dInfo = pluginData.get(directory);
@@ -1237,7 +1244,7 @@
pluginData.put(directory, dInfo);
}
return dInfo;
- }
+ }*/
/**
* Returns information about plugin directories which provide the requested
@@ -1248,15 +1255,15 @@
* @return information about the directories which provide an implementation
* of the requested resource
*/
- public static Set<DirectoryInfo> getDirectoryInfo(String resourceClassName) {
- Set<DirectoryInfo> dirs = new HashSet<DirectoryInfo>();
+ public static Set<Plugin> getPlugins(String resourceClassName) {
+ Set<Plugin> dirs = new HashSet<Plugin>();
- for (URL url : knownPlugins) {
- DirectoryInfo dInfo = getDirectoryInfo(url);
+ for (Plugin plugin: knownPlugins) {
- for (ResourceInfo rInfo : dInfo.getResourceInfoList()) {
+
+ for (ResourceInfo rInfo : plugin.getResourceInfoList()) {
if (rInfo.resourceClassName.equals(resourceClassName)) {
- dirs.add(dInfo);
+ dirs.add(plugin);
}
}
}
@@ -1272,12 +1279,14 @@
*
* @param pluginURL
*/
- public static void removeKnownPlugin(URL pluginURL) {
- pluginURL = normaliseCreoleUrl(pluginURL);
- knownPlugins.remove(pluginURL);
- autoloadPlugins.remove(pluginURL);
- creoleRegister.removeDirectory(pluginURL);
- pluginData.remove(pluginURL);
+ public static void removeKnownPlugin(Plugin plugin) {
+ //pluginURL = normaliseCreoleUrl(pluginURL);
+ knownPlugins.remove(plugin);
+ //autoloadPlugins.remove(pluginURL);
+
+ //TODO make this work :)
+ //creoleRegister.removeDirectory(pluginURL);
+ //pluginData.remove(pluginURL);
}
/**
@@ -1289,14 +1298,15 @@
* the URL to be removed.
*/
public static void removeAutoloadPlugin(URL pluginURL) {
- pluginURL = normaliseCreoleUrl(pluginURL);
- autoloadPlugins.remove(pluginURL);
+ /*pluginURL = normaliseCreoleUrl(pluginURL);
+ autoloadPlugins.remove(pluginURL);*/
+ //TODO this needs to work again
}
/**
* Stores information about the contents of a CREOLE directory.
*/
- public static class DirectoryInfo {
+ /*public static class DirectoryInfo {
private String name, html;
@@ -1373,10 +1383,7 @@
return name;
}
- /**
- * Performs a shallow parse of the creole.xml file to get the information
- * about the resources contained.
- */
+
protected void parseCreole(org.jdom.Document creoleDoc) {
try {
@@ -1522,43 +1529,26 @@
}
}
- /**
- * @return Returns the resourceInfoList.
- */
public List<ResourceInfo> getResourceInfoList() {
return resourceInfoList;
}
- /**
- * @return Returns the url.
- */
+
public URL getUrl() {
return url;
}
- /**
- * @return Returns the valid.
- */
+
public boolean isValid() {
return valid;
}
- /**
- * The URL for the CREOLE directory.
- */
protected URL url;
- /**
- * Is the directory valid (i.e. is the location reachable and the
creole.xml
- * file parsable).
- */
protected boolean valid;
- /**
- * The list of {@link Gate.ResourceInfo} objects.
- */
protected List<ResourceInfo> resourceInfoList;
- }
+ }*/
/**
* Stores information about a resource defined by a CREOLE directory. The
@@ -1572,6 +1562,10 @@
this.resourceName = name;
this.resourceComment = comment;
}
+
+ public String toString() {
+ return resourceName+" ("+resourceClassName+")";
+ }
/**
* @return Returns the resourceClassName.
@@ -1813,18 +1807,19 @@
* The list of plugins (aka CREOLE directories) the system knows about. This
* list contains URL objects.
*/
- private static List<URL> knownPlugins;
+ private static Set<Plugin> knownPlugins;
/**
* The list of plugins (aka CREOLE directories) the system loads
automatically
* at start-up. This list contains URL objects.
*/
- protected static List<URL> autoloadPlugins;
+ protected static List<Plugin> autoloadPlugins;
/**
* Map from URL of directory to {@link DirectoryInfo}.
*/
- protected static Map<URL, DirectoryInfo> pluginData;
+ //protected static Map<URL, DirectoryInfo> pluginData;
+ //protected static Set<Plugin> pluginData;
/**
* Flag for whether to use native serialization or xml serialization when
Added: gate/branches/sawdust2/src/main/gate/Plugin.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/Plugin.java
(rev 0)
+++ gate/branches/sawdust2/src/main/gate/Plugin.java 2016-04-03 16:38:15 UTC
(rev 19188)
@@ -0,0 +1,525 @@
+package gate;
+
+import gate.Gate.ResourceInfo;
+import gate.creole.metadata.CreoleResource;
+import gate.gui.MainFrame;
+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 gate.util.asm.commons.EmptyVisitor;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import javax.swing.SwingUtilities;
+
+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.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.collection.CollectRequest;
+import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyNode;
+import org.eclipse.aether.impl.DefaultServiceLocator;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
+import org.eclipse.aether.resolution.DependencyRequest;
+import org.eclipse.aether.resolution.DependencyResult;
+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.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+
+public abstract class Plugin {
+
+ protected static final Logger log = Logger.getLogger(Plugin.class);
+
+ /**
+ * Is the plugin valid (i.e. is the location reachable and the
+ * creole.xml file parsable).
+ */
+ protected boolean valid;
+
+ protected URL baseURL;
+
+ protected String name;
+
+ /**
+ * The list of {@link Gate.ResourceInfo} objects.
+ */
+ protected List<ResourceInfo> resourceInfoList = null;
+
+ protected List<Plugin> requiredPlugins = null;
+
+ public abstract org.jdom.Document getCreoleXML() throws Exception,
+ JDOMException;
+
+ public abstract String getName();
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((baseURL == null) ? 0 : baseURL.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(getClass() != obj.getClass()) return false;
+ Plugin other = (Plugin)obj;
+ if(baseURL == null) {
+ if(other.baseURL != null) return false;
+ } else if(!baseURL.equals(other.baseURL)) return false;
+ return true;
+ }
+
+ public List<ResourceInfo> getResourceInfoList() {
+ if (resourceInfoList == null) parseCreole();
+
+ return resourceInfoList;
+ }
+
+ public URL getBaseURL() {
+ return baseURL;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ protected void parseCreole() {
+
+ resourceInfoList = new ArrayList<ResourceInfo>();
+
+ try {
+ org.jdom.Document creoleDoc = getCreoleXML();
+
+ XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
+ xmlOut.output(creoleDoc, System.out);
+
+ 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 if(currentElem.getName().equalsIgnoreCase("REQUIRES")) {
+ System.out.println("REQUIRES: " + currentElem.getTextTrim());
+ }
+ 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(baseURL, 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 " + toString() + "!\n"
+ + ioe.toString() + "\nPlugin not available!");
+ }
+ catch(JDOMException jde) {
+ valid = false;
+ log.error("Problem while parsing plugin " + toString() + "!\n"
+ + jde.toString() + "\nPlugin not available!");
+ }
+ catch(Exception e) {
+ valid = false;
+ log.error("Problem while parsing plugin " + toString() + "!\n"
+ + e.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(baseURL, allJars.get(i));
+ }
+
+ //TODO shouldn't we use a proper temp gate class loader which we can then
throw away?
+ 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 static class Directory extends Plugin {
+
+ public Directory(URL directoryURL) {
+ baseURL = Gate.normaliseCreoleUrl(directoryURL);
+ }
+
+ @Override
+ public Document getCreoleXML() throws Exception {
+ SAXBuilder builder = new SAXBuilder(false);
+ URL creoleFileURL = new URL(baseURL, "creole.xml");
+ return builder.build(creoleFileURL);
+ }
+
+ @Override
+ 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 = baseURL.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;
+ }
+ }
+
+ public static class Maven extends Plugin {
+ // TODO needs a better name that isn't tied to using Maven but talks
+ // more about dependency resolution
+
+ private String group, artifact, version;
+
+ public Maven(String group, String artifact, String version) {
+ this.group = group;
+ this.artifact = artifact;
+ this.version = version;
+ }
+
+
+
+ @Override
+ public Document getCreoleXML() throws Exception {
+ Artifact artifactObj =
+ new DefaultArtifact(group, artifact, "jar", version);
+
+ Dependency dependency = new Dependency(artifactObj, "all");
+ RemoteRepository central =
+ new RemoteRepository.Builder("central", "default",
+ "http://repo1.maven.org/maven2/").build();
+
+ ArtifactRequest artifactRequest = new ArtifactRequest();
+ artifactRequest.setArtifact(artifactObj);
+ artifactRequest.addRepository(central);
+
+ ArtifactResult artifactResult =
+ getRepositorySystem().resolveArtifact(getRepositorySession(),
+ artifactRequest);
+
+ System.out.println(artifactResult.getArtifact().getFile());
+
+ baseURL =
+ new URL("jar:"
+ + artifactResult.getArtifact().getFile().toURI().toURL()
+ + "!/");
+ System.out.println(baseURL);
+
+ // check it has a creole.xml at the root
+ URL directoryXmlFileUrl = new URL(baseURL, "creole.xml");
+ System.out.println(directoryXmlFileUrl);
+
+ InputStream creoleStream = null;
+
+ try {
+ creoleStream = directoryXmlFileUrl.openStream();
+ } catch(IOException ioe) {
+ throw new IOException(directoryXmlFileUrl.toExternalForm()
+ + " does not exist so this artifact is not a GATE plugin");
+ }
+
+ CollectRequest collectRequest = new CollectRequest();
+ collectRequest.setRoot(dependency);
+ collectRequest.addRepository(central);
+ DependencyNode node =
+ getRepositorySystem().collectDependencies(getRepositorySession(),
+ collectRequest).getRoot();
+
+ DependencyRequest dependencyRequest = new DependencyRequest();
+ dependencyRequest.setRoot(node);
+
+ DependencyResult result =
+ repoSystem.resolveDependencies(getRepositorySession(),
+ dependencyRequest);
+
+ // get the creole.xml out of the jar and add jar elements for this
+ // jar (marked for scanning) and the dependencies
+ SAXBuilder builder = new SAXBuilder(false);
+ Document jdomDoc =
+ builder.build(creoleStream,
directoryXmlFileUrl.toExternalForm());
+
+ Element creoleRoot = jdomDoc.getRootElement();
+
+ for(ArtifactResult ar : result.getArtifactResults()) {
+ Element jarElement = new Element("JAR");
+ jarElement.setText(ar.getArtifact().getFile().toURI().toURL()
+ .toExternalForm());
+
+ if(ar.getArtifact().equals(artifactResult.getArtifact())) {
+ jarElement.setAttribute("SCAN", "true");
+ }
+
+ creoleRoot.addContent(jarElement);
+ }
+
+ return jdomDoc;
+ }
+
+ private static RepositorySystem repoSystem = null;
+
+ private static DefaultRepositorySystemSession repoSystemSession = null;
+
+ private static RepositorySystem getRepositorySystem() {
+ if(repoSystem != null) return repoSystem;
+
+ DefaultServiceLocator locator =
+ MavenRepositorySystemUtils.newServiceLocator();
+ locator.addService(RepositoryConnectorFactory.class,
+ BasicRepositoryConnectorFactory.class);
+ locator.addService(TransporterFactory.class,
FileTransporterFactory.class);
+ locator.addService(TransporterFactory.class,
HttpTransporterFactory.class);
+
+ repoSystem = locator.getService(RepositorySystem.class);
+
+ return repoSystem;
+ }
+
+ private static RepositorySystemSession getRepositorySession() {
+ if(repoSystemSession != null) return repoSystemSession;
+
+ repoSystemSession = MavenRepositorySystemUtils.newSession();
+
+ // LocalRepository localRepo = new
+ // LocalRepository("target/local-repo");
+ LocalRepository localRepo =
+ new LocalRepository("/home/mark/.m2/repository/");
+ repoSystemSession.setLocalRepositoryManager(getRepositorySystem()
+ .newLocalRepositoryManager(repoSystemSession, localRepo));
+
+ return repoSystemSession;
+ }
+
+ @Override
+ public String getName() {
+ return group+":"+artifact+":"+version;
+ }
+ }
+
+ /**
+ * 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);
+ }
+ }
+ }
+
+ public static void main(String args[]) throws Exception {
+ Gate.runInSandbox(true);
+ Gate.init();
+
+
+ Plugin annieDir = new Plugin.Directory(new
File("/home/mark/gate-top/externals/gate-ix/plugins/ANNIE").toURI().toURL());
+ System.out.println(annieDir.getResourceInfoList());
+
+ Plugin annieMaven = new Plugin.Maven("uk.ac.gate", "ANNIE", "9");
+ System.out.println(annieMaven.getResourceInfoList());
+ }
+}
Modified:
gate/branches/sawdust2/src/main/gate/creole/AbstractProcessingResource.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/creole/AbstractProcessingResource.java
2016-04-03 08:56:16 UTC (rev 19187)
+++ gate/branches/sawdust2/src/main/gate/creole/AbstractProcessingResource.java
2016-04-03 16:38:15 UTC (rev 19188)
@@ -238,7 +238,7 @@
protected class InternalStatusListener implements StatusListener{
public InternalStatusListener() {
- // TODO Auto-generated constructor stub
+
}
@Override
Modified:
gate/branches/sawdust2/src/main/gate/creole/CreoleAnnotationHandler.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/creole/CreoleAnnotationHandler.java
2016-04-03 08:56:16 UTC (rev 19187)
+++ gate/branches/sawdust2/src/main/gate/creole/CreoleAnnotationHandler.java
2016-04-03 16:38:15 UTC (rev 19188)
@@ -17,8 +17,8 @@
package gate.creole;
import gate.Gate;
-import gate.Gate.DirectoryInfo;
import gate.Gate.ResourceInfo;
+import gate.Plugin;
import gate.Resource;
import gate.creole.metadata.AutoInstance;
import gate.creole.metadata.AutoInstanceParam;
@@ -70,7 +70,8 @@
private static final Logger log = Logger
.getLogger(CreoleAnnotationHandler.class);
- private URL creoleFileUrl;
+ //private URL creoleFileUrl;
+ private Plugin plugin;
/**
* Create an annotation handler for the given creole.xml file.
@@ -78,8 +79,9 @@
* @param creoleFileUrl
* location of the creole.xml file.
*/
- public CreoleAnnotationHandler(URL creoleFileUrl) {
- this.creoleFileUrl = creoleFileUrl;
+ public CreoleAnnotationHandler(Plugin plugin) {
+ //this.creoleFileUrl = creoleFileUrl;
+ this.plugin = plugin;
}
/**
@@ -118,7 +120,7 @@
String urlString = required.getTextTrim();
if(urlString.startsWith(relativePathMarker)) {
url =
- new URL(creoleFileUrl, urlString.substring(relativePathMarker
+ new URL(plugin.getBaseURL(),
urlString.substring(relativePathMarker
.length()));
} else if(urlString.startsWith(gatehomePathMarker)) {
URL gatehome = Gate.getGateHome().toURI().toURL();
@@ -131,7 +133,7 @@
new URL(gateplugins, urlString.substring(gatepluginsPathMarker
.length()));
} else {
- url = new URL(creoleFileUrl, urlString);
+ url = new URL(plugin.getBaseURL(), urlString);
}
Gate.getCreoleRegister().registerDirectories(url);
@@ -164,7 +166,7 @@
resolveOptions.setLog(LogOptions.LOG_QUIET);
for(Element e : ivyElts) {
- URL url = new URL(creoleFileUrl, ExpandIvy.getIvyPath(e));
+ URL url = new URL(plugin.getBaseURL(), ExpandIvy.getIvyPath(e));
ResolveReport report = ivy.resolve(url, resolveOptions);
if(report.getAllProblemMessages().size() > 0)
@@ -192,7 +194,7 @@
private void addJarsToClassLoader(GateClassLoader gcl, Element jdomElt)
throws MalformedURLException {
if("JAR".equals(jdomElt.getName())) {
- URL url = new URL(creoleFileUrl, jdomElt.getTextTrim());
+ URL url = new URL(plugin.getBaseURL(), jdomElt.getTextTrim());
try {
java.io.InputStream s = url.openStream();
s.close();
@@ -201,7 +203,6 @@
log.debug("Unable to add JAR "
+ url
+ " specified in creole file "
- + creoleFileUrl
+ " to class loader, hopefully the required classes are already on
the classpath.");
}
} else {
@@ -223,12 +224,12 @@
public void createResourceElementsForDirInfo(Document jdomDoc)
throws MalformedURLException {
Element jdomElt = jdomDoc.getRootElement();
- URL directoryUrl = new URL(creoleFileUrl, ".");
- DirectoryInfo dirInfo = Gate.getDirectoryInfo(directoryUrl,jdomDoc);
- if(dirInfo != null) {
+ //URL directoryUrl = new URL(creoleFileUrl, ".");
+ //DirectoryInfo dirInfo = Gate.getDirectoryInfo(directoryUrl,jdomDoc);
+ //if(dirInfo != null) {
Map<String, Element> resourceElements = new HashMap<String, Element>();
findResourceElements(resourceElements, jdomElt);
- for(ResourceInfo resInfo : dirInfo
+ for(ResourceInfo resInfo : plugin
.getResourceInfoList()) {
if(!resourceElements.containsKey(resInfo.getResourceClassName())) {
// no existing RESOURCE element for this resource type (so it
@@ -240,7 +241,7 @@
"CLASS").setText(resInfo.getResourceClassName())));
}
}
- }
+ //}
}
@@ -299,15 +300,15 @@
throws GateException {
String className = element.getChildTextTrim("CLASS");
if(className == null) { throw new GateException(
- "\"CLASS\" element not found for resource in " + creoleFileUrl); }
+ "\"CLASS\" element not found for resource in " + plugin); }
Class<?> resourceClass = null;
try {
resourceClass = Gate.getClassLoader().loadClass(className);
} catch(ClassNotFoundException e) {
log.debug("Couldn't load class " + className + " for resource in "
- + creoleFileUrl, e);
+ + plugin, e);
throw new GateException("Couldn't load class " + className
- + " for resource in " + creoleFileUrl);
+ + " for resource in " + plugin);
}
processCreoleResourceAnnotations(element, resourceClass);
Modified: gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
2016-04-03 08:56:16 UTC (rev 19187)
+++ gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
2016-04-03 16:38:15 UTC (rev 19188)
@@ -20,9 +20,10 @@
import gate.CreoleRegister;
import gate.Factory;
import gate.Gate;
-import gate.Gate.DirectoryInfo;
import gate.Gate.ResourceInfo;
+import gate.Plugin.Directory;
import gate.LanguageResource;
+import gate.Plugin;
import gate.ProcessingResource;
import gate.Resource;
import gate.VisualResource;
@@ -61,19 +62,9 @@
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
-import org.eclipse.aether.artifact.Artifact;
-import org.eclipse.aether.artifact.DefaultArtifact;
-import org.eclipse.aether.collection.CollectRequest;
import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
-import org.eclipse.aether.graph.Dependency;
-import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.impl.DefaultServiceLocator;
import org.eclipse.aether.repository.LocalRepository;
-import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.resolution.ArtifactRequest;
-import org.eclipse.aether.resolution.ArtifactResult;
-import org.eclipse.aether.resolution.DependencyRequest;
-import org.eclipse.aether.resolution.DependencyResult;
import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
import org.eclipse.aether.transport.file.FileTransporterFactory;
@@ -192,128 +183,59 @@
return Collections.unmodifiableSet(directories);
} // getDirectories
- public void registerPlugin(String group, String artifact, String version)
throws Exception {
- // get the jar file for the coordinates (not dependencies yet)
- Artifact artifactObj = new DefaultArtifact(group,artifact,"jar",version );
+ @Override
+ public void registerPlugin(Plugin plugin) throws Exception {
+ //TODO narrow the excpetion list to GateException
- Dependency dependency =
- new Dependency(artifactObj , "all" );
- RemoteRepository central = new RemoteRepository.Builder( "central",
"default", "http://repo1.maven.org/maven2/" ).build();
-
- ArtifactRequest artifactRequest = new ArtifactRequest();
- artifactRequest.setArtifact(artifactObj);
- artifactRequest.addRepository(central);
+ //if (!directories.contains(directoryUrl)) {
+ Gate.addKnownPlugin(plugin);
- ArtifactResult artifactResult =
getRepositorySystem().resolveArtifact(getRepositorySession(), artifactRequest);
-
- System.out.println(artifactResult.getArtifact().getFile());
-
- URL directoryUrl = new
URL("jar:"+artifactResult.getArtifact().getFile().toURI().toURL()+"!/");
- System.out.println(directoryUrl);
-
-
- // check it has a creole.xml at the root
- URL directoryXmlFileUrl = new URL(directoryUrl,"creole.xml");
- System.out.println(directoryXmlFileUrl);
-
- InputStream creoleStream = null;
-
try {
- creoleStream = directoryXmlFileUrl.openStream();
+ parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(),
+ new URL(plugin.getBaseURL(),"creole.xml"), true);
+ log.info("CREOLE plugin loaded: " + plugin.getName());
}
- catch(IOException ioe) {
- throw new IOException(directoryXmlFileUrl.toExternalForm() + " does not
exist so this artifact is not a GATE plugin");
- }
+ catch(Throwable e) {
+ // it failed:
+ throw (new GateException("couldn't open creole.xml",e));
+ }
- CollectRequest collectRequest = new CollectRequest();
- collectRequest.setRoot( dependency );
- collectRequest.addRepository( central );
- DependencyNode node = getRepositorySystem().collectDependencies(
getRepositorySession(), collectRequest ).getRoot();
-
- DependencyRequest dependencyRequest = new DependencyRequest();
- dependencyRequest.setRoot( node );
-
- DependencyResult result = repoSystem.resolveDependencies(
getRepositorySession(), dependencyRequest );
+ //directories.add(directoryUrl);
- // get the creole.xml out of the jar and add jar elements for this
- // jar (marked for scanning) and the dependencies
+ //firePluginLoaded(directoryUrl);
+ // }
+ }
+
+ public void registerPlugin(String group, String artifact, String version)
throws Exception {
- Document jdomDoc =
- jdomBuilder.build(creoleStream,
directoryXmlFileUrl.toExternalForm());
+ Plugin plugin = new Plugin.Maven(group, artifact, version);
- Element creoleRoot = jdomDoc.getRootElement();
-
- for (ArtifactResult ar : result.getArtifactResults()) {
- Element jarElement = new Element("JAR");
-
jarElement.setText(ar.getArtifact().getFile().toURI().toURL().toExternalForm());
-
- if (ar.getArtifact().equals(artifactResult.getArtifact())) {
- jarElement.setAttribute("SCAN", "true");
- }
-
- creoleRoot.addContent(jarElement);
- }
-
- XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
- xmlOut.output(jdomDoc, System.out);
-
- // fingers crossed processing then continues as for any other plugin
- if (!directories.contains(directoryUrl)) {
- Gate.addKnownPlugin(directoryUrl);
+ //if (!directories.contains(directoryUrl)) {
+ Gate.addKnownPlugin(plugin);
try {
- parseDirectory(jdomDoc, directoryUrl,
- directoryXmlFileUrl, true);
- log.info("CREOLE plugin loaded: " + directoryUrl);
+ 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);
+ //directories.add(directoryUrl);
- firePluginLoaded(directoryUrl);
- }
+ //firePluginLoaded(directoryUrl);
+ // }
}
- private static RepositorySystem repoSystem = null;
-
- private static DefaultRepositorySystemSession repoSystemSession = null;
-
- private static RepositorySystem getRepositorySystem() {
- if(repoSystem != null) return repoSystem;
+ //TODO put this back
- DefaultServiceLocator locator =
- MavenRepositorySystemUtils.newServiceLocator();
- locator.addService(RepositoryConnectorFactory.class,
- BasicRepositoryConnectorFactory.class);
- locator.addService(TransporterFactory.class, FileTransporterFactory.class);
- locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
-
- repoSystem = locator.getService(RepositorySystem.class);
-
- return repoSystem;
- }
-
- private static RepositorySystemSession getRepositorySession() {
- if(repoSystemSession != null) return repoSystemSession;
-
- repoSystemSession = MavenRepositorySystemUtils.newSession();
-
- //LocalRepository localRepo = new LocalRepository("target/local-repo");
- LocalRepository localRepo = new
LocalRepository("/home/mark/.m2/repository/");
- repoSystemSession.setLocalRepositoryManager(getRepositorySystem()
- .newLocalRepositoryManager(repoSystemSession, localRepo));
-
- return repoSystemSession;
- }
-
@Override
public void registerComponent(Class<? extends Resource> resourceClass)
throws GateException {
- URL creoleFileUrl =
resourceClass.getResource("/gate/creole/CreoleRegisterImpl.class");
+ /*URL creoleFileUrl =
resourceClass.getResource("/gate/creole/CreoleRegisterImpl.class");
Gate.addKnownPlugin(creoleFileUrl);
Document doc = new Document();
Element element;
@@ -333,7 +255,7 @@
}
catch(JDOMException e) {
throw new GateException(e);
- }
+ }*/
}
/**
@@ -349,7 +271,7 @@
@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(
@@ -442,7 +364,22 @@
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>
@@ -457,7 +394,7 @@
registerDirectories(directoryUrl, true);
}
- protected void parseDirectory(InputStream directoryStream, URL directoryUrl,
+ /*protected void parseDirectory(InputStream directoryStream, URL
directoryUrl,
URL creoleFileUrl, boolean loadDependencies) throws GateException {
try {
Document jdomDoc =
@@ -472,21 +409,21 @@
throw (new GateException(je));
}
- }
+ }*/
/**
* Parse a directory file (represented as an open stream), adding resource
* data objects to the CREOLE register as they occur. If the resource is from
* a URL then that location is passed (otherwise null).
*/
- protected void parseDirectory(Document jdomDoc, URL directoryUrl,
+ protected void parseDirectory(Plugin plugin, Document jdomDoc, URL
directoryUrl,
URL creoleFileUrl, boolean loadDependencies) throws GateException {
// create a handler for the directory file and parse it;
// this will create ResourceData entries in the register
try {
CreoleAnnotationHandler annotationHandler =
- new CreoleAnnotationHandler(creoleFileUrl);
+ new CreoleAnnotationHandler(plugin);
if (loadDependencies) {
annotationHandler.loadRequiredPlugins(jdomDoc);
@@ -548,11 +485,18 @@
try {
URL creoleDirURL = Gate.getBuiltinCreoleDir();
- URL creoleFileURL = new URL(creoleDirURL, "creole.xml");
+ //URL creoleFileURL = new URL(creoleDirURL, "creole.xml");
// URL creoleFileURL = Files.getGateResource("/creole/creole.xml");
- parseDirectory(creoleFileURL.openStream(), creoleDirURL,
creoleFileURL,true);
+ //parseDirectory(creoleFileURL.openStream(), creoleDirURL,
creoleFileURL,true);*/
+ Plugin plugin = new Plugin.Directory(creoleDirURL);
+
+
+ parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(),
+ new URL(plugin.getBaseURL(),"creole.xml"), true);
+ log.info("CREOLE plugin loaded: " + plugin.getName());
+
}
- catch(IOException e) {
+ catch(Exception e) {
if(DEBUG) log.debug(e);
throw (new GateException(e));
}
@@ -641,6 +585,8 @@
public void removeDirectory(URL directory) {
int prCount = 0;
+ //TODO make this work again
+ /*
if(directories.remove(directory)) {
DirectoryInfo dInfo = Gate.getDirectoryInfo(directory);
if(dInfo != null) {
@@ -679,7 +625,7 @@
log.warn(prCount+" resources were deleted as they relied on the " +
dInfo.getName() +" plugin");
firePluginUnloaded(directory);
- }
+ }*/
}
/**
Modified: gate/branches/sawdust2/src/main/gate/gui/MainFrame.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/gui/MainFrame.java 2016-04-03
08:56:16 UTC (rev 19187)
+++ gate/branches/sawdust2/src/main/gate/gui/MainFrame.java 2016-04-03
16:38:15 UTC (rev 19188)
@@ -26,6 +26,7 @@
import gate.GateConstants;
import gate.LanguageResource;
import gate.Main;
+import gate.Plugin;
import gate.ProcessingResource;
import gate.Resource;
import gate.VisualResource;
@@ -4271,7 +4272,7 @@
URL pluginUrl = new File(Gate.getPluginsHome(),
ANNIEConstants.PLUGIN_DIR).toURI().toURL();
Gate.getCreoleRegister().registerDirectories(pluginUrl);
- Gate.addAutoloadPlugin(pluginUrl);
+ Gate.addAutoloadPlugin(new Plugin.Directory(pluginUrl));
} catch(Exception ex) {
log.error("Unable to load ANNIE plugin.", ex);
}
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 08:56:16 UTC (rev 19187)
+++
gate/branches/sawdust2/src/main/gate/gui/creole/manager/AvailablePlugins.java
2016-04-03 16:38:15 UTC (rev 19188)
@@ -19,6 +19,9 @@
import gate.Gate;
import gate.Gate.ResourceInfo;
+import gate.Plugin;
+import gate.Plugin.Directory;
+import gate.creole.CreoleRegisterImpl;
import gate.gui.MainFrame;
import gate.resources.img.svg.AddIcon;
import gate.resources.img.svg.AvailableIcon;
@@ -96,7 +99,7 @@
* Contains the URLs from Gate.getKnownPlugins() that satisfy the filter
* filterTextField for the plugin URL and the plugin resources names
*/
- private List<URL> visibleRows = new ArrayList<URL>();
+ private List<Plugin> visibleRows = new ArrayList<Plugin>();
private JSplitPane mainSplit;
@@ -111,13 +114,13 @@
/**
* Map from URL to Boolean. Stores temporary values for the loadNow options.
*/
- private Map<URL, Boolean> loadNowByURL = new HashMap<URL, Boolean>();
+ private Map<Plugin, Boolean> loadNowByURL = new HashMap<Plugin, Boolean>();
/**
* Map from URL to Boolean. Stores temporary values for the loadAlways
* options.
*/
- private Map<URL, Boolean> loadAlwaysByURL = new HashMap<URL, Boolean>();
+ private Map<Plugin, Boolean> loadAlwaysByURL = new HashMap<Plugin,
Boolean>();
private static final int ICON_COLUMN = 0;
@@ -328,18 +331,19 @@
} else {
// filter rows case insensitively on each plugin URL and its resources
visibleRows.clear();
- for(int i = 0; i < Gate.getKnownPlugins().size(); i++) {
- Gate.DirectoryInfo dInfo =
- Gate.getDirectoryInfo(Gate.getKnownPlugins().get(i));
- String url = dInfo.getUrl().toString();
+ //for(int i = 0; i < Gate.getKnownPlugins().size(); i++) {
+ for (Plugin plugin : Gate.getKnownPlugins()) {
+ //Gate.DirectoryInfo dInfo =
+ // Gate.getDirectoryInfo(Gate.getKnownPlugins().get(i));
+ String url =
plugin.getBaseURL().toString();//dInfo.getUrl().toString();
String resources = "";
- for(int j = 0; j < dInfo.getResourceInfoList().size(); j++) {
+ for(int j = 0; j < plugin.getResourceInfoList().size(); j++) {
resources +=
- dInfo.getResourceInfoList().get(j).getResourceName() + " ";
+ plugin.getResourceInfoList().get(j).getResourceName() + " ";
}
if(url.toLowerCase().contains(filter)
|| resources.toLowerCase().contains(filter)) {
- visibleRows.add(Gate.getKnownPlugins().get(i));
+ visibleRows.add(plugin);
}
}
}
@@ -371,20 +375,22 @@
}
}
- private Boolean getLoadNow(URL url) {
- Boolean res = loadNowByURL.get(url);
+ private Boolean getLoadNow(Plugin plugin) {
+ Boolean res = loadNowByURL.get(plugin);
+ //TODO this seems bad
if(res == null) {
- res = Gate.getCreoleRegister().getDirectories().contains(url);
- loadNowByURL.put(url, res);
+ res =
Gate.getCreoleRegister().getDirectories().contains(plugin.getBaseURL());
+ loadNowByURL.put(plugin, res);
}
return res;
}
- private Boolean getLoadAlways(URL url) {
- Boolean res = loadAlwaysByURL.get(url);
+ private Boolean getLoadAlways(Plugin plugin) {
+ Boolean res = loadAlwaysByURL.get(plugin);
+ //TODO this seems bad
if(res == null) {
- res = Gate.getAutoloadPlugins().contains(url);
- loadAlwaysByURL.put(url, res);
+ res = Gate.getAutoloadPlugins().contains(plugin);
+ loadAlwaysByURL.put(plugin, res);
}
return res;
}
@@ -444,21 +450,22 @@
@Override
public Object getValueAt(int row, int column) {
- Gate.DirectoryInfo dInfo = Gate.getDirectoryInfo(visibleRows.get(row));
+ Plugin dInfo = visibleRows.get(row);
if(dInfo == null) { return null; }
switch(column){
case NAME_COLUMN:
- return dInfo.toHTMLString();
+ return dInfo.getName();
+ //return dInfo.toHTMLString();
case ICON_COLUMN:
- if(!dInfo.isValid()) return invalidIcon;
- if(dInfo.isRemotePlugin()) return remoteIcon;
- if(dInfo.isCorePlugin()) return coreIcon;
- if(dInfo.isUserPlugin()) return userIcon;
+ //if(!dInfo.isValid()) return invalidIcon;
+ //if(dInfo.isRemotePlugin()) return remoteIcon;
+ //if(dInfo.isCorePlugin()) return coreIcon;
+ //if(dInfo.isUserPlugin()) return userIcon;
return otherIcon;
case LOAD_NOW_COLUMN:
- return getLoadNow(dInfo.getUrl());
+ return getLoadNow(dInfo);
case LOAD_ALWAYS_COLUMN:
- return getLoadAlways(dInfo.getUrl());
+ return getLoadAlways(dInfo);
default:
return null;
}
@@ -466,27 +473,26 @@
@Override
public boolean isCellEditable(int row, int column) {
- Gate.DirectoryInfo dInfo = Gate.getDirectoryInfo(visibleRows.get(row));
- return dInfo.isValid()
+ Plugin plugin = visibleRows.get(row);
+ return plugin.isValid()
&& (column == LOAD_NOW_COLUMN || column == LOAD_ALWAYS_COLUMN);
}
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Boolean valueBoolean = (Boolean)aValue;
- Gate.DirectoryInfo dInfo =
- Gate.getDirectoryInfo(visibleRows.get(rowIndex));
- if(dInfo == null) { return; }
+ Plugin plugin = visibleRows.get(rowIndex);
+ if(plugin == null) { return; }
switch(columnIndex){
case LOAD_NOW_COLUMN:
- loadNowByURL.put(dInfo.getUrl(), valueBoolean);
+ loadNowByURL.put(plugin, valueBoolean);
// for some reason the focus is sometime lost after editing
// however it is needed for Enter key to execute OkAction
mainTable.requestFocusInWindow();
break;
case LOAD_ALWAYS_COLUMN:
- loadAlwaysByURL.put(dInfo.getUrl(), valueBoolean);
+ loadAlwaysByURL.put(plugin, valueBoolean);
mainTable.requestFocusInWindow();
break;
}
@@ -500,8 +506,8 @@
int row = mainTable.getSelectedRow();
if(row == -1) return null;
row = mainTable.rowViewToModel(row);
- Gate.DirectoryInfo dInfo = Gate.getDirectoryInfo(visibleRows.get(row));
- return dInfo.getResourceInfoList().get(index);
+ Plugin plugin = visibleRows.get(row);
+ return plugin.getResourceInfoList().get(index);
}
@Override
@@ -509,9 +515,9 @@
int row = mainTable.getSelectedRow();
if(row == -1) return 0;
row = mainTable.rowViewToModel(row);
- Gate.DirectoryInfo dInfo = Gate.getDirectoryInfo(visibleRows.get(row));
- if(dInfo == null) { return 0; }
- return dInfo.getResourceInfoList().size();
+ Plugin plugin = visibleRows.get(row);
+ if(plugin == null) { return 0; }
+ return plugin.getResourceInfoList().size();
}
public void dataChanged() {
@@ -543,9 +549,9 @@
Set<URL> creoleDirectories = Gate.getCreoleRegister().getDirectories();
- Iterator<URL> pluginIter = loadNowByURL.keySet().iterator();
+ Iterator<Plugin> pluginIter = loadNowByURL.keySet().iterator();
while(pluginIter.hasNext()) {
- URL aPluginURL = pluginIter.next();
+ Plugin aPluginURL = pluginIter.next();
boolean load = loadNowByURL.get(aPluginURL);
boolean loaded = creoleDirectories.contains(aPluginURL);
if(load && !loaded) { return true; }
@@ -554,7 +560,7 @@
pluginIter = loadAlwaysByURL.keySet().iterator();
while(pluginIter.hasNext()) {
- URL aPluginURL = pluginIter.next();
+ Plugin aPluginURL = pluginIter.next();
boolean load = loadAlwaysByURL.get(aPluginURL);
boolean loaded = Gate.getAutoloadPlugins().contains(aPluginURL);
if(load && !loaded) { return true; }
@@ -564,16 +570,16 @@
return false;
}
- protected Set<URL> updateAvailablePlugins() {
+ protected Set<Plugin> updateAvailablePlugins() {
Set<URL> creoleDirectories = Gate.getCreoleRegister().getDirectories();
// update the data structures to reflect the user's choices
- Iterator<URL> pluginIter = loadNowByURL.keySet().iterator();
+ Iterator<Plugin> pluginIter = loadNowByURL.keySet().iterator();
- Set<URL> toLoad = new HashSet<URL>();
+ Set<Plugin> toLoad = new HashSet<Plugin>();
while(pluginIter.hasNext()) {
- URL aPluginURL = pluginIter.next();
+ Plugin aPluginURL = pluginIter.next();
boolean load = loadNowByURL.get(aPluginURL);
boolean loaded = creoleDirectories.contains(aPluginURL);
if(load && !loaded) {
@@ -582,13 +588,15 @@
}
if(!load && loaded) {
// remove the directory
- Gate.getCreoleRegister().removeDirectory(aPluginURL);
+
+ //TODO remove not working yet
+ //Gate.getCreoleRegister().removeDirectory(aPluginURL);
}
}
pluginIter = loadAlwaysByURL.keySet().iterator();
while(pluginIter.hasNext()) {
- URL aPluginURL = pluginIter.next();
+ Plugin aPluginURL = pluginIter.next();
boolean load = loadAlwaysByURL.get(aPluginURL);
boolean loaded = Gate.getAutoloadPlugins().contains(aPluginURL);
if(load && !loaded) {
@@ -597,7 +605,7 @@
}
if(!load && loaded) {
// set autoload to false
- Gate.removeAutoloadPlugin(aPluginURL);
+ Gate.removeAutoloadPlugin(aPluginURL.getBaseURL());
}
}
@@ -608,11 +616,11 @@
pluginIter = toLoad.iterator();
while(pluginIter.hasNext()) {
- URL aPluginURL = pluginIter.next();
+ Plugin aPluginURL = pluginIter.next();
// load the directory
try {
- Gate.getCreoleRegister().registerDirectories(aPluginURL);
+
((CreoleRegisterImpl)Gate.getCreoleRegister()).registerPlugin(aPluginURL);
pluginIter.remove();
} catch(Throwable ge) {
//TODO suppress the errors unless we are going to break out of the
loop
@@ -651,17 +659,19 @@
for(int row : rows) {
int rowModel = mainTable.rowViewToModel(row);
- URL toDelete = visibleRows.get(rowModel);
+ Plugin toDelete = visibleRows.get(rowModel);
- Gate.DirectoryInfo dInfo = Gate.getDirectoryInfo(toDelete);
+ //Gate.DirectoryInfo dInfo = Gate.getDirectoryInfo(toDelete);
- Gate.getCreoleRegister().removeDirectory(toDelete);
+ /*Gate.getCreoleRegister().removeDirectory(toDelete);
+ //TODO make this work again
+
if(!dInfo.isCorePlugin() && !dInfo.isUserPlugin()) {
Gate.removeKnownPlugin(toDelete);
loadAlwaysByURL.remove(toDelete);
loadNowByURL.remove(toDelete);
- }
+ }*/
}
// redisplay the table with the current filter
@@ -758,7 +768,7 @@
try {
final URL creoleURL = new URL(urlTextField.getText());
- Gate.addKnownPlugin(creoleURL);
+ Gate.addKnownPlugin(new Plugin.Directory(creoleURL));
mainTable.clearSelection();
// redisplay the table without filtering
filterRows("");
Modified:
gate/branches/sawdust2/src/main/gate/gui/creole/manager/PluginUpdateManager.java
===================================================================
---
gate/branches/sawdust2/src/main/gate/gui/creole/manager/PluginUpdateManager.java
2016-04-03 08:56:16 UTC (rev 19187)
+++
gate/branches/sawdust2/src/main/gate/gui/creole/manager/PluginUpdateManager.java
2016-04-03 16:38:15 UTC (rev 19188)
@@ -15,6 +15,7 @@
package gate.gui.creole.manager;
import gate.Gate;
+import gate.Plugin;
import gate.gui.MainFrame;
import gate.resources.img.svg.AddIcon;
import gate.resources.img.svg.AdvancedIcon;
@@ -273,7 +274,7 @@
// add the plugin. most will already be known but this will
// catch any that have just been installed
- Gate.addKnownPlugin(f.toURI().toURL());
+ Gate.addKnownPlugin(new Plugin.Directory(f.toURI().toURL()));
} catch(Exception e) {
e.printStackTrace();
}
@@ -462,7 +463,7 @@
// (un)load already installed plugins
progressPanel.messageChanged("Updating CREOLE Plugin
Configuration...");
- Set<URL> failedPlugins = installed.updateAvailablePlugins();
+ Set<Plugin> failedPlugins = installed.updateAvailablePlugins();
if (!failedPlugins.isEmpty()) {
JOptionPane
.showMessageDialog(
Modified: gate/branches/sawdust2/src/main/gate/util/GateClassLoader.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/util/GateClassLoader.java
2016-04-03 08:56:16 UTC (rev 19187)
+++ gate/branches/sawdust2/src/main/gate/util/GateClassLoader.java
2016-04-03 16:38:15 UTC (rev 19188)
@@ -22,8 +22,8 @@
package gate.util;
import gate.Gate;
-import gate.Gate.DirectoryInfo;
import gate.Gate.ResourceInfo;
+import gate.Plugin;
import gate.Resource;
import gate.creole.AbstractResource;
@@ -348,7 +348,7 @@
}
- public void forgetClassLoader(String id, DirectoryInfo dInfo) {
+ public void forgetClassLoader(String id, Plugin dInfo) {
if(dInfo == null) {
forgetClassLoader(id);
Modified: gate/branches/sawdust2/src/main/gate/util/ant/ExpandCreoleXmls.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/util/ant/ExpandCreoleXmls.java
2016-04-03 08:56:16 UTC (rev 19187)
+++ gate/branches/sawdust2/src/main/gate/util/ant/ExpandCreoleXmls.java
2016-04-03 16:38:15 UTC (rev 19188)
@@ -1,5 +1,12 @@
package gate.util.ant;
+import gate.Gate;
+import gate.Plugin;
+import gate.creole.CreoleAnnotationHandler;
+import gate.creole.metadata.CreoleResource;
+import gate.util.CreoleXmlUpperCaseFilter;
+import gate.util.GateException;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
@@ -8,12 +15,6 @@
import java.util.Iterator;
import java.util.List;
-import gate.Gate;
-import gate.creole.CreoleAnnotationHandler;
-import gate.creole.metadata.CreoleResource;
-import gate.util.CreoleXmlUpperCaseFilter;
-import gate.util.GateException;
-
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
@@ -108,8 +109,10 @@
File destPlugin = destFile.getParentFile();
log("Expanding " + creoleFile + " to " + destFile,
Project.MSG_VERBOSE);
- Gate.addKnownPlugin(plugin.toURI().toURL());
- CreoleAnnotationHandler annotationHandler = new
CreoleAnnotationHandler(creoleFile.toURI().toURL());
+ //TODO check this works
+ Plugin dirPlugin = new Plugin.Directory(plugin.toURI().toURL());
+ Gate.addKnownPlugin(dirPlugin);
+ CreoleAnnotationHandler annotationHandler = new
CreoleAnnotationHandler(dirPlugin);
Document creoleDoc = builder.build(creoleFile);
annotationHandler.createResourceElementsForDirInfo(creoleDoc);
if(!classesOnly) {
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