Introduction

This is a library of tasks/types to allow arbitrary resources to be, as transparently as possible, cached to the filesystem for use with tasks that require file resources: for example, many of the tasks that work with archives. You might need access to the contents of a JAR resource located at a given URL, by means of the unzip task. Alternatively, you might simply need access to a particular entry in the JAR as a zipentry. Long story short, the fscache Antlib allows you to expose a resource of arbitrary origin as a filesystem resource, and provides options which can be used or omitted to control the generation of the cache. In most cases accepting default options will cause temporary files to be generated on-demand in your system ${java.io.tmpdir} temp directory, and these files will be marked for deletion on VM exit. Other possible applications of this functionality include compiling Java source found e.g. in an archive using the javac task, or accessing nested archive resources by caching multiple levels from an outer archive file, e.g. reading a JAR resource from a WAR or, indirectly, an EAR file.

Requirements

The current version of this antlib is built against the Ant 1.8.x development version, to be found in Ant's Subversion trunk.

Where is it?

The source code for the library lives in the sandbox antlibs subspace of Ant's SVN - http://svn.apache.org/viewvc/ant/sandbox/antlibs/fscache/trunk/.

Installation

If you are building this from sources, run the antlib target and you'll get a file ant-fscache.jar.

There are several ways to use the tasks:

Tasks and Types

collect

Presents nested Resource Collections of arbitrary types such that they live in a single directory structure on the filesystem.

Attribute Description Required
basedir Directory that will hold the cache. No, default ${java.io.tmpdir}
deleteonexit Whether cached resources should be deleted on JVM exit via java.io.File#deleteOnExit(). This may or may not be reliable. No, defaults to false if basedir is specified, true otherwise.
enablemultiplemappings Whether resources will be created for all names (rather than the first only) returned from the configured File Mapper, if present. No, default false

Parameters specified as nested elements

One or more nested Resource Collections must be specified.

A nested File Mapper may be specified.

single

Filesystem cache for a single nested Resource. The specific file used can be specified explicitly or derived using the name of the nested resource.

This type inherits from the file resource type and therefore supports its same attributes in addition to the following:

Attribute Description Required
deleteonexit Whether the cached resource should be deleted on JVM exit via java.io.File#deleteOnExit(). This may or may not be reliable. No, defaults to false if basedir or file is specified, true otherwise.

Parameters specified as nested elements

A single nested Resource is required.

preload

Task to preload cached resources onto disk. This is necessary when one needs to use a filesystem cache with e.g. directory-based tasks such as Javac.

Parameters specified as nested elements

One or more nested Resource Collections must be specified. It is considered an error condition if any resource returned from these is not a cached resource.