Package org.apache.tools.ant.types
Class Path
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.types.DataType
org.apache.tools.ant.types.Path
- All Implemented Interfaces:
Cloneable
,Iterable<Resource>
,ResourceCollection
This object represents a path as used by CLASSPATH or PATH
environment variable. A path might also be described as a collection
of unique filesystem resources.
<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 implementation 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
Modifier and TypeClassDescriptionclass
Helper class, holds the nested<pathelement>
values. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Path
The system bootclasspath as a Path object.static Path
The system classpath as a Path objectFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a nested pathvoid
Add a nestedResourceCollection
.void
Adds a nested<dirset>
element.void
addExisting
(Path source) Adds the components on the given path which exist to this Path.void
addExisting
(Path source, boolean tryUserDir) Same as addExisting, but support classpath behavior if tryUserDir is true.void
addExtdirs
(Path extdirs) Emulation of extdirs feature in Java >= 1.2.void
addFilelist
(FileList fl) Adds a nested<filelist>
element.void
addFileset
(FileSet fs) Adds a nested<fileset>
element.void
Add the Java Runtime classes to this Path instance.void
Append the contents of the other Path instance to this.protected ResourceCollection
Verify the specified ResourceCollection is filesystem-only.clone()
Clone this Path.concatSystemBootClasspath
(String defValue) Concatenates the system boot class path in the order specified by the ${build.sysclasspath} property - using the supplied value if ${build.sysclasspath} has not been set.Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using "last" as default value.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.Creates a nested<path>
element.Creates the nested<pathelement>
element.protected boolean
Helps determine whether to preserve BC by callinglist()
on subclasses.protected void
dieOnCircularReference
(Stack<Object> stk, Project p) Overrides the version of DataType to recurse on all DataType child elements that may have been added.boolean
Fulfill the ResourceCollection contract.iterator()
Fulfill the ResourceCollection contract.String[]
list()
Returns all path elements defined by this and nested path objects.void
setCache
(boolean b) Whether to cache the current path.void
setLocation
(File location) Adds a element definition to the path.void
Parses a path definition and creates single PathElements.void
Makes this instance in effect a reference to another Path instance.int
size()
Fulfill the ResourceCollection contract.toString()
Returns a textual representation of the path, which can be used as CLASSPATH or PATH environment variable definition.static String
translateFile
(String source) Returns its argument with all file separator characters replaced so that they match the local OS conventions.protected static boolean
translateFileSep
(StringBuffer buffer, int pos) Translates occurrences at a position of / or \ to correct separator of the current platform and returns whether it had to do a replacement.static String[]
translatePath
(Project project, String source) Splits a PATH (with : or ; as separators) into its parts.Methods inherited from class org.apache.tools.ant.types.DataType
checkAttributesAllowed, checkChildrenAllowed, circularReference, dieOnCircularReference, dieOnCircularReference, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getCheckedRef, getDataTypeName, getRefid, invokeCircularReferenceCheck, isChecked, isReference, noChildrenAllowed, pushAndInvokeCircularReferenceCheck, setChecked, tooManyAttributes
Methods inherited from class org.apache.tools.ant.ProjectComponent
getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.apache.tools.ant.types.ResourceCollection
isEmpty, stream
-
Field Details
-
systemClasspath
The system classpath as a Path object -
systemBootClasspath
The system bootclasspath as a Path object.- Since:
- Ant 1.6.2
-
-
Constructor Details
-
Path
-
Path
Construct an emptyPath
.- Parameters:
project
- theProject
for this path.
-
-
Method Details
-
setLocation
Adds a element definition to the path.- Parameters:
location
- the location of the element to add (must not benull
nor empty.- Throws:
BuildException
- on error
-
setPath
Parses a path definition and creates single PathElements.- Parameters:
path
- theString
path definition.- Throws:
BuildException
- on error
-
setRefid
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 classDataType
- Parameters:
r
- the reference to another Path- Throws:
BuildException
- on error
-
createPathElement
Creates the nested<pathelement>
element.- Returns:
- the
PathElement
to be configured - Throws:
BuildException
- on error
-
addFileset
Adds a nested<fileset>
element.- Parameters:
fs
- aFileSet
to be added to the path- Throws:
BuildException
- on error
-
addFilelist
Adds a nested<filelist>
element.- Parameters:
fl
- aFileList
to be added to the path- Throws:
BuildException
- on error
-
addDirset
Adds a nested<dirset>
element.- Parameters:
dset
- aDirSet
to be added to the path- Throws:
BuildException
- on error
-
add
Adds a nested path- Parameters:
path
- aPath
to be added to the path- Throws:
BuildException
- on error- Since:
- Ant 1.6
-
add
Add a nestedResourceCollection
.- Parameters:
c
- the ResourceCollection to add.- Since:
- Ant 1.7
-
createPath
Creates a nested<path>
element.- Returns:
- a
Path
to be configured - Throws:
BuildException
- on error
-
append
Append the contents of the other Path instance to this.- Parameters:
other
- aPath
to be added to the path
-
addExisting
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
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
- the source pathtryUserDir
- if true try the user directory if the file is not present
-
setCache
public void setCache(boolean b) Whether to cache the current path.- Parameters:
b
- boolean- Since:
- Ant 1.8.0
-
list
Returns all path elements defined by this and nested path objects.- Returns:
- list of path elements.
-
toString
-
translatePath
-
translateFile
-
translateFileSep
Translates occurrences at a position of / or \ to correct separator of the current platform and returns whether it had to do a replacement.- Parameters:
buffer
- a buffer containing a stringpos
- the position in the string buffer to convert- Returns:
- true if the character was a / or \
-
size
public int size()Fulfill the ResourceCollection contract.- Specified by:
size
in interfaceResourceCollection
- Returns:
- number of elements as int.
-
clone
-
dieOnCircularReference
Overrides the version of DataType to recurse on all DataType child elements that may have been added.- Overrides:
dieOnCircularReference
in classDataType
- Parameters:
stk
- the stack of data types to use (recursively).p
- the project to use to dereference the references.- Throws:
BuildException
- on error.
-
concatSystemClasspath
Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using "last" as default value.- Returns:
- the concatenated path
-
concatSystemClasspath
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.- Parameters:
defValue
- the order ("first", "last", "only")- Returns:
- the concatenated path
-
concatSystemBootClasspath
Concatenates the system boot class path in the order specified by the ${build.sysclasspath} property - using the supplied value if ${build.sysclasspath} has not been set.- Parameters:
defValue
- the order ("first", "last", "only")- Returns:
- the concatenated path
-
addJavaRuntime
public void addJavaRuntime()Add the Java Runtime classes to this Path instance. -
addExtdirs
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
-
iterator
Fulfill the ResourceCollection contract. The Iterator returned will throw ConcurrentModificationExceptions if ResourceCollections are added to this container while the Iterator is in use. -
isFilesystemOnly
public boolean isFilesystemOnly()Fulfill the ResourceCollection contract.- Specified by:
isFilesystemOnly
in interfaceResourceCollection
- Returns:
- whether this is a filesystem-only resource collection.
-
assertFilesystemOnly
Verify the specified ResourceCollection is filesystem-only.- Parameters:
rc
- the ResourceCollection to check.- Returns:
- the passed in ResourceCollection.
- Throws:
BuildException
- ifrc
is not filesystem-only.
-
delegateIteratorToList
protected boolean delegateIteratorToList()Helps determine whether to preserve BC by callinglist()
on subclasses. The default behavior of this method is to returntrue
for any subclass that implementslist()
; this can, of course, be avoided by overriding this method to returnfalse
. It is not expected that the result of this method should change over time, thus it is called only once.- Returns:
true
ifiterator()
should delegate tolist()
.
-