gate.util.ant.packager
Class PackageGappTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by gate.util.ant.packager.PackageGappTask
All Implemented Interfaces:
Cloneable

public class PackageGappTask
extends org.apache.tools.ant.Task

Ant task to copy a gapp file, rewriting any relative paths it contains to point within the same directory as the target file location and copy the referenced files into the right locations. The resulting structure is self-contained and can be packaged up (e.g. in a zip file) to send to a third party.

Author:
Ian Roberts

Nested Class Summary
 class PackageGappTask.MappingHint
          Class to represent a nested hint element.
static class PackageGappTask.UnresolvedAction
          Enumeration of the actions to take when there are unresolved resources.
 
Field Summary
private  boolean copyPlugins
          Should we copy the complete contents of referenced plugin directories into the right place relative to the destFile?
private  boolean copyResourceDirs
          Should we copy the complete contents of the parent directories of any referenced resource files?
private  File destFile
          The file into which the modified gapp will be written.
private  List<org.apache.tools.ant.types.Path> extraResourcesPaths
          Path-like structure listing extra resources that should be packaged with the gapp, as if they had been referenced by relpaths from within the gapp file.
private  File gateHome
          The location of the GATE home directory.
private  List<PackageGappTask.MappingHint> hintTasks
          List of mapping hint sub-elements.
private  Map<URL,String> mappingHints
          Map of mapping hints.
private  PackageGappTask.UnresolvedAction onUnresolved
          The action to take when there are unresolved resources.
static Comparator<URL> PATH_COMPARATOR
          Comparator to compare URLs by lexicographic ordering of their getPath() values.
private  File src
          The original file containing the gapp to package.
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
PackageGappTask()
           
 
Method Summary
 void addExtraResourcesPath(org.apache.tools.ant.types.Path path)
          Add a path containing extra resources that should be treated as if they had been referenced by relpaths within the gapp file.
private  void copyDirectories(Map<URL,URL> copyMap, boolean minimalPlugin)
          Copy directories as specified by the given map.
 PackageGappTask.MappingHint createHint()
          Create and add the representation for a nested <hint from="X" to="Y" /> element.
 void execute()
           
 File getDestFile()
          Get the destination file to which the modified gapp will be written.
 File getGateHome()
          Get the location of the GATE home directory, used to resolve $gatehome$ relative paths in the GAPP file.
private  Set<String> getJars(URL creoleXml)
          Extract the text values from any <JAR> elements contained in the referenced creole.xml file.
 PackageGappTask.UnresolvedAction getOnUnresolved()
          Get the action performed when there are unresolved resources.
 File getSrc()
          Get the original gapp file that is to be modified.
private  URL getUnresolvedResourcesTarget(TreeMap<URL,URL> unresolvedResourcesSubDirs, URL unresolvedResourcesDir, URL resourceDir)
          Get a URL for a directory to which the given (unresolved) resource directory should be mapped.
 boolean isCopyPlugins()
          Will the task copy the complete contents of referenced plugins into the target location?
 boolean isCopyResourceDirs()
          Will the task copy the complete contents of directories containing referenced resources into the target location or just the referenced resources themselves?
private  void processExtraResourcesPaths(Set<URL> resources)
          Process any extraresourcespath elements provided to this task and include the resources they refer to in the given set.
 void setCopyPlugins(boolean copyPlugins)
          Will the task copy the complete contents of referenced plugins into the target location?
 void setCopyResourceDirs(boolean copyResourceDirs)
          Will the task copy the complete contents of directories containing referenced resources into the target location?
 void setDestFile(File destFile)
          Set the destination file to which the modified gapp will be written.
 void setGateHome(File gateHome)
          Set the location of the GATE home directory, used to resolve $gatehome$ relative paths in the GAPP file.
 void setOnUnresolved(PackageGappTask.UnresolvedAction onUnresolved)
          What should we do if there are unresolved relpaths within the gapp file?
 void setSrc(File src)
          Set the location of the original gapp file which is to be modified.
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_COMPARATOR

public static final Comparator<URL> PATH_COMPARATOR
Comparator to compare URLs by lexicographic ordering of their getPath() values. null compares less-than anything not null.


destFile

private File destFile
The file into which the modified gapp will be written.


src

private File src
The original file containing the gapp to package.


gateHome

private File gateHome
The location of the GATE home directory. Only required if the GAPP file to be packaged contains URLs relative to $gatehome$.


copyPlugins

private boolean copyPlugins
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 referenced resource files will be copied. Anything else needs to be declared in an <extrafiles> sub-element.


copyResourceDirs

private boolean copyResourceDirs
Should we copy the complete contents of the parent directories of any referenced resource files? If true, whenever the gapp references a resource file f we will also include the whole contents of f.getParentFile().


extraResourcesPaths

private List<org.apache.tools.ant.types.Path> extraResourcesPaths
Path-like structure listing extra resources that should be packaged with the gapp, as if they had been referenced by relpaths from within the gapp file. Their target locations are determined by the plugins and mapping hints in the usual way. Typically this would be used for other resource files that are not referenced directly by the gapp file but are referenced indirectly by the PRs in the application (e.g. the .lst files corresponding to a gazetteer .def).


