WarTF

Build a War archive.

Task package:org.schmant.task.base
Java package:org.schmant.task.jdk.jar
Category:Archiving tasks
Since:0.5
EntityFS-aware?Yes*
Implements:ActionTaskFactory
GeneratorTaskFactory
ProcessTaskFactory
Produces:EFile (the target).
See also:JarTF
EarTF
At4JUnzipTF

Description:

Build a new War archive.

This task extends JarTF with special handling of files that should end up in or under the WEB-INF directory. See the classDirectories, libraryFiles and webXml properties.

There are two ways that a META-INF/MANIFEST.MF file can be added to the created War file. It can be set using the manifest property, or it can be copied to the War file from the sources. A manifest set using the manifest property always has precedence.

Required properties

Properties

classDirectoriestop

A collection of directories whose contents will be put in /WEB-INF/classes in the archive.

Setter method:
addClassDirectories(Object o)
Add one or several class directories.
parameters:
o – One class directory or an array or collection of class directories.
Interpreted by AbstractJavaZipTask.createIterator().
Setter method:
addClassDirectory(Object o)
Add one or several class directories.
parameters:
o – One or class directory or an array or collection of class directories.
Interpreted by AbstractJavaZipTask.createIterator().
Setter method:
clearClassDirectories()
Clear the collection of class directories.
commenttop

The War file comment.

Setter method:
setComment(String s)
Set the comment.
parameters:
s – The comment.
Default value:
Created by Schmant -- www.schmant.org
entryInfoProvidertop

A provider for extra Zip entry information for each entry (file or directory) in the archive.

Setter method:
setExtraInfoProvider(ZipEntryInfoProvider p)
Set the provider
parameters:
p – The provider.
leveltop

The compression level for entries added to the archive. The level is represented as an integer between 0 (no compression) and 9 (best compression).

Setter method:
setLevel(int l)
Set the compression level
parameters:
l – The level (0-9).
Default value:
The default compression level of the Zlib library. Currently 6, but that may change in the future.
libraryFilestop

Library files that are put in /WEB-INF/lib in the archive.

Setter method:
addLibraryFile(Object o)
Add one or several library files.
parameters:
o – One library file or an array or collection of library files.
Interpreted by AbstractJavaZipTask.createIterator().
Setter method:
addLibraryFiles(Object o)
Add one or several library files.
parameters:
o – One library file or an array or collection of library files.
Interpreted by AbstractJavaZipTask.createIterator().
Setter method:
clearLibraryFiles()
Clear the collection of library files.
logFootertop

The message that is logged to info level after the task has been successfully run.

Setter method:
setLogFooter(String s)
parameters:
s – The footer message.
Default value:
Empty (no footer message is logged.)
See also:
logHeader
logHeadertop

The message that is logged to info level before the task is run.

Setter method:
setLogHeader(String s)
parameters:
s – The header message.
Default value:
A task class specific message.
See also:
logFooter
manifesttop

The archive file's META-INF/MANIFEST.MF file

Setter method:
setManifest(Object o)
parameters:
o – A manifest.
Interpreted by InterpretAsReadableFileStrategy.
Setter method:
setManifest(Manifest m)
parameters:
m – A manifest
Default value:
See org/schmant/task/jdk/jar/default_manifest.txt in Schmant's source distribution
methodtop

The compression method for entities added to the archive.

Setter method:
setMethod(ZipCompressionMethod m)
Set the compression method represented by a ZipCompressionMethod enum.
parameters:
m – A ZipCompressionMethod representing the compression method. This is one of
  • DEFLATED
  • FILTERED
  • HUFFMAN_ONLY
  • NO_COMPRESSION

Setter method:
setMethod(int i)
Set the compression method represented by one of the Deflater constants.
parameters:
i – Set the compression method represented by one of the Deflater constants.
Default value:
DEFLATED
overwriteStrategytop

The overwrite strategy decides how the task will react if there already is an entity (file or directory) in a location where it wants to create a new entity.

If the strategy is to not overwrite existing entities, the task will fail when it cannot create the entities that it wants to create.

Non-empty directories are never overwritten, regardless of the chosen strategy.

Setter method:
setOverwrite(boolean b)
Setting this to a value of true means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.
parameters:
b – Should an existing entity be overwritten?
Setter method:
setOverwriteStrategy(OverwriteStrategy strat)
Set the overwrite strategy.
parameters:
strat – The overwrite strategy.
Default value:
DontOverwriteAndThrowException
See also:
target
reportLeveltop

This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.

Setter method:
setReportLevel(Level l)
Set the report level
parameters:
l – The new report level.
sources (required)top

A collection of files and directories that should be added to the War archive. The contents of source directories are added recursively.

