org.apache.tools.ant.types
Class Path

java.lang.Object
  |
  +--org.apache.tools.ant.types.DataType
        |
        +--org.apache.tools.ant.types.Path
All Implemented Interfaces:
java.lang.Cloneable

public class Path
extends DataType
implements java.lang.Cloneable

This object represents a path as used by CLASSPATH or PATH environment variable.

<sometask>
  <somepath>
    <pathelement location="/path/to/file.jar" />
    <pathelement path="/path/to/file2.jar:/path/to/class2;/path/to/class3" />
    <pathelement location="/path/to/file3.jar" />
    <pathelement location="/path/to/file4.jar" />
  </somepath>
</sometask>

The object implemention sometask must provide a method called createSomepath which returns an instance of Path. Nested path definitions are handled by the Path object and must be labeled pathelement.

The path element takes a parameter path which will be parsed and split into single elements. It will usually be used to define a path from an environment variable.

Author:
Thomas.Haas@softwired-inc.com, Stefan Bodewig

Inner Class Summary
 class Path.PathElement
          Helper class, holds the nested values.
 
Field Summary
static Path systemClasspath
           
 
Fields inherited from class org.apache.tools.ant.types.DataType
checked, description, ref
 
Constructor Summary
Path(Project project)
           
Path(Project p, java.lang.String path)
          Invoked by IntrospectionHelper for setXXX(Path p) attribute setters.
 
Method Summary
 void addExisting(Path source)
          Adds the components on the given path which exist to this Path.
 void addFileset(FileSet fs)
          Adds a nested element.
 void append(Path other)
          Append the contents of the other Path instance to this.
 java.lang.Object clone()
          Return a Path that holds the same elements as this instance.
 Path concatSystemClasspath()
          Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using "last" as default value.
 Path concatSystemClasspath(java.lang.String defValue)
          Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using the supplied value if ${build.sysclasspath} has not been set.
 Path createPath()
          Creates a nested element.
 Path.PathElement createPathElement()
          Creates the nested element.
protected  void dieOnCircularReference(java.util.Stack stk, Project p)
          Overrides the version of DataType to recurse on all DataType child elements that may have been added.
 java.lang.String[] list()
          Returns all path elements defined by this and nested path objects.
 void setLocation(java.io.File location)
          Adds a element definition to the path.
 void setPath(java.lang.String path)
          Parses a path definition and creates single PathElements.
 void setRefid(Reference r)
          Makes this instance in effect a reference to another Path instance.
 int size()
          How many parts does this Path instance consist of.
 java.lang.String toString()
          Returns a textual representation of the path, which can be used as CLASSPATH or PATH environment variable definition.
static java.lang.String translateFile(java.lang.String source)
          Returns its argument with all file separator characters replaced so that they match the local OS conventions.
protected static boolean translateFileSep(java.lang.StringBuffer buffer, int pos)
          Translates all occurrences of / or \ to correct separator of the current platform and returns whether it had to do any replacements.
static java.lang.String[] translatePath(Project project, java.lang.String source)
          Splits a PATH (with : or ; as separators) into its parts.
 
Methods inherited from class org.apache.tools.ant.types.DataType
circularReference, getDescription, isReference, noChildrenAllowed, setDescription, tooManyAttributes
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

systemClasspath

public static Path systemClasspath
Constructor Detail

Path

public Path(Project p,
            java.lang.String path)
Invoked by IntrospectionHelper for setXXX(Path p) attribute setters.

Path

public Path(Project project)
Method Detail

setLocation

public void setLocation(java.io.File location)
                 throws BuildException
Adds a element definition to the path.
Parameters:
location - the location of the element to add (must not be null nor empty.

setPath

public void setPath(java.lang.String path)
             throws BuildException
Parses a path definition and creates single PathElements.
Parameters:
path - the path definition.

setRefid

public void setRefid(Reference r)
              throws BuildException
Makes this instance in effect a reference to another Path instance.

You must not set another attribute or nest elements inside this element if you make it a reference.

Overrides:
setRefid in class DataType

createPathElement

public Path.PathElement createPathElement()
                                   throws BuildException
Creates the nested element.

addFileset

public void addFileset(FileSet fs)
                throws BuildException
Adds a nested element.

createPath

public Path createPath()
                throws BuildException
Creates a nested element.

append

public void append(Path other)
Append the contents of the other Path instance to this.

addExisting

public void addExisting(Path source)
Adds the components on the given path which exist to this Path. Components that don't exist, aren't added.
Parameters:
source - - source path whose components are examined for existence

list

public java.lang.String[] list()
Returns all path elements defined by this and nested path objects.
Returns:
list of path elements.

toString

public java.lang.String toString()
Returns a textual representation of the path, which can be used as CLASSPATH or PATH environment variable definition.
Overrides:
toString in class java.lang.Object
Returns:
a textual representation of the path.

translatePath

public static java.lang.String[] translatePath(Project project,
                                               java.lang.String source)
Splits a PATH (with : or ; as separators) into its parts.

translateFile

public static java.lang.String translateFile(java.lang.String source)
Returns its argument with all file separator characters replaced so that they match the local OS conventions.

translateFileSep

protected static boolean translateFileSep(java.lang.StringBuffer buffer,
                                          int pos)
Translates all occurrences of / or \ to correct separator of the current platform and returns whether it had to do any replacements.

size

public int size()
How many parts does this Path instance consist of.

clone

public java.lang.Object clone()
Return a Path that holds the same elements as this instance.
Overrides:
clone in class java.lang.Object

dieOnCircularReference

protected void dieOnCircularReference(java.util.Stack stk,
                                      Project p)
                               throws BuildException
Overrides the version of DataType to recurse on all DataType child elements that may have been added.
Overrides:
dieOnCircularReference in class DataType

concatSystemClasspath

public Path concatSystemClasspath()
Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using "last" as default value.

concatSystemClasspath

public Path concatSystemClasspath(java.lang.String defValue)
Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using the supplied value if ${build.sysclasspath} has not been set.


Copyright ? 2000 Apache Software Foundation. All Rights Reserved.