Revision: 17705
          http://sourceforge.net/p/gate/code/17705
Author:   ian_roberts
Date:     2014-03-19 17:49:33 +0000 (Wed, 19 Mar 2014)
Log Message:
-----------
Added $resourceshome$ support to <packagegapp>

Modified Paths:
--------------
    gate/trunk/src/main/gate/util/ant/packager/GappModel.java
    gate/trunk/src/main/gate/util/ant/packager/PackageGappTask.java

Modified: gate/trunk/src/main/gate/util/ant/packager/GappModel.java
===================================================================
--- gate/trunk/src/main/gate/util/ant/packager/GappModel.java   2014-03-19 
17:00:01 UTC (rev 17704)
+++ gate/trunk/src/main/gate/util/ant/packager/GappModel.java   2014-03-19 
17:49:33 UTC (rev 17705)
@@ -39,6 +39,11 @@
   private URL gateHomeURL;
 
   /**
+   * The URL against which to resolve $resourceshome$ relative paths.
+   */
+  private URL resourcesHomeURL;
+
+  /**
    * Map whose keys are the resolved URLs of plugins referred to by relative
    * paths in the GAPP file and whose values are the JDOM Elements of the
    * &lt;urlString&gt; elements concerned.
@@ -67,13 +72,20 @@
   private static XPath relativePluginPathElementsXPath;
 
   /**
-   * @see #GappModel(URL,URL)
+   * @see #GappModel(URL,URL, URL)
    */
   public GappModel(URL gappFileURL) {
-    this(gappFileURL, null);
+    this(gappFileURL, null, null);
   }
 
   /**
+   * @see #GappModel(URL,URL, URL)
+   */
+  public GappModel(URL gappFileURL, URL gateHomeURL) {
+    this(gappFileURL, gateHomeURL, null);
+  }
+
+  /**
    * Create a GappModel for a GAPP file.
    * 
    * @param gappFileURL the URL of the GAPP file to model.
@@ -82,9 +94,15 @@
    * packaging does not contain any $gatehome$ paths.  If no gateHomeURL is
    * provided but the application does contain a $gatehome$ path, a
    * GateRuntimeException will be thrown.
+   * @param resourcesHomeURL TODO
+   * @param resourcesHomeURL the URL against which $resourceshome$ relative 
paths should
+   * be resolved.  This may be null if you are sure that the GAPP you are
+   * packaging does not contain any $resourceshome$ paths.  If no gateHomeURL 
is
+   * provided but the application does contain a $resourceshome$ path, a
+   * GateRuntimeException will be thrown.
    */
   @SuppressWarnings("unchecked")
-  public GappModel(URL gappFileURL, URL gateHomeURL) {
+  public GappModel(URL gappFileURL, URL gateHomeURL, URL resourcesHomeURL) {
     if(!"file".equals(gappFileURL.getProtocol())) {
       throw new GateRuntimeException("GAPP URL must be a file: URL");
     }
@@ -93,6 +111,7 @@
     }
     this.gappFileURL = gappFileURL;
     this.gateHomeURL = gateHomeURL;
+    this.resourcesHomeURL = resourcesHomeURL;
 
     try {
       SAXBuilder builder = new SAXBuilder();
@@ -110,12 +129,14 @@
                         
.newInstance("/gate.util.persistence.GateApplication/application"
                                 + 
"//gate.util.persistence.PersistenceManager-URLHolder"
                                 + "/urlString[starts-with(., '$relpath$') "
+                                + "or starts-with(., '$resourceshome$') "
                                 + "or starts-with(., '$gatehome$')]");
         relativePluginPathElementsXPath =
                 XPath
                         
.newInstance("/gate.util.persistence.GateApplication/urlList"
                                 + 
"//gate.util.persistence.PersistenceManager-URLHolder"
                                 + "/urlString[starts-with(., '$relpath$') "
+                                + "or starts-with(., '$resourceshome$') "
                                 + "or starts-with(., '$gatehome$')]");
       }
       catch(JDOMException jdx) {
@@ -163,6 +184,15 @@
         String relativePath = el.getText().substring("$gatehome$".length());
         targetURL = new URL(gateHomeURL, relativePath);
       }
+      else if(elementText.startsWith("$resourceshome$")) {
+        // complain if gateHomeURL not set
+        if(gateHomeURL == null) {
+          throw new GateRuntimeException("Found a $resourceshome$ relative 
path in "
+              + "GAPP file, but no resources home URL provided to resolve 
against");
+        }
+        String relativePath = 
el.getText().substring("$resourceshome$".length());
+        targetURL = new URL(resourcesHomeURL, relativePath);
+      }
       else if(elementText.startsWith("$relpath$")) {
         String relativePath = el.getText().substring("$relpath$".length());
         targetURL = new URL(gappFileURL, relativePath);

Modified: gate/trunk/src/main/gate/util/ant/packager/PackageGappTask.java
===================================================================
--- gate/trunk/src/main/gate/util/ant/packager/PackageGappTask.java     
2014-03-19 17:00:01 UTC (rev 17704)
+++ gate/trunk/src/main/gate/util/ant/packager/PackageGappTask.java     
2014-03-19 17:49:33 UTC (rev 17705)
@@ -95,6 +95,12 @@
   private File gateHome;
 
   /**
+   * The location of the resources home directory.  Only required if the GAPP 
file
+   * to be packaged contains URLs relative to $resourceshome$.
+   */
+  private File resourcesHome;
+
+  /**
    * Should we copy the complete contents of referenced plugin
    * directories into the right place relative to the destFile? If not,
    * only the creole.xmls, any JARs they directly include, and directly
@@ -204,6 +210,22 @@
   }
 
   /**
+   * Get the location of the resources home directory, used to resolve 
$resourceshome$
+   * relative paths in the GAPP file.
+   */
+  public File getResourcesHome() {
+    return resourcesHome;
+  }
+
+  /**
+   * Set the location of the resources home directory, used to resolve 
$resourceshome$
+   * relative paths in the GAPP file.
+   */
+  public void setResourcesHome(File resourcesHome) {
+    this.resourcesHome = resourcesHome;
+  }
+
+  /**
    * Will the task copy the complete contents of referenced plugins into
    * the target location?
    */
@@ -318,7 +340,12 @@
       if(gateHome != null) {
         gateHomeURL = gateHome.toURI().toURL();
       }
-      gappModel = new GappModel(src.toURI().toURL(), gateHomeURL);
+      URL resourcesHomeURL = null;
+      // convert resourcesHome to a URL, if it was provided
+      if(resourcesHome != null) {
+        resourcesHomeURL = resourcesHome.toURI().toURL();
+      }
+      gappModel = new GappModel(src.toURI().toURL(), gateHomeURL, 
resourcesHomeURL);
       newFileURL = destFile.toURI().toURL();
       gappModel.setGappFileURL(newFileURL);
     }

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


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to