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:
- java.lang.Cloneable,- java.lang.Iterable<Resource>,- ResourceCollection
 
 public class Path extends DataType implements java.lang.Cloneable, 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 sometaskmust provide a method calledcreateSomepathwhich returns an instance ofPath. Nested path definitions are handled by the Path object and must be labeledpathelement.The path element takes a parameter pathwhich will be parsed and split into single elements. It will usually be used to define a path from an environment variable.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description classPath.PathElementHelper class, holds the nested<pathelement>values.
 - 
Field SummaryFields Modifier and Type Field Description static PathsystemBootClasspathThe system bootclasspath as a Path object.static PathsystemClasspathThe system classpath as a Path object- 
Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
 
- 
 - 
Method SummaryModifier and Type Method Description voidadd(Path path)Adds a nested pathvoidadd(ResourceCollection c)Add a nestedResourceCollection.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.protected ResourceCollectionassertFilesystemOnly(ResourceCollection rc)Verify the specified ResourceCollection is filesystem-only.java.lang.Objectclone()Clone this Path.PathconcatSystemBootClasspath(java.lang.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.PathconcatSystemClasspath()Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using "last" as default value.PathconcatSystemClasspath(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.PathcreatePath()Creates a nested<path>element.Path.PathElementcreatePathElement()Creates the nested<pathelement>element.protected booleandelegateIteratorToList()Helps determine whether to preserve BC by callinglist()on subclasses.protected voiddieOnCircularReference(java.util.Stack<java.lang.Object> stk, Project p)Overrides the version of DataType to recurse on all DataType child elements that may have been added.booleanisFilesystemOnly()Fulfill the ResourceCollection contract.java.util.Iterator<Resource>iterator()Fulfill the ResourceCollection contract.java.lang.String[]list()Returns all path elements defined by this and nested path objects.voidsetCache(boolean b)Whether to cache the current path.voidsetLocation(java.io.File location)Adds a element definition to the path.voidsetPath(java.lang.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()Fulfill the ResourceCollection contract.java.lang.StringtoString()Returns a textual representation of the path, which can be used as CLASSPATH or PATH environment variable definition.static java.lang.StringtranslateFile(java.lang.String source)Returns its argument with all file separator characters replaced so that they match the local OS conventions.protected static booleantranslateFileSep(java.lang.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 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.DataTypecheckAttributesAllowed, 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.ProjectComponentgetDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject
 - 
Methods inherited from class java.lang.Objectequals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.apache.tools.ant.types.ResourceCollectionisEmpty, stream
 
- 
 
- 
- 
- 
Constructor Detail- 
Pathpublic Path(Project p, java.lang.String path) Invoked by IntrospectionHelper forsetXXX(Path p)attribute setters.- Parameters:
- p- the- Projectfor this path.
- path- the- Stringpath definition.
 
 - 
Pathpublic Path(Project project) Construct an emptyPath.- Parameters:
- project- the- Projectfor this path.
 
 
- 
 - 
Method Detail- 
setLocationpublic void setLocation(java.io.File location) throws BuildExceptionAdds a element definition to the path.- Parameters:
- location- the location of the element to add (must not be- nullnor empty.
- Throws:
- BuildException- on error
 
 - 
setPathpublic void setPath(java.lang.String path) throws BuildExceptionParses a path definition and creates single PathElements.- Parameters:
- path- the- Stringpath definition.
- Throws:
- BuildException- on error
 
 - 
setRefidpublic 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:
- setRefidin class- DataType
- Parameters:
- r- the reference to another Path
- Throws:
- BuildException- on error
 
 - 
createPathElementpublic Path.PathElement createPathElement() throws BuildException Creates the nested<pathelement>element.- Returns:
- the PathElementto be configured
- Throws:
- BuildException- on error
 
 - 
addFilesetpublic void addFileset(FileSet fs) throws BuildException Adds a nested<fileset>element.- Parameters:
- fs- a- FileSetto be added to the path
- Throws:
- BuildException- on error
 
 - 
addFilelistpublic void addFilelist(FileList fl) throws BuildException Adds a nested<filelist>element.- Parameters:
- fl- a- FileListto be added to the path
- Throws:
- BuildException- on error
 
 - 
addDirsetpublic void addDirset(DirSet dset) throws BuildException Adds a nested<dirset>element.- Parameters:
- dset- a- DirSetto be added to the path
- Throws:
- BuildException- on error
 
 - 
addpublic void add(Path path) throws BuildException Adds a nested path- Parameters:
- path- a- Pathto be added to the path
- Throws:
- BuildException- on error
- Since:
- Ant 1.6
 
 - 
addpublic void add(ResourceCollection c) Add a nestedResourceCollection.- Parameters:
- c- the ResourceCollection to add.
- Since:
- Ant 1.7
 
 - 
createPathpublic Path createPath() throws BuildException Creates a nested<path>element.- Returns:
- a Pathto be configured
- Throws:
- BuildException- on error
 
 - 
appendpublic void append(Path other) Append the contents of the other Path instance to this.- Parameters:
- other- a- Pathto be added to the path
 
 - 
addExistingpublic 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
 
 - 
addExistingpublic 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- the source path
- tryUserDir- if true try the user directory if the file is not present
 
 - 
setCachepublic void setCache(boolean b) Whether to cache the current path.- Parameters:
- b- boolean
- Since:
- Ant 1.8.0
 
 - 
listpublic java.lang.String[] list() Returns all path elements defined by this and nested path objects.- Returns:
- list of path elements.
 
 - 
toStringpublic java.lang.String toString() Returns a textual representation of the path, which can be used as CLASSPATH or PATH environment variable definition.
 - 
translatePathpublic static java.lang.String[] translatePath(Project project, java.lang.String source) Splits a PATH (with : or ; as separators) into its parts.- Parameters:
- project- the project to use
- source- a- Stringvalue
- Returns:
- an array of strings, one for each path element
 
 - 
translateFilepublic 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.- Parameters:
- source- the path to convert
- Returns:
- the converted path
 
 - 
translateFileSepprotected static boolean translateFileSep(java.lang.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.- Parameters:
- buffer- a buffer containing a string
- pos- the position in the string buffer to convert
- Returns:
- true if the character was a / or \
 
 - 
sizepublic int size() Fulfill the ResourceCollection contract.- Specified by:
- sizein interface- ResourceCollection
- Returns:
- number of elements as int.
 
 - 
clonepublic java.lang.Object clone() Clone this Path.
 - 
dieOnCircularReferenceprotected void dieOnCircularReference(java.util.Stack<java.lang.Object> stk, Project p) throws BuildExceptionOverrides the version of DataType to recurse on all DataType child elements that may have been added.- Overrides:
- dieOnCircularReferencein class- DataType
- Parameters:
- stk- the stack of data types to use (recursively).
- p- the project to use to dereference the references.
- Throws:
- BuildException- on error.
 
 - 
concatSystemClasspathpublic Path concatSystemClasspath() Concatenates the system class path in the order specified by the ${build.sysclasspath} property - using "last" as default value.- Returns:
- the concatenated path
 
 - 
concatSystemClasspathpublic 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.- Parameters:
- defValue- the order ("first", "last", "only")
- Returns:
- the concatenated path
 
 - 
concatSystemBootClasspathpublic Path concatSystemBootClasspath(java.lang.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.- Parameters:
- defValue- the order ("first", "last", "only")
- Returns:
- the concatenated path
 
 - 
addJavaRuntimepublic void addJavaRuntime() Add the Java Runtime classes to this Path instance.
 - 
addExtdirspublic 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
 
 - 
iteratorpublic final java.util.Iterator<Resource> iterator() Fulfill the ResourceCollection contract. The Iterator returned will throw ConcurrentModificationExceptions if ResourceCollections are added to this container while the Iterator is in use.- Specified by:
- iteratorin interface- java.lang.Iterable<Resource>
- Returns:
- a "fail-fast" Iterator.
 
 - 
isFilesystemOnlypublic boolean isFilesystemOnly() Fulfill the ResourceCollection contract.- Specified by:
- isFilesystemOnlyin interface- ResourceCollection
- Returns:
- whether this is a filesystem-only resource collection.
 
 - 
assertFilesystemOnlyprotected ResourceCollection assertFilesystemOnly(ResourceCollection rc) Verify the specified ResourceCollection is filesystem-only.- Parameters:
- rc- the ResourceCollection to check.
- Returns:
- the passed in ResourceCollection.
- Throws:
- BuildException- if- rcis not filesystem-only.
 
 - 
delegateIteratorToListprotected boolean delegateIteratorToList() Helps determine whether to preserve BC by callinglist()on subclasses. The default behavior of this method is to returntruefor 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:
- trueif- iterator()should delegate to- list().
 
 
- 
 
-