org.apache.tools.ant.types

Class Path

public class Path extends DataType implements 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.

Nested Class Summary
classPath.PathElement
Helper class, holds the nested <pathelement> values.
Field Summary
static PathsystemBootClasspath
The system bootclassspath as a Path object.
static PathsystemClasspath
The system classspath as a Path object
Constructor Summary
Path(Project p, String path)
Invoked by IntrospectionHelper for setXXX(Path p) attribute setters.
Path(Project project)
Construct an empty Path.
Method Summary
voidadd(Path path)
Adds a nested path
voidaddDirset(DirSet dset)
Adds a nested <dirset> element.
voidaddExisting(Path source)
Adds the components on the given path which exist to this Path.
voidaddExisting(Path source, boolean tryUserDir)
Same as addExisting, but support classpath behavior if tryUserDir is true.
voidaddExtdirs(Path extdirs)
Emulation of extdirs feature in java >= 1.2.
voidaddFilelist(FileList fl)
Adds a nested <filelist> element.
voidaddFileset(FileSet fs)
Adds a nested <fileset> element.
voidaddJavaRuntime()
Add the Java Runtime classes to this Path instance.
voidappend(Path other)
Append the contents of the other Path instance to this.
Objectclone()
Return a Path that holds the same elements as this instance.
PathconcatSystemClasspath()
Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using "last" as default value.
PathconcatSystemClasspath(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.
PathcreatePath()
Creates a nested <path> element.
Path.PathElementcreatePathElement()
Creates the nested <pathelement> element.
protected voiddieOnCircularReference(Stack stk, Project p)
Overrides the version of DataType to recurse on all DataType child elements that may have been added.
String[]list()
Returns all path elements defined by this and nested path objects.
voidsetLocation(File location)
Adds a element definition to the path.
voidsetPath(String path)
Parses a path definition and creates single PathElements.
voidsetRefid(Reference r)
Makes this instance in effect a reference to another Path instance.
intsize()
How many parts does this Path instance consist of.
StringtoString()
Returns a textual representation of the path, which can be used as CLASSPATH or PATH environment variable definition.
static StringtranslateFile(String source)
Returns its argument with all file separator characters replaced so that they match the local OS conventions.
protected static booleantranslateFileSep(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 String[]translatePath(Project project, String source)
Splits a PATH (with : or ; as separators) into its parts.

Field Detail

systemBootClasspath

public static Path systemBootClasspath
The system bootclassspath as a Path object.

Since: Ant 1.6.2

systemClasspath

public static Path systemClasspath
The system classspath as a Path object

Constructor Detail

Path

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

Parameters: project the Project for this path. path the String path definition.

Path

public Path(Project project)
Construct an empty Path.

Parameters: project the Project for this path.

Method Detail

add

public void add(Path path)
Adds a nested path

Since: Ant 1.6

addDirset

public void addDirset(DirSet dset)
Adds a nested <dirset> element.

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

addExisting

public void addExisting(Path source, boolean tryUserDir)
Same as addExisting, but support classpath behavior if tryUserDir is true. Classpaths are relative to user dir, not the project base. That used to break jspc test

Parameters: source tryUserDir

addExtdirs

public void addExtdirs(Path extdirs)
Emulation of extdirs feature in java >= 1.2. This method adds all files in the given directories (but not in sub-directories!) to the classpath, so that you don't have to specify them all one by one.

Parameters: extdirs - Path to append files to

addFilelist

public void addFilelist(FileList fl)
Adds a nested <filelist> element.

addFileset

public void addFileset(FileSet fs)
Adds a nested <fileset> element.

addJavaRuntime

public void addJavaRuntime()
Add the Java Runtime classes to this Path instance.

append

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

clone

public Object clone()
Return a Path that holds the same elements as this instance.

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(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.

createPath

public Path createPath()
Creates a nested <path> element.

createPathElement

public Path.PathElement createPathElement()
Creates the nested <pathelement> element.

dieOnCircularReference

protected void dieOnCircularReference(Stack stk, Project p)
Overrides the version of DataType to recurse on all DataType child elements that may have been added.

list

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

Returns: list of path elements.

setLocation

public void setLocation(File location)
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(String path)
Parses a path definition and creates single PathElements.

Parameters: path the String path definition.

setRefid

public void setRefid(Reference r)
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.

size

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

toString

public String toString()
Returns a textual representation of the path, which can be used as CLASSPATH or PATH environment variable definition.

Returns: a textual representation of the path.

translateFile

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

translateFileSep

protected static boolean translateFileSep(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.

translatePath

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