Revision: 17069
http://sourceforge.net/p/gate/code/17069
Author: markagreenwood
Date: 2013-11-08 17:41:43 +0000 (Fri, 08 Nov 2013)
Log Message:
-----------
a little more sawing and we now have plugin dependencies working as well :) see
the Twitter plugin for an example
Modified Paths:
--------------
gate/branches/sawdust/plugins/Twitter/creole.xml
gate/branches/sawdust/src/core/gate/CreoleRegister.java
gate/branches/sawdust/src/core/gate/creole/CreoleAnnotationHandler.java
gate/branches/sawdust/src/core/gate/creole/CreoleRegisterImpl.java
gate/branches/sawdust/src/core/gate/creole/CreoleXmlHandler.java
gate/branches/sawdust/src/core/gate/util/persistence/PersistenceManager.java
Modified: gate/branches/sawdust/plugins/Twitter/creole.xml
===================================================================
--- gate/branches/sawdust/plugins/Twitter/creole.xml 2013-11-08 17:40:00 UTC
(rev 17068)
+++ gate/branches/sawdust/plugins/Twitter/creole.xml 2013-11-08 17:41:43 UTC
(rev 17069)
@@ -5,4 +5,5 @@
<JAR>lib/jackson-core-2.2.3.jar</JAR>
<JAR>lib/jackson-databind-2.2.3.jar</JAR>
<JAR>lib/jackson-annotations-2.2.3.jar</JAR>
+ <REQUIRES>../Tagger_Stanford</REQUIRES>
</CREOLE-DIRECTORY>
Modified: gate/branches/sawdust/src/core/gate/CreoleRegister.java
===================================================================
--- gate/branches/sawdust/src/core/gate/CreoleRegister.java 2013-11-08
17:40:00 UTC (rev 17068)
+++ gate/branches/sawdust/src/core/gate/CreoleRegister.java 2013-11-08
17:41:43 UTC (rev 17069)
@@ -97,9 +97,24 @@
/** 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.
+ * is now added. If any other plugins that nees top be loaded for this
+ * plugin to load (specified by <CODE>REQUIRES</Code> elements in
+ * <code>creole.xml</code>) will also be loaded.
*/
public void registerDirectories(URL directoryUrl) throws GateException;
+
+ /**
+ * 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 plugin to load (specified by
+ * <CODE>REQUIRES</Code> elements in <code>creole.xml</code>) will only be
+ * loaded if the <code>loadDependencies</code> param is true. It is useful to
+ * be able to ignore dependencies when loading an xgapp where we know they
+ * have already been resolved.
+ */
+ public void registerDirectories(URL directoryUrl, boolean loadDependencies)
+ throws GateException;
/**
* Removes a CREOLE directory from the set of loaded directories.
Modified:
gate/branches/sawdust/src/core/gate/creole/CreoleAnnotationHandler.java
===================================================================
--- gate/branches/sawdust/src/core/gate/creole/CreoleAnnotationHandler.java
2013-11-08 17:40:00 UTC (rev 17068)
+++ gate/branches/sawdust/src/core/gate/creole/CreoleAnnotationHandler.java
2013-11-08 17:41:43 UTC (rev 17069)
@@ -1,7 +1,7 @@
/*
* CreoleAnnotationHandler.java
*
- * Copyright (c) 1995-2012, The University of Sheffield. See the file
+ * Copyright (c) 1995-2013, The University of Sheffield. See the file
* COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
*
* This file is part of GATE (see http://gate.ac.uk/), and is free software,
@@ -59,6 +59,7 @@
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
+import org.jdom.xpath.XPath;
/**
* Class to take a creole.xml file (as a JDOM tree) and add elements
@@ -95,6 +96,52 @@
}
/**
+ * Extracts all the the REQUIRES elements from the given JDOM document,
+ * expands the URLs and then attempts to load the specified plugin
+ *
+ * @param jdomDoc JDOM document representing a parsed creole.xml file.
+ */
+ public void loadRequiredPlugins(Document jdomDoc) throws IOException {
+ try {
+ XPath jarXPath =
+ XPath
+ .newInstance("//*[translate(local-name(), 'requires',
'REQUIRES') = 'REQUIRES']");
+ @SuppressWarnings("unchecked")
+ List<Element> requires = jarXPath.selectNodes(jdomDoc);
+
+ 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(creoleFileUrl, 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(creoleFileUrl, urlString);
+ }
+
+ Gate.getCreoleRegister().registerDirectories(url);
+ }
+ } catch(Exception e) {
+ throw new IOException("Unable to load required plugin", e);
+ }
+ }
+
+ /**
* Extract all the IVY elements from the given JDOM document and then add all
* the jars resulting from ivy's dependency resolution to the
GateClassLoader.
*
Modified: gate/branches/sawdust/src/core/gate/creole/CreoleRegisterImpl.java
===================================================================
--- gate/branches/sawdust/src/core/gate/creole/CreoleRegisterImpl.java
2013-11-08 17:40:00 UTC (rev 17068)
+++ gate/branches/sawdust/src/core/gate/creole/CreoleRegisterImpl.java
2013-11-08 17:41:43 UTC (rev 17069)
@@ -1,7 +1,7 @@
/*
* CreoleRegisterImpl.java
*
- * Copyright (c) 1995-2012, The University of Sheffield. See the file
+ * Copyright (c) 1995-2013, The University of Sheffield. See the file
* COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
*
* This file is part of GATE (see http://gate.ac.uk/), and is free
@@ -230,12 +230,18 @@
/**
* 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. URLs for
- * resource JAR files are added to the GATE class loader.
+ * If the directory URL has not yet been added it is now added. If any other
+ * plugins that nees top be loaded for this plugin to load (specified by
+ * <CODE>REQUIRES</Code> elements in <code>creole.xml</code>) will only be
+ * loaded if the <code>loadDependencies</code> param is true. It is useful to
+ * be able to ignore dependencies when loading an xgapp where we know they
+ * have already been resolved.
*/
- public void registerDirectories(URL directoryUrl) throws GateException {
-
- // directory URLs shouldn't include "creole.xml"
+ @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 "
@@ -315,7 +321,7 @@
// parse the directory file
try {
parseDirectory(creoleStream, directoryUrl,
- directoryXmlFileUrl);
+ directoryXmlFileUrl, loadDependencies);
log.info("CREOLE plugin loaded: " + urlName);
}
catch(Throwable e) {
@@ -325,7 +331,19 @@
throw (new GateException("couldn't open creole.xml",e));
}
}
- } // registerDirectories(URL)
+ }
+
+ /** 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
+ * plugin to load (specified by <CODE>REQUIRES</Code> elements in
+ * <code>creole.xml</code>) will also be loaded.
+ */
+ @Override
+ public void registerDirectories(URL directoryUrl) throws GateException {
+ registerDirectories(directoryUrl, true);
+ }
/**
* Parse a directory file (represented as an open stream), adding resource
@@ -333,7 +351,7 @@
* a URL then that location is passed (otherwise null).
*/
protected void parseDirectory(InputStream directoryStream, URL directoryUrl,
- URL creoleFileUrl) throws GateException {
+ 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 {
@@ -342,6 +360,10 @@
CreoleAnnotationHandler annotationHandler =
new CreoleAnnotationHandler(creoleFileUrl);
+ if (loadDependencies) {
+ annotationHandler.loadRequiredPlugins(jdomDoc);
+ }
+
GateClassLoader gcl =
Gate.getClassLoader().getDisposableClassLoader(creoleFileUrl.toExternalForm());
// Add any JARs from the creole.xml to the GATE ClassLoader
@@ -399,7 +421,7 @@
URL creoleDirURL = Gate.getBuiltinCreoleDir();
URL creoleFileURL = new URL(creoleDirURL, "creole.xml");
// URL creoleFileURL = Files.getGateResource("/creole/creole.xml");
- parseDirectory(creoleFileURL.openStream(), creoleDirURL, creoleFileURL);
+ parseDirectory(creoleFileURL.openStream(), creoleDirURL,
creoleFileURL,true);
}
catch(IOException e) {
if(DEBUG) log.debug(e);
Modified: gate/branches/sawdust/src/core/gate/creole/CreoleXmlHandler.java
===================================================================
--- gate/branches/sawdust/src/core/gate/creole/CreoleXmlHandler.java
2013-11-08 17:40:00 UTC (rev 17068)
+++ gate/branches/sawdust/src/core/gate/creole/CreoleXmlHandler.java
2013-11-08 17:41:43 UTC (rev 17069)
@@ -1,7 +1,7 @@
/*
* CreoleXmlHandler.java
*
- * Copyright (c) 1995-2012, The University of Sheffield. See the file
+ * Copyright (c) 1995-2013, The University of Sheffield. See the file
* COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
*
* This file is part of GATE (see http://gate.ac.uk/), and is free
@@ -423,6 +423,10 @@
if (!contentStack.isEmpty()) contentStack.pop();
// End IVY processing
//////////////////////////////////////////////////////////////////
+ } else if (elementName.toUpperCase().equals("REQUIRES")) {
+ if (!contentStack.isEmpty()) contentStack.pop();
+ // End REQUIRES processing
+ //////////////////////////////////////////////////////////////////
} else if(elementName.toUpperCase().equals("JAR")) {
checkStack("endElement", "JAR");
Modified:
gate/branches/sawdust/src/core/gate/util/persistence/PersistenceManager.java
===================================================================
---
gate/branches/sawdust/src/core/gate/util/persistence/PersistenceManager.java
2013-11-08 17:40:00 UTC (rev 17068)
+++
gate/branches/sawdust/src/core/gate/util/persistence/PersistenceManager.java
2013-11-08 17:41:43 UTC (rev 17069)
@@ -894,7 +894,7 @@
while(urlIter.hasNext()) {
URL anUrl = (URL)urlIter.next();
try {
- Gate.getCreoleRegister().registerDirectories(anUrl);
+ Gate.getCreoleRegister().registerDirectories(anUrl,false);
}
catch(GateException ge) {
Err.prln("Could not reload creole directory "
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs