Revision: 19203
http://sourceforge.net/p/gate/code/19203
Author: markagreenwood
Date: 2016-04-06 09:31:50 +0000 (Wed, 06 Apr 2016)
Log Message:
-----------
the requires now supports mavenized plugins, plus some tidying up
Modified Paths:
--------------
gate/branches/sawdust2/src/main/gate/Plugin.java
gate/branches/sawdust2/src/main/gate/Utils.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
Modified: gate/branches/sawdust2/src/main/gate/Plugin.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/Plugin.java 2016-04-06 01:22:24 UTC
(rev 19202)
+++ gate/branches/sawdust2/src/main/gate/Plugin.java 2016-04-06 09:31:50 UTC
(rev 19203)
@@ -27,6 +27,7 @@
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
@@ -56,7 +57,6 @@
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
-import org.jdom.xpath.XPath;
public abstract class Plugin {
@@ -88,49 +88,8 @@
if (requiredPlugins == null) parseCreole();
return requiredPlugins;
- }
+ }
- /*
-
- XPath jarXPath =
- XPath
- .newInstance("//*[translate(local-name(), 'requires',
'REQUIRES') = 'REQUIRES']");
- @SuppressWarnings("unchecked")
- List<Element> requires = jarXPath.selectNodes(getCreoleXML());
-
- String relativePathMarker = "$relpath$";
- String gatehomePathMarker = "$gatehome$";
- String gatepluginsPathMarker = "$gateplugins$";
-
- for(Element required : requires) {
-
- URL url = null;
- String urlString = required.getTextTrim();
- if(urlString.startsWith(relativePathMarker)) {
- url =
- new URL(getBaseURL(), urlString.substring(relativePathMarker
- .length()));
- } else if(urlString.startsWith(gatehomePathMarker)) {
- URL gatehome = Gate.getGateHome().toURI().toURL();
- url =
- new URL(gatehome,
- urlString.substring(gatehomePathMarker.length()));
- } else if(urlString.startsWith(gatepluginsPathMarker)) {
- URL gateplugins = Gate.getPluginsHome().toURI().toURL();
- url =
- new URL(gateplugins, urlString.substring(gatepluginsPathMarker
- .length()));
- } else {
- url = new URL(getBaseURL(), urlString);
- }
-
- Gate.getCreoleRegister().registerDirectories(url);
- }
-
-
- return requiredPlugins;
- }*/
-
@Override
public int hashCode() {
final int prime = 31;
@@ -178,7 +137,7 @@
org.jdom.Document creoleDoc = getCreoleXML();
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
- xmlOut.output(creoleDoc, System.out);
+ log.debug(xmlOut.outputString(creoleDoc));
final Map<String, ResourceInfo> resInfos = new LinkedHashMap<String,
ResourceInfo>();
List<Element> jobsList = new ArrayList<Element>();
@@ -213,28 +172,39 @@
}
}
else if(currentElem.getName().equalsIgnoreCase("REQUIRES")) {
- //System.out.println("REQUIRES: " + currentElem.getTextTrim());
- URL url = null;
- String urlString = currentElem.getTextTrim();
- if(urlString.startsWith(relativePathMarker)) {
- url =
- new URL(getBaseURL(), urlString.substring(relativePathMarker
- .length()));
- } else if(urlString.startsWith(gatehomePathMarker)) {
- URL gatehome = Gate.getGateHome().toURI().toURL();
- url =
- new URL(gatehome,
- urlString.substring(gatehomePathMarker.length()));
- } else if(urlString.startsWith(gatepluginsPathMarker)) {
- URL gateplugins = Gate.getPluginsHome().toURI().toURL();
- url =
- new URL(gateplugins, urlString.substring(gatepluginsPathMarker
- .length()));
- } else {
- url = new URL(getBaseURL(), urlString);
+
+ if (currentElem.getAttribute("GROUP") != null) {
+ //TODO probably need more error checking here
+ requiredPlugins.add(new Plugin.Maven(currentElem
+ .getAttributeValue("GROUP"), currentElem
+ .getAttributeValue("ARTIFACT"), currentElem
+ .getAttributeValue("VERSION")));
}
-
- requiredPlugins.add(new Plugin.Directory(url));
+ else {
+ URL url = null;
+ String urlString = currentElem.getTextTrim();
+ if(urlString.startsWith(relativePathMarker)) {
+ url =
+ new URL(getBaseURL(), urlString.substring(relativePathMarker
+ .length()));
+ } else if(urlString.startsWith(gatehomePathMarker)) {
+ URL gatehome = Gate.getGateHome().toURI().toURL();
+ url =
+ new URL(gatehome,
+ urlString.substring(gatehomePathMarker.length()));
+ } else if(urlString.startsWith(gatepluginsPathMarker)) {
+ URL gateplugins = Gate.getPluginsHome().toURI().toURL();
+ url =
+ new URL(gateplugins,
urlString.substring(gatepluginsPathMarker
+ .length()));
+ } else {
+ url = new URL(getBaseURL(), urlString);
+ }
+
+ requiredPlugins.add(new Plugin.Directory(url));
+
+ Utils.logOnce(log, Level.WARN, "Dependencies on other plugins via
URL is deprecated ("+getName()+" plugin)");
+ }
}
else {
// this is some higher level element -> simulate recursion
@@ -321,7 +291,7 @@
}
protected void fillInResInfos(List<ResourceInfo> incompleteResInfos,
- List<String> allJars) throws IOException {
+ 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).
@@ -329,20 +299,23 @@
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();
+
+ // TODO shouldn't we use a proper temp gate class loader which we
+ // can then throw away?
+ try(URLClassLoader 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();
+ }
}
}
}
Modified: gate/branches/sawdust2/src/main/gate/Utils.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/Utils.java 2016-04-06 01:22:24 UTC
(rev 19202)
+++ gate/branches/sawdust2/src/main/gate/Utils.java 2016-04-06 09:31:50 UTC
(rev 19203)
@@ -1179,6 +1179,7 @@
*
* @param dirName The directory name of the plugin within the standard GATE
plugins directory.
*/
+ @Deprecated
public static void loadPlugin(String dirName) {
File gatehome = Gate.getGateHome();
if(gatehome == null) {
@@ -1196,7 +1197,7 @@
*/
public static void loadPlugin(File pluginDir) {
try {
- Gate.getCreoleRegister().registerDirectories(pluginDir.toURI().toURL());
+ Gate.getCreoleRegister().registerPlugin(new
Plugin.Directory(pluginDir.toURI().toURL()));
} catch (Exception ex) {
throw new GateRuntimeException("Could not register plugin directory
"+pluginDir,ex);
}
Modified: gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
2016-04-06 01:22:24 UTC (rev 19202)
+++ gate/branches/sawdust2/src/main/gate/creole/CreoleRegisterImpl.java
2016-04-06 09:31:50 UTC (rev 19203)
@@ -186,8 +186,15 @@
Gate.addKnownPlugin(plugin);
try {
+
+ if (loadDependencies) {
+ for (Plugin required : plugin.getRequiredPlugins()) {
+ registerPlugin(required, true);
+ }
+ }
+
parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(),
- new URL(plugin.getBaseURL(),"creole.xml"), loadDependencies);
+ new URL(plugin.getBaseURL(),"creole.xml"));
log.info("CREOLE plugin loaded: " + plugin.getName());
}
catch(Throwable e) {
@@ -253,18 +260,13 @@
* a URL then that location is passed (otherwise null).
*/
protected void parseDirectory(Plugin plugin, Document jdomDoc, URL
directoryUrl,
- URL creoleFileUrl, boolean loadDependencies) throws GateException {
+ URL creoleFileUrl) 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(plugin);
-
- if (loadDependencies) {
- //TODO move this earlier I think
- annotationHandler.loadRequiredPlugins(jdomDoc);
- }
GateClassLoader gcl =
Gate.getClassLoader().getDisposableClassLoader(creoleFileUrl.toExternalForm());
@@ -327,9 +329,8 @@
//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);
+ new URL(plugin.getBaseURL(),"creole.xml"));
log.info("CREOLE plugin loaded: " + plugin.getName());
}
Modified: gate/branches/sawdust2/src/main/gate/gui/MainFrame.java
===================================================================
--- gate/branches/sawdust2/src/main/gate/gui/MainFrame.java 2016-04-06
01:22:24 UTC (rev 19202)
+++ gate/branches/sawdust2/src/main/gate/gui/MainFrame.java 2016-04-06
09:31:50 UTC (rev 19203)
@@ -4269,10 +4269,11 @@
@Override
public void actionPerformed(ActionEvent e) {
try {
+ //TODO we should probably be pulling this in via Maven not a
URL
URL pluginUrl = new File(Gate.getPluginsHome(),
ANNIEConstants.PLUGIN_DIR).toURI().toURL();
- Gate.getCreoleRegister().registerDirectories(pluginUrl);
- Gate.addAutoloadPlugin(new Plugin.Directory(pluginUrl));
+ Plugin anniePlugin = new Plugin.Directory(pluginUrl);
+ Gate.getCreoleRegister().registerPlugin(anniePlugin);
} 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-06 01:22:24 UTC (rev 19202)
+++
gate/branches/sawdust2/src/main/gate/gui/creole/manager/AvailablePlugins.java
2016-04-06 09:31:50 UTC (rev 19203)
@@ -454,7 +454,7 @@
return dInfo.getName();
//return dInfo.toHTMLString();
case ICON_COLUMN:
- //if(!dInfo.isValid()) return invalidIcon;
+ if(!dInfo.isValid()) return invalidIcon;
//if(dInfo.isRemotePlugin()) return remoteIcon;
//if(dInfo.isCorePlugin()) return coreIcon;
//if(dInfo.isUserPlugin()) return userIcon;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs