Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class Available

extends Task
implements Condition
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.taskdefs.condition.Condition
Imports
java.io.File, .InputStream, org.apache.tools.ant.AntClassLoader, .BuildException, .Project, .PropertyHelper, .Task, org.apache.tools.ant.taskdefs.condition.Condition, org.apache.tools.ant.types.EnumeratedAttribute, .Path, .Reference, org.apache.tools.ant.util.FileUtils

Will set the given property if the requested resource is available at runtime. This task may also be used as a condition by the condition task.
Since
Ant 1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Available.FileDir

EnumeratedAttribute covering the file types to be checked for, either file or dir.

Field Summary

Modifier and TypeField and Description
private String
private Path
private File
private static final FileUtils
private String
private Path
private boolean
private boolean
private AntClassLoader
private String
private String
private boolean
private Available.FileDir
private Object
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
checkClass(String classname)

Check if a given class can be loaded.

private boolean
checkFile()

Search for file/directory either relative to project's basedir or in the path given as filepath.

private boolean
checkFile(File f, String text)

Check if a given file exists and matches the required type.

private boolean
checkResource(String resource)

Check if a given resource can be loaded.

public Path

Returns:

an empty Path instance to be configured by Ant.
createClasspath
()

Classpath to be used when searching for classes and resources.

public Path

Returns:

a new Path instance which Ant will configure with a file search path.
createFilepath
()

Path to search for file resources.

public boolean

Returns:

boolean is the resource is available.
eval
()

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Evaluate the availability of a resource.
public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Entry point when operating as a task.
public void
setClassname(String
the name of the class required.
classname
)

Set a classname of a class which must be available to set the given property.

public void
setClasspath(Path
an Ant Path object containing the search path.
classpath
)

Set the classpath to be used when searching for classes and resources.

public void
setClasspathRef(Reference
a Reference to a Path instance to be used as the classpath value.
r
)

Set the classpath by reference.

public void
setFile(File
the name of the file which is required.
file
)

Set the file which must be present in the file system to set the given property.

public void
setFilepath(Path
a Path instance containing the search path for files.
filepath
)

Set the path to use when looking for a file.

public void
setIgnoresystemclasses(boolean
true if system classes are to be ignored.
ignore
)

Set whether the search for classes should ignore the runtime classes and just use the given classpath.

public void
setProperty(String
the name of the property to set.
property
)

Set the name of the property which will be set if the particular resource is available.

public void
setResource(String
the name of a resource which is required to be available.
resource
)

Set the name of a Java resource which is required to set the property.

public void
setSearchParents(boolean
the value to set.
searchParents
)

Set the searchParents attribute.

public void
setType(String
the type of resource
type
)

Deprecated since 1.5.x.
public void
setType(Available.FileDir
an instance of the FileDir enumeratedAttribute indicating whether the file required is to be a directory or a plain file.
type
)

Set what type of file is required - either directory or file.

public void
setValue(Object
the value to be given.
value
)

Set the value to be given to the property if the desired resource is available.

public void
setValue(String
the value to be given.
value
)

Set the value to be given to the property if the desired resource is available.

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

classnameback to summary
private String classname
classpathback to summary
private Path classpath
fileback to summary
private File file
FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
filenameback to summary
private String filename
filepathback to summary
private Path filepath
ignoreSystemclassesback to summary
private boolean ignoreSystemclasses
isTaskback to summary
private boolean isTask
loaderback to summary
private AntClassLoader loader
propertyback to summary
private String property
resourceback to summary
private String resource
searchParentsback to summary
private boolean searchParents
typeback to summary
private Available.FileDir type
valueback to summary
private Object value

Constructor Detail

Availableback to summary
public Available()

Method Detail

checkClassback to summary
private boolean checkClass(String classname)

Check if a given class can be loaded.

checkFileback to summary
private boolean checkFile()

Search for file/directory either relative to project's basedir or in the path given as filepath.

