com.threerings.cast.bundle.tools
Class ComponentBundlerTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by com.threerings.cast.bundle.tools.ComponentBundlerTask
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
DirectoryComponentBundlerTask

public class ComponentBundlerTask
extends Task

Ant task for creating component bundles. This task must be configured with a number of parameters:

 target=[path to bundle file, which will be created]
 mapfile=[path to the component map file which maintains a mapping from
          component id to component class/name, it will be created the
          first time and updated as new components are mapped]
 
It should also contain one or more nested <fileset> elements that enumerate the action tileset images that should be included in the component bundle.


Nested Class Summary
protected static class ComponentBundlerTask.HashMapIDBroker
           
 
Field Summary
protected  File _actionDef
          The path to our action tilesets definition file.
protected  ArrayList<FileSet> _filesets
          A list of filesets that contain tile images.
protected  boolean _keepRawPngs
          Whether we should keep raw pngs rather than reencoding them in the bundle.
protected  File _mapfile
          The path to our component map file.
protected  String _root
          The component directory root.
protected  File _target
          The path to our component bundle file.
protected  boolean _uncompressed
          Whether we should keep the bundle jars uncompressed rather than zipped.
protected static String[] AUX_EXTS
          Used to process auxilliary tilesets.
protected static String SEP_STR
          Used to separate keys and values in the map file.
 
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
ComponentBundlerTask()
           
 
Method Summary
 void addFileset(FileSet set)
          Adds a nested <fileset> element.
protected  String composePath(String[] info, String extension)
          Composes a triplet of [class, name, action] into the path that should be supplied to the JarEntry that contains the associated image data.
protected  OutputStream createOutputStream(File target)
          Creates the base output stream to which to write our bundle's files.
protected  String[] decomposePath(String path)
          Decomposes the full path to a component image into a [class, name, action] triplet.
protected  void ensureSet(Object value, String errmsg)
           
 void execute()
          Performs the actual work of the task.
protected  long getNewestDate(ArrayList<Object> sources)
           
protected  long getNewestDate(Object source)
           
protected  ComponentBundlerTask.HashMapIDBroker loadBroker(File mapfile)
          Loads the hashmap ID broker from its persistent representation in the specified file.
protected  OutputStream nextEntry(OutputStream lastEntry, String path)
          Advances to the next named entry in the bundle and returns the stream to which to write that entry.
protected  void processComponent(String[] info, TileSet aset, File cfile, OutputStream fout, long newest)
           
protected  void saveBroker(File mapfile, ComponentIDBroker broker)
          Stores a persistent representation of the supplied hashmap ID broker in the specified file.
 void setActiondef(File actiondef)
          Sets the path to the action tilesets definition file.
 void setKeepRawPngs(boolean keep)
          Note whether we are supposed to use the raw png files directly in the bundle or try to re-encode them.
 void setMapfile(File mapfile)
          Sets the path to the component map file that we'll use to obtain component ids for the bundled components.
 void setRoot(File root)
          Sets the root path which will be stripped from the image paths prior to parsing them to obtain the component class, type and action names.
 void setTarget(File target)
          Sets the path to the bundle file that we'll be creating.
 void setUncompressed(boolean uncompressed)
          Note whether we are supposed to leave the jar uncompressed rather than the normal process of zipping it at maximum compression.
protected  boolean skipEntry(String path, long newest)
          Returns whether we should skip the specified entry in the bundle, presumably if it was already created and up to date.
protected  boolean skipIfTargetNewer()
          Returns whether we should skip updating the bundle if the target is newer than any component.
protected  TrimmedTileSet trim(TileSet aset, OutputStream fout)
          Converts the tileset to a trimmed tile set and saves it at the specified location.
 
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

_target

protected File _target
The path to our component bundle file.


_mapfile

protected File _mapfile
The path to our component map file.


_actionDef

protected File _actionDef
The path to our action tilesets definition file.


_root

protected String _root
The component directory root.


_filesets

protected ArrayList<FileSet> _filesets
A list of filesets that contain tile images.


_keepRawPngs

protected boolean _keepRawPngs
Whether we should keep raw pngs rather than reencoding them in the bundle.


_uncompressed

protected boolean _uncompressed
Whether we should keep the bundle jars uncompressed rather than zipped.


SEP_STR

protected static final String SEP_STR
Used to separate keys and values in the map file.

See Also:
Constant Field Values

AUX_EXTS

protected static final String[] AUX_EXTS
Used to process auxilliary tilesets.

Constructor Detail

ComponentBundlerTask

public ComponentBundlerTask()
Method Detail

setTarget

public void setTarget(File target)
Sets the path to the bundle file that we'll be creating.


setMapfile

public void setMapfile(File mapfile)
Sets the path to the component map file that we'll use to obtain component ids for the bundled components.


setActiondef

public void setActiondef(File actiondef)
Sets the path to the action tilesets definition file.


setRoot

public void setRoot(File root)
Sets the root path which will be stripped from the image paths prior to parsing them to obtain the component class, type and action names.


addFileset

public void addFileset(FileSet set)
Adds a nested <fileset> element.


setKeepRawPngs

public void setKeepRawPngs(boolean keep)
Note whether we are supposed to use the raw png files directly in the bundle or try to re-encode them.


setUncompressed

public void setUncompressed(boolean uncompressed)
Note whether we are supposed to leave the jar uncompressed rather than the normal process of zipping it at maximum compression.


execute

public void execute()
             throws BuildException
Performs the actual work of the task.

Overrides:
execute in class Task
Throws:
BuildException

processComponent

protected void processComponent(String[] info,
                                TileSet aset,
                                File cfile,
                                OutputStream fout,
                                long newest)
                         throws IOException,
                                BuildException
Throws:
IOException
BuildException

getNewestDate

protected long getNewestDate(ArrayList<Object> sources)

getNewestDate

protected long getNewestDate(Object source)

skipIfTargetNewer

protected boolean skipIfTargetNewer()
Returns whether we should skip updating the bundle if the target is newer than any component.


decomposePath

protected String[] decomposePath(String path)
                          throws BuildException
Decomposes the full path to a component image into a [class, name, action] triplet.

Throws:
BuildException

composePath

protected String composePath(String[] info,
                             String extension)
Composes a triplet of [class, name, action] into the path that should be supplied to the JarEntry that contains the associated image data.


ensureSet

protected void ensureSet(Object value,
                         String errmsg)
                  throws BuildException
Throws:
BuildException

createOutputStream

protected OutputStream createOutputStream(File target)
                                   throws IOException
Creates the base output stream to which to write our bundle's files.

Throws:
IOException

nextEntry

protected OutputStream nextEntry(OutputStream lastEntry,
                                 String path)
                          throws IOException
Advances to the next named entry in the bundle and returns the stream to which to write that entry.

Throws:
IOException

skipEntry

protected boolean skipEntry(String path,
                            long newest)
Returns whether we should skip the specified entry in the bundle, presumably if it was already created and up to date.


trim

protected TrimmedTileSet trim(TileSet aset,
                              OutputStream fout)
                       throws IOException
Converts the tileset to a trimmed tile set and saves it at the specified location.

Throws:
IOException

loadBroker

protected ComponentBundlerTask.HashMapIDBroker loadBroker(File mapfile)
                                                   throws BuildException
Loads the hashmap ID broker from its persistent representation in the specified file.

Throws:
BuildException

saveBroker

protected void saveBroker(File mapfile,
                          ComponentIDBroker broker)
                   throws BuildException
Stores a persistent representation of the supplied hashmap ID broker in the specified file.

Throws:
BuildException