org.jini.project.example.jade.tools
Class ClassDepAndJarTask

java.lang.Object
  |
  +--org.apache.tools.ant.Task
        |
        +--org.jini.project.example.jade.tools.ClassDepAndJarTask

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

ClassDepAndJarTask is an Ant Task that will create a jar file from the list of classes generated by the ClassDep tool that is part of the Jini[tm] Technology SDK. In particular it:

  1. Searches and extracts classes directly from jar files that are specified in the classpath attribute. Thus it is not necessary to unjar libraries in order to include elements (classes).
  2. Creates a Jar file directly; it is not an extension of the Ant Jar task. (See Limitations below.)
  3. Additional elements can be included in the jar file by using nested Fileset elements.

For details on how ClassDep works and the meaning and usage of its parameters, see its documentation.

The following table shows the ClassDepAndJarTask attributes and their corresponding ClassDep parameters.

Attribute Parameter Comment
classpath-cp
in-in
out-out
files-files
edges-edges
outer-outer
hide-hide
prune-prune
show-show
skip-skip
tell-tell
topclassclass
manifest
jarfileRequired
debugSet ="true" for additional informationn

Elements:

ClassDepAndJar supports Ant fileset's as elements. Use one or more of these elements to specify files, other than those generated by ClassDep, that should be added to the jarfile - for example, GIF files, etc. See the Ant documentation for a description of Filesets.

Limitations:

  1. Because this Task does not extend JarTask you can not use all of the various attributes that are associated with the the Jar Ant Task.
  2. Jar files are always recreated - they are never updated.

Usage:

To run properly, the tools.jar file in the Jini technology library must be reachable by Ant. This is where the ClassDep is stored. This can easily be done by adding it's directory (usually jini1_1/lib) to the classpath of the Ant program.

The following must be included in your build file in order to use the ClassDepAndJarTask. The classpath attribute needs to point where the ClassDepAndJarTask class is located. Alternatively, the task can be "installed" as an Ant Task; please refer to the Ant documentation for instructions.

<taskdef name="classdepandjar" 
classname="org.jini.project.example.jade.tools.ClassDepAndJarTask"
classpath="directory/classdepandjar.jar " />
 

The following two targets illustrate how to use the ClassDepAndJar task. The hello.jar target specifies a manifest. The hello-dl.jar target specifies additional elements to add to the jarfile - a gif file, for example.

<target name="hello.jar" depends="rmics" >
<classdepandjar jarfile="${lib}/hello.jar" files="true" 
manifest="${src}/org/jini/project/example/jade/serviceimpl/example/hello.mf" >
<classpath refid="project.path" />
<in name="net.jini" />
<in name="org.jini" />
<in name="com.sun.jini" />
<topclass name="org.jini.project.example.jade.serviceimpl.example.StartHelloService" />
<topclass name="org.jini.project.example.jade.serviceimpl.example.HelloImpl_Stub" />
<topclass name="net.jini.lookup.JoinManager" />
</classdepandjar>
</target>

<target name="hello-dl.jar" depends="rmics" >
<classdepandjar jarfile="${lib}/hello-dl.jar" files="true" >
<classpath refid="project.path" />
<in name="net.jini" />
<in name="org.jini" />
<in name="com.sun.jini" />
<topclass name="org.jini.project.example.jade.service.example.Hello" />
<topclass name="org.jini.project.example.jade.serviceimpl.example.HelloImpl_Stub" />
<topclass name="net.jini.lookup.entry.Name" />
<topclass name="net.jini.lookup.entry.ServiceInfo" />
<topclass name="net.jini.lookup.entry.UIDescriptor" />
<fileset dir="${src}"
includes="org/jini/project/example/jade/action/example/hello*.gif" />
<fileset dir="${classes}"
includes="org/jini/project/example/jade/action/example/*Hello*.class" />
</classdepandjar>
</target>

 

Acknowledgements:

Steven Harris wrote the class that does all the work: ClassDepJarFactory. His code utilizes some Jar support classes developed by Jimmy Torres.
Jim Clarke wrote a ClassDepTask that served as a guide for writing this Ant Task. The author has used his ClassDepTask.

Version:
1.0
Author:
Peter C. Marks (Assembler)

Inner Class Summary
protected  class ClassDepAndJarTask.Argument
          A class to handle the name attribute of child elements: "name = value" and "name = value1 <delimiter> value2 <delimiter> ...
 
Fields inherited from class org.apache.tools.ant.Task
description, location, project, target, taskName, taskType, wrapper
 
Constructor Summary
ClassDepAndJarTask()
          Creates a new ClassDepAndJarTask
 
Method Summary
 void addFileset(org.apache.tools.ant.types.FileSet fs)
          Append another fileset
 org.apache.tools.ant.types.Path createClasspath()
          Maybe create a nested classpath element
 ClassDepAndJarTask.Argument createHide()
          Creator for hide element.
 ClassDepAndJarTask.Argument createIn()
          Creator for in element.
 ClassDepAndJarTask.Argument createOut()
          Creator for out element.
 ClassDepAndJarTask.Argument createPrune()
          Creator for prune element.
 ClassDepAndJarTask.Argument createShow()
          Creator for show element.
 ClassDepAndJarTask.Argument createSkip()
          Creator for skip element.
 ClassDepAndJarTask.Argument createTell()
          Creator for tell element.
 ClassDepAndJarTask.Argument createTopclass()
          Creator for topclass element.
 void execute()
          Ant calls this execute() method to have the task do its thing.
protected  java.lang.String[] getClassDepArgs()
          Transform all the Ant task attributes and elements into an array of Strings that we can feed to ClassDep