filepath can be a list of directory and/or file names (gen'd via )

look for:

  • full-pathname specified == path in list
  • full-pathname specified == parent dir of path in list
  • simple name specified == path in list
  • simple name specified == path in list + name
  • simple name specified == parent dir + name
  • simple name specified == parent of parent dir + name
checkFileback to summary
private boolean checkFile(File f, String text)

Check if a given file exists and matches the required type.

checkResourceback to summary
private boolean checkResource(String resource)

Check if a given resource can be loaded.

createClasspathback to summary
public Path createClasspath()

Classpath to be used when searching for classes and resources.

Returns:Path

an empty Path instance to be configured by Ant.

createFilepathback to summary
public Path createFilepath()

Path to search for file resources.

Returns:Path

a new Path instance which Ant will configure with a file search path.

evalback to summary
public boolean eval() throws BuildException

Implements org.apache.tools.ant.taskdefs.condition.Condition.eval.

Evaluate the availability of a resource.

Returns:boolean

boolean is the resource is available.

Annotations
@Override
Exceptions
BuildException:
if the condition is not configured correctly
executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Entry point when operating as a task.

Annotations
@Override
Exceptions
BuildException:
if the task is not configured correctly.
setClassnameback to summary
public void setClassname(String classname)

Set a classname of a class which must be available to set the given property.

Parameters
classname:String

the name of the class required.

setClasspathback to summary
public void setClasspath(Path classpath)

Set the classpath to be used when searching for classes and resources.

Parameters
classpath:Path

an Ant Path object containing the search path.

setClasspathRefback to summary
public void setClasspathRef(Reference r)

Set the classpath by reference.

Parameters
r:Reference

a Reference to a Path instance to be used as the classpath value.

setFileback to summary
public void setFile(File file)

Set the file which must be present in the file system to set the given property.

Parameters
file:File

the name of the file which is required.

setFilepathback to summary
public void setFilepath(Path filepath)

Set the path to use when looking for a file.

Parameters
filepath:Path

a Path instance containing the search path for files.

setIgnoresystemclassesback to summary
public void setIgnoresystemclasses(boolean ignore)

Set whether the search for classes should ignore the runtime classes and just use the given classpath.

Parameters
ignore:boolean

true if system classes are to be ignored.

setPropertyback to summary
public void setProperty(String property)

Set the name of the property which will be set if the particular resource is available.

Parameters
property:String

the name of the property to set.

setResourceback to summary
public void setResource(String resource)

Set the name of a Java resource which is required to set the property.

Parameters
resource:String

the name of a resource which is required to be available.

setSearchParentsback to summary
public void setSearchParents(boolean searchParents)

Set the searchParents attribute. This controls the behaviour of the the "file" type. If true, the path, parent path and grandparent path are searched for the file. If false, only the path is searched. The default value is false.

Parameters
searchParents:boolean

the value to set.

setTypeback to summary
public void setType(String type)

Deprecated

since 1.5.x. setType(String) is deprecated and is replaced with setType(Available.FileDir) to make Ant's Introspection mechanism do the work and also to encapsulate operations on the type in its own class.

Parameters
type:String

the type of resource

Annotations
@Deprecated
setTypeback to summary
public void setType(Available.FileDir type)

Set what type of file is required - either directory or file.

Parameters
type:Available.FileDir

an instance of the FileDir enumeratedAttribute indicating whether the file required is to be a directory or a plain file.

setValueback to summary
public void setValue(Object value)

Set the value to be given to the property if the desired resource is available.

Parameters
value:Object

the value to be given.

setValueback to summary
public void setValue(String value)

Set the value to be given to the property if the desired resource is available.

Parameters
value:String

the value to be given.

org.apache.tools.ant.taskdefs back to summary

public Class Available.FileDir

extends EnumeratedAttribute
Class Inheritance

EnumeratedAttribute covering the file types to be checked for, either file or dir.

Field Summary

Modifier and TypeField and Description
private static final String[]
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]
getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.
public boolean

Returns:

true if the value specifies a directory.
isDir
()

Indicate if the value specifies a directory.

public boolean

Returns:

true if the value specifies a file.
isFile
()

Indicate if the value specifies a file.

Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

VALUESback to summary
private static final String[] VALUES

Constructor Detail

FileDirback to summary
public FileDir()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.

Returns:String[]

an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

Annotations
@Override
See Also
.
isDirback to summary
public boolean isDir()

Indicate if the value specifies a directory.

Returns:boolean

true if the value specifies a directory.

isFileback to summary
public boolean isFile()

Indicate if the value specifies a file.

Returns:boolean

true if the value specifies a file.