There are two ways that EntityFilter:s can be used to limit which child entities of a Directory that is added:

  1. Using a DirectoryView as source: Only files and directories that match the view's filter will be added. The task will not proceed down into child directories that don't pass the filter.
  2. Using a DirectoryAndFilter as source: Only files and directories that match the filter will be added. The task will proceed down into all child directories. If an entity is added, but not its parent directory, the parent directory will be created automatically.

By default entities are added to the War file in the same location relative to the War file root that they had relative to the source directory that they were added from. For instance, the file d/d2/f will be added at the location /d2/f in the War file if d is used as a source directory. If instead d2 is used as a source directory, f will be added at the location /f.

To add entities at other locations in the tree, a source entity can be wrapped in an EntityAndAbsoluteLocation object. For instance, if the directory d containing the file d/d2/f is added with a new EntityAndAbsoluteLocation(d, new AbsoluteLocation("/foo"), the file will have the location /foo/d2/f in the War file.

Setter method:
addSource(Object o)
Add one or several sources.
parameters:
o – A source object or an array or collection of source objects.
Interpreted by AbstractJavaZipTask.createIterator().
Setter method:
addSources(Object o)
Add one or several sources.
parameters:
o – A source object or an array or collection of source objects.
Interpreted by AbstractJavaZipTask.createIterator().
Setter method:
clearSources()
Discard all sources.
Setter method:
setSource(Object o)
Set one or several sources and discard previously set sources.
parameters:
o – A source object or an array or collection of source objects.
Interpreted by AbstractJavaZipTask.createIterator().
Setter method:
setSources(Object o)
Set one or several sources and discard previously set sources.
parameters:
o – A source object or an array or collection of source objects.
Interpreted by AbstractJavaZipTask.createIterator().
target (required)top

The target War file.

Setter method:
setTarget(Object o)
parameters:
o – The target file.
Interpreted by InterpretAsFutureEntityStrategy.
See also:
overwriteStrategy
traceLoggingtop

If trace logging is enabled for a task, it reports its configuration before it is run.

Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).

Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.
parameters:
b – Enable trace logging?
webXmltop

The War archive's /WEB-INF/web.xml file.

Setter method:
setWebXml(Object o)
parameters:
o – The web.xml file.
Interpreted by AbstractJavaZipTask.createIterator().

Examples

Example 1

Create a War archive using web files from the directory web, library files from the directory lib, class files from the directory classes and an inline web.xml file. Put the War file in the directory d.

import org.entityfs.util.* import org.entityfs.util.filter.entity.EFileNameExtensionFilter import org.entityfs.util.itr.* import WarTF new WarTF(). addSource(web). // We cannot add the library file directory here since that would add the // directory itself as a subdirectory of /WEB-INF/lib. We must add each // library file instead. // This adds all Jar files in, or in a subdirectory of, lib addLibraryFiles( Iterators.list( new FilteringIterator( Directories.getDepthLastIterator(lib), new EFileNameExtensionFilter("jar", false)))). addClassDirectory(classes). setWebXml( new CharSequenceReadableFile( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + "<!DOCTYPE web-app\n" + " PUBLIC \"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN\"\n" + " \"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd\">\n" + "<web-app>\n" + " <servlet>\n" + " <servlet-class>org.example.DoerServlet</servlet-class>\n" + " <servlet-name>doer</servlet-name>\n" + " </servlet>\n" + " <servlet-mapping>\n" + " <servlet-name>doer</servlet-name>\n" + " <url-pattern>/*</url-pattern>\n" + " </servlet-mapping>\n" + "</web-app>")). setTarget(new FutureFile(d, "my.war")).run()

Example 2

Create a War archive using web files from the directory web, but filter away all .svn directories. Use library files from the directory lib, class files from the directory classes and an inline web.xml file. Put the War file in the directory d.

new WarTF(). // Use a directory view to hide all .svn directories. // If we were to use a DirectoryAndFilter instead, we would have to use // a SuperParentOrFilter for hiding the .svn // directories since that filter would be applied to all entities returned // from the iterator used internally by WarTF. (See documentation above.) addSource(web.newView(new EntityNameFilter(".svn").not())). // This adds all Jar files in lib addLibraryFiles(Directories.getAllFilesMatching(lib, "*.jar")). addClassDirectory(classes). setWebXml( new CharSequenceReadableFile( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + "<!DOCTYPE web-app\n" + " PUBLIC \"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN\"\n" + " \"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd\">\n" + "<web-app>\n" + " <servlet>\n" + " <servlet-class>org.example.DoerServlet</servlet-class>\n" + " <servlet-name>doer</servlet-name>\n" + " </servlet>\n" + " <servlet-mapping>\n" + " <servlet-name>doer</servlet-name>\n" + " <url-pattern>/*</url-pattern>\n" + " </servlet-mapping>\n" + "</web-app>")). setTarget(new FutureFile(d, "my.war")).run();


* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.