protected  org.apache.tools.ant.types.Path getClasspath()
          Getter for classpath.
 java.lang.String getDescription()
          Return a text description of this Task.
 java.io.File getJarfile()
          Getter for the jarfile attribute
 java.util.jar.Manifest getManifest()
          Getter for the manifest attribute
 boolean isDebug()
          Getter for debug attribute
 boolean isEdges()
          Getter for edges.
 boolean isFiles()
          Getter for files
 boolean isOuter()
          Getter for outer.
 void setClasspath(org.apache.tools.ant.types.Path classpath)
          Set the classpath to be used for this compilation
 void setClasspathRef(org.apache.tools.ant.types.Reference ref)
          Adds a reference to a classpath defined elsewhere.
 void setDebug(boolean debug)
          Setter for debug attribute
 void setEdges(boolean edges)
          Set the edges attribute
 void setFiles(boolean files)
          Set the files attribute
 void setHide(java.lang.String arg)
          Set the hide element
 void setIn(java.lang.String arg)
          Set the in element.
 void setJarfile(java.io.File jarfile)
          Set the jarfile attribute
 void setManifest(java.io.File manifestFile)
          Set the manifest attribute
 void setOut(java.lang.String arg)
          Set the out element.
 void setOuter(boolean outer)
          Set the outer attribute
 void setPrune(java.lang.String arg)
          Set the prune element.
 void setShow(java.lang.String arg)
          Set the show element.
 void setSkip(java.lang.String arg)
          Set the skip element.
 void setTell(java.lang.String arg)
          Set the tell element.
 void setTopclass(java.lang.String arg)
          Set the topclass element.
 
Methods inherited from class org.apache.tools.ant.Task
getLocation, getOwningTarget, getProject, getRuntimeConfigurableWrapper, getTaskName, init, log, log, maybeConfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassDepAndJarTask

public ClassDepAndJarTask()
Creates a new ClassDepAndJarTask
Method Detail

setClasspath

public void setClasspath(org.apache.tools.ant.types.Path classpath)
Set the classpath to be used for this compilation
Parameters:
classpath - The classpath to store.

createClasspath

public org.apache.tools.ant.types.Path createClasspath()
Maybe create a nested classpath element
Returns:
The classpath

setClasspathRef

public void setClasspathRef(org.apache.tools.ant.types.Reference ref)
Adds a reference to a classpath defined elsewhere.
Parameters:
ref - An Ant reference to a path

getClasspath

protected org.apache.tools.ant.types.Path getClasspath()
Getter for classpath.
Returns:
The stored classpath

setEdges

public void setEdges(boolean edges)
Set the edges attribute
Parameters:
edges - classes outside of namespaces

isEdges

public boolean isEdges()
Getter for edges.
Returns:
if edges has been specified

setFiles

public void setFiles(boolean files)
Set the files attribute
Parameters:
files - true or false

isFiles

public boolean isFiles()
Getter for files
Returns:
true or false

createHide

public ClassDepAndJarTask.Argument createHide()
Creator for hide element.

setHide

public void setHide(java.lang.String arg)
Set the hide element

createIn

public ClassDepAndJarTask.Argument createIn()
Creator for in element.

setIn

public void setIn(java.lang.String arg)
Set the in element.

setJarfile

public void setJarfile(java.io.File jarfile)
Set the jarfile attribute

getJarfile

public java.io.File getJarfile()
Getter for the jarfile attribute

setManifest

public void setManifest(java.io.File manifestFile)
Set the manifest attribute

getManifest

public java.util.jar.Manifest getManifest()
Getter for the manifest attribute

createOut

public ClassDepAndJarTask.Argument createOut()
Creator for out element.

setOut

public void setOut(java.lang.String arg)
Set the out element.

setOuter

public void setOuter(boolean outer)
Set the outer attribute

isOuter

public boolean isOuter()
Getter for outer.

createPrune

public ClassDepAndJarTask.Argument createPrune()
Creator for prune element.

setPrune

public void setPrune(java.lang.String arg)
Set the prune element.

createShow

public ClassDepAndJarTask.Argument createShow()
Creator for show element.

setShow

public void setShow(java.lang.String arg)
Set the show element.

createSkip

public ClassDepAndJarTask.Argument createSkip()
Creator for skip element.

setSkip

public void setSkip(java.lang.String arg)
Set the skip element.

createTell

public ClassDepAndJarTask.Argument createTell()
Creator for tell element.

setTell

public void setTell(java.lang.String arg)
Set the tell element.

createTopclass

public ClassDepAndJarTask.Argument createTopclass()
Creator for topclass element.

setTopclass

public void setTopclass(java.lang.String arg)
Set the topclass element.
Parameters:
arg - Name of a class

addFileset

public void addFileset(org.apache.tools.ant.types.FileSet fs)
Append another fileset
Parameters:
fs - Additional fileset

getClassDepArgs

protected java.lang.String[] getClassDepArgs()
Transform all the Ant task attributes and elements into an array of Strings that we can feed to ClassDep
Returns:
Ant attributes in array format

isDebug

public boolean isDebug()
Getter for debug attribute
Returns:
To debug or not to debug

setDebug

public void setDebug(boolean debug)
Setter for debug attribute
Parameters:
debug - true or false

getDescription

public java.lang.String getDescription()
Return a text description of this Task.
Overrides:
getDescription in class org.apache.tools.ant.Task
Returns:
Description of this Task.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Ant calls this execute() method to have the task do its thing. Gather arguments given to us by Ant and have a ClassDepJarFileFactory run ClassDep and then create a jar file. Finally, add any files specified via fileset elements.
Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - Thrown when an error occurs within the task.


Copyright (c) 2001 Sun MicroSystems Inc. All Rights Reserved.