onUnresolved

private PackageGappTask.UnresolvedAction onUnresolved
The action to take when there are unresolved resources. By default, unresolved resources will fail the build.


hintTasks

private List<PackageGappTask.MappingHint> hintTasks
List of mapping hint sub-elements.


mappingHints

private Map<URL,String> mappingHints
Map of mapping hints. This is an insertion-ordered LinkedHashMap, so where two hints could apply to the same path, the one specified first in the configuration wins.

Constructor Detail

PackageGappTask

public PackageGappTask()
Method Detail

getDestFile

public File getDestFile()
Get the destination file to which the modified gapp will be written.


setDestFile

public void setDestFile(File destFile)
Set the destination file to which the modified gapp will be written.


getSrc

public File getSrc()
Get the original gapp file that is to be modified.


setSrc

public void setSrc(File src)
Set the location of the original gapp file which is to be modified.


getGateHome

public File getGateHome()
Get the location of the GATE home directory, used to resolve $gatehome$ relative paths in the GAPP file.


setGateHome

public void setGateHome(File gateHome)
Set the location of the GATE home directory, used to resolve $gatehome$ relative paths in the GAPP file.


isCopyPlugins

public boolean isCopyPlugins()
Will the task copy the complete contents of referenced plugins into the target location?


setCopyPlugins

public void setCopyPlugins(boolean copyPlugins)
Will the task copy the complete contents of referenced plugins into the target location? If false, only the bare minimum will be copied (the creole.xml files, any JARs referenced therein, and any directly referenced resource files). Anything extra must be copied in separately, typically with extra <copy> tasks after the <packagegapp> one.


isCopyResourceDirs

public boolean isCopyResourceDirs()
Will the task copy the complete contents of directories containing referenced resources into the target location or just the referenced resources themselves?


setCopyResourceDirs

public void setCopyResourceDirs(boolean copyResourceDirs)
Will the task copy the complete contents of directories containing referenced resources into the target location? By default it does not do this, but only includes the directly-referenced resource files - for example, if the gapp refers to a .def file defining gazetteer lists, the lists themselves will not be included. If copyResourceDirs is false, the additional resources will need to be included using an appropriate <extraresourcespath>.


getOnUnresolved

public PackageGappTask.UnresolvedAction getOnUnresolved()
Get the action performed when there are unresolved resources.


setOnUnresolved

public void setOnUnresolved(PackageGappTask.UnresolvedAction onUnresolved)
What should we do if there are unresolved relpaths within the gapp file? By default the build will fail, but instead you can opt to have the relative paths replaced by absolute paths to the same URL, or to have the task recover by putting the files into an "application-resources" directory.


createHint

public PackageGappTask.MappingHint createHint()
Create and add the representation for a nested <hint from="X" to="Y" /> element.


addExtraResourcesPath

public void addExtraResourcesPath(org.apache.tools.ant.types.Path path)
Add a path containing extra resources that should be treated as if they had been referenced by relpaths within the gapp file. The locations to which these extra resources will be copied are determined by the plugins and mapping hints in the usual way.


execute

public void execute()
             throws org.apache.tools.ant.BuildException
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException

processExtraResourcesPaths

private void processExtraResourcesPaths(Set<URL> resources)
Process any extraresourcespath elements provided to this task and include the resources they refer to in the given set.


copyDirectories

private void copyDirectories(Map<URL,URL> copyMap,
                             boolean minimalPlugin)
Copy directories as specified by the given map.

Parameters:
copyMap - map specifying the directories to copy and the target locations to which they should be copied.
minimalPlugin - if true, treat the directory as a GATE plugin and copy just the minimal files needed for the plugin to work (creole.xml and any referenced jars).

getJars

private Set<String> getJars(URL creoleXml)
Extract the text values from any <JAR> elements contained in the referenced creole.xml file.

Returns:
a set with one element for each unique <JAR> entry in the given creole.xml.

getUnresolvedResourcesTarget

private URL getUnresolvedResourcesTarget(TreeMap<URL,URL> unresolvedResourcesSubDirs,
                                         URL unresolvedResourcesDir,
                                         URL resourceDir)
                                  throws org.apache.tools.ant.BuildException
Get a URL for a directory to which the given (unresolved) resource directory should be mapped.

Parameters:
unresolvedResourcesSubDirs - a map from URLs of directories containing unresolved resources to the URLs under the target unresolved-resources directory that they will be mapped to. This map is updated by this method.
unresolvedResourcesDir - the top-level application-resources directory in the target location.
resourceDir - a directory containing an unresolved resource.
Returns:
the URL under application-resources to which this directory should be mapped. For a resourceDir of the form .../foo, the returned URL would typically be <applicationResourcesDir>/foo, but if a different directory with the same name has already been mapped then we will return the first ..../foo-2, foo-3, etc. that is not already in use. If one of the directory's ancestors has already been mapped then we return a URL pointing to the same relative path inside that ancestor's mapping, e.g. if .../foo has already been mapped to a-r/foo-2 then .../foo/bar/baz will map to a-r/foo-2/bar/baz.
Throws:
org.apache.tools.ant.BuildException