org.apache.tools.ant.taskdefs.optional.ejb
Class EjbJar

java.lang.Object
  |
  +--org.apache.tools.ant.Task
        |
        +--org.apache.tools.ant.taskdefs.MatchingTask
              |
              +--org.apache.tools.ant.taskdefs.optional.ejb.EjbJar

public class EjbJar
extends MatchingTask

Provides automated ejb jar file creation for ant. Extends the MatchingTask class provided in the default ant distribution to provide a directory scanning EJB jarfile generator.

The task works by taking the deployment descriptors one at a time and parsing them to locate the names of the classes which should be placed in the jar. The classnames are translated to java.io.Files by replacing periods with File.separatorChar and resolving the generated filename as a relative path under the srcdir attribute. All necessary files are then assembled into a jarfile. One jarfile is constructed for each deployment descriptor found.

Functionality is currently provided for standard EJB1.1 jars and Weblogic 5.1 jars. The weblogic deployment descriptors, used in constructing the Weblogic jar, are located based on a simple naming convention. The name of the standard deployment descriptor is taken upto the first instance of a String, specified by the attribute basenameterminator, and then the regular Weblogic descriptor name is appended. For example if basenameterminator is set to '-', its default value, and a standard descriptor is called Foo-ejb-jar.xml then the files Foo-weblogic-ejb-jar.xml and Foo-weblogic-cmp-rdbms-jar.xml will be looked for, and if found, included in the jarfile.

Attributes and setter methods are provided to support optional generation of Weblogic5.1 jars, optional deletion of generic jar files, setting alternate values for basenameterminator, and setting the strings to append to the names of the generated jarfiles.

Author:
Tim Fennell

Inner Class Summary
protected  class EjbJar.DescriptorHandler
          Inner class used by EjbJar to facilitate the parsing of deployment descriptors and the capture of appropriate information.
 
Inner classes inherited from class org.apache.tools.ant.taskdefs.MatchingTask
MatchingTask.NameEntry
 
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
excludeList, includeList, useDefaultExcludes
 
Fields inherited from class org.apache.tools.ant.Task
description, location, project, target, taskName, taskType
 
Constructor Summary
EjbJar()
           
 
Method Summary
protected  void addFileToJar(java.util.jar.JarOutputStream jStream, java.io.FileInputStream iStream, java.lang.String filename)
          Utility method that encapsulates the logic of adding a file entry to a .jar file.
 void buildWeblogicJar(java.io.File sourceJar, java.io.File destJar)
           
 void execute()
          Invoked by Ant after the task is prepared, when it is ready to execute this task.
 void setBasenameterminator(java.lang.String inValue)
          Setter used to store the value of basenameterminator
 void setDestdir(java.lang.String inDir)
          Setter used to store the value of destination directory prior to execute() being called.
 void setGenerateweblogic(java.lang.String inValue)
          Setter used to store the value of generateweblogic.
 void setGenericjarsuffix(java.lang.String inString)
          Setter used to store the suffix for the generated jar file.
 void setKeepgeneric(java.lang.String inValue)
          Setter used to store the value of keepgeneric
 void setSrcdir(java.lang.String inDir)
          Setter used to store the value of srcdir prior to execute() being called.
 void setWeblogicjarsuffix(java.lang.String inString)
          Setter used to store the suffix for the generated weblogic jar file.
 void writeJar(java.io.File jarfile, java.util.Hashtable files)
          Method used to encapsulate the writing of the JAR file.
 
Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
createExclude, createInclude, getDirectoryScanner, getProperty, setDefaultexcludes, setExcludes, setExcludesfile, setIgnore, setIncludes, setIncludesfile, setItems
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getProject, getTaskName, init, log, log, setDescription, setLocation, setOwningTarget, setTaskName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EjbJar

public EjbJar()
Method Detail

setSrcdir

public void setSrcdir(java.lang.String inDir)
Setter used to store the value of srcdir prior to execute() being called.
Parameters:
inDir - The string indicating the source directory.

setDestdir

public void setDestdir(java.lang.String inDir)
Setter used to store the value of destination directory prior to execute() being called.
Parameters:
inFile - The string indicating the source directory.

setGenericjarsuffix

public void setGenericjarsuffix(java.lang.String inString)
Setter used to store the suffix for the generated jar file.
Parameters:
inString - the string to use as the suffix.

setWeblogicjarsuffix

public void setWeblogicjarsuffix(java.lang.String inString)
Setter used to store the suffix for the generated weblogic jar file.
Parameters:
inString - the string to use as the suffix.

setGenerateweblogic

public void setGenerateweblogic(java.lang.String inValue)
Setter used to store the value of generateweblogic.
Parameters:
inValue - a string, either 'true' or 'false'.

setKeepgeneric

public void setKeepgeneric(java.lang.String inValue)
Setter used to store the value of keepgeneric
Parameters:
inValue - a string, either 'true' or 'false'.

setBasenameterminator

public void setBasenameterminator(java.lang.String inValue)
Setter used to store the value of basenameterminator
Parameters:
inValue - a string which marks the end of the basename.

addFileToJar

protected void addFileToJar(java.util.jar.JarOutputStream jStream,
                            java.io.FileInputStream iStream,
                            java.lang.String filename)
                     throws BuildException
Utility method that encapsulates the logic of adding a file entry to a .jar file. Used by execute() to add entries to the jar file as it is constructed.
Parameters:
jStream - A JarOutputStream into which to write the jar entry.
iStream - A FileInputStream from which to read the contents the file being added.
filename - A String representing the name, including all relevant path information, that should be stored for the entry being added.

writeJar

public void writeJar(java.io.File jarfile,
                     java.util.Hashtable files)
              throws BuildException
Method used to encapsulate the writing of the JAR file. Iterates over the filenames/java.io.Files in the Hashtable stored on the instance variable ejbFiles.

buildWeblogicJar

public void buildWeblogicJar(java.io.File sourceJar,
                             java.io.File destJar)

execute

public void execute()
             throws BuildException
Invoked by Ant after the task is prepared, when it is ready to execute this task. Parses the XML deployment descriptor to acquire the list of files, then constructs the destination jar file (first deleting it if it already exists) from the list of classfiles encountered and the descriptor itself. File will be of the expected format with classes under full package hierarchies and the descriptor in META-INF/ejb-jar.xml
Overrides:
execute in class Task
Throws:
BuildException - thrown whenever a problem is encountered that cannot be recovered from, to signal to ant that a major problem occurred within this task.


Copyright © 2000 Apache Software Foundation. All Rights Reserved.