Available (Apache Ant API)
Description: declaration: package: org.apache.tools.ant.taskdefs, class: Available

# Class Available

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.Available

All Implemented Interfaces:
  `Cloneable, Condition`

public class Available extends Task implements Condition
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 Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `Available.FileDir`
  EnumeratedAttribute covering the file types to be checked for, either file or dir.

- ## Field Summary

  ### Fields inherited from class Task

  `target, taskName, taskType, wrapper`
  Modifier and Type
  Field
  Description
  `protected Target`
  `target`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskName`
  Deprecated.
  since 1.6.x.
  `protected String`
  `taskType`
  Deprecated.
  since 1.6.x.
  `protected RuntimeConfigurable`
  `wrapper`
  Deprecated.
  since 1.6.x.

  ### Fields inherited from class ProjectComponent

  `description, location, project`
  Modifier and Type
  Field
  Description
  `protected String`
  `description`
  Deprecated.
  since 1.6.x.
  `protected Location`
  `location`
  Deprecated.
  since 1.6.x.
  `protected Project`
  `project`
  Deprecated.
  since 1.6.x.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Available()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Path`
  `createClasspath()`
  Classpath to be used when searching for classes and resources.
  `Path`
  `createFilepath()`
  Path to search for file resources.
  `boolean`
  `eval()`
  Evaluate the availability of a resource.
  `void`
  `execute()`
  Entry point when operating as a task.
  `void`
  `setClassname(String classname)`
  Set a classname of a class which must be available to set the given property.
  `void`
  `setClasspath(Path classpath)`
  Set the classpath to be used when searching for classes and resources.
  `void`
  `setClasspathRef(Reference r)`
  Set the classpath by reference.
  `void`
  `setFile(File file)`
  Set the file which must be present in the file system to set the given property.
  `void`
  `setFilepath(Path filepath)`
  Set the path to use when looking for a file.
  `void`
  `setIgnoresystemclasses(boolean ignore)`
  Set whether the search for classes should ignore the runtime classes and just use the given classpath.
  `void`
  `setProperty(String property)`
  Set the name of the property which will be set if the particular resource is available.
  `void`
  `setResource(String resource)`
  Set the name of a Java resource which is required to set the property.
  `void`
  `setSearchParents(boolean searchParents)`
  Set the searchParents attribute.
  `void`
  `setType(String type)`
  Deprecated.
  since 1.5.x.
  `void`
  `setType(Available.FileDir type)`
  Set what type of file is required - either directory or file.
  `void`
  `setValue(Object value)`
  Set the value to be given to the property if the desired resource is available.
  `void`
  `setValue(String value)`
  Set the value to be given to the property if the desired resource is available.

  ### Methods inherited from class Task

  `bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType`
  Modifier and Type
  Method
  Description
  `final void`
  `bindToOwner(Task owner)`
  Bind a task to another; use this when configuring a newly created task to do work on behalf of another.
  `Target`
  `getOwningTarget()`
  Returns the container target of this task.
  `RuntimeConfigurable`
  `getRuntimeConfigurableWrapper()`
  Returns the wrapper used for runtime configuration.
  `String`
  `getTaskName()`
  Returns the name to use in logging messages.
  `String`
  `getTaskType()`
  Return the type of task.
  `protected RuntimeConfigurable`
  `getWrapper()`
  Return the runtime configurable structure for this task.
  `protected void`
  `handleErrorFlush(String output)`
  Handles an error line by logging it with the WARN priority.
  `protected void`
  `handleErrorOutput(String output)`
  Handles an error output by logging it with the WARN priority.
  `protected void`
  `handleFlush(String output)`
  Handles output by logging it with the INFO priority.
  `protected int`
  `handleInput(byte[] buffer, int offset, int length)`
  Handle an input request by this task.
  `protected void`
  `handleOutput(String output)`
  Handles output by logging it with the INFO priority.
  `void`
  `init()`
  Called by the project to let the task initialize properly.
  `protected final boolean`
  `isInvalid()`
  Has this task been marked invalid?
  `void`
  `log(String msg)`
  Logs a message with the default (INFO) priority.
  `void`
  `log(String msg, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(String msg, Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `log(Throwable t, int msgLevel)`
  Logs a message with the given priority.
  `void`
  `maybeConfigure()`
  Configures this task - if it hasn't been done already.
  `final void`
  `perform()`
  Performs this task if it's still valid, or gets a replacement version and performs that otherwise.
  `void`
  `reconfigure()`
  Force the task to be reconfigured from its RuntimeConfigurable.
  `void`
  `setOwningTarget(Target target)`
  Sets the target container of this task.
  `void`
  `setRuntimeConfigurableWrapper(RuntimeConfigurable wrapper)`
  Sets the wrapper to be used for runtime configuration.
  `void`
  `setTaskName(String name)`
  Sets the name to use in logging messages.
  `void`
  `setTaskType(String type)`
  Sets the name with which the task has been invoked.

  ### Methods inherited from class ProjectComponent

  `clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject`
  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  `String`
  `getDescription()`
  Returns the description of the current action.
  `Location`
  `getLocation()`
  Returns the file/location where this task was defined.
  `Project`
  `getProject()`
  Returns the project to which this component belongs.
  `void`
  `setDescription(String desc)`
  Sets a description of the current action.
  `void`
  `setLocation(Location location)`
  Sets the file/location where this task was defined.
  `void`
  `setProject(Project project)`
  Sets the project object of this component.

  ### Methods inherited from class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Available

    public Available()

- ## Method Details

  - ### setSearchParents

    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` - the value to set.

  - ### setClasspath

    public void setClasspath(Path classpath)
    Set the classpath to be used when searching for classes and resources.
    Parameters:
      `classpath` - an Ant Path object containing the search path.

  - ### createClasspath

    public Path createClasspath()
    Classpath to be used when searching for classes and resources.
    Returns:
      an empty Path instance to be configured by Ant.

  - ### setClasspathRef

    public void setClasspathRef(Reference r)
    Set the classpath by reference.
    Parameters:
      `r` - a Reference to a Path instance to be used as the classpath value.

  - ### setFilepath

    public void setFilepath(Path filepath)
    Set the path to use when looking for a file.
    Parameters:
      `filepath` - a Path instance containing the search path for files.

  - ### createFilepath

    public Path createFilepath()
    Path to search for file resources.
    Returns:
      a new Path instance which Ant will configure with a file search path.

  - ### setProperty

    public void setProperty(String property)
    Set the name of the property which will be set if the particular resource is available.
    Parameters:
      `property` - the name of the property to set.

  - ### setValue

    public void setValue(Object value)
    Set the value to be given to the property if the desired resource is available.
    Parameters:
      `value` - the value to be given.

  - ### setValue

    public void setValue(String value)
    Set the value to be given to the property if the desired resource is available.
    Parameters:
      `value` - the value to be given.

  - ### setClassname

    public void setClassname(String classname)
    Set a classname of a class which must be available to set the given property.
    Parameters:
      `classname` - the name of the class required.

  - ### setFile

    public void setFile(File file)
    Set the file which must be present in the file system to set the given property.
    Parameters:
      `file` - the name of the file which is required.

  - ### setResource

    public void setResource(String resource)
    Set the name of a Java resource which is required to set the property.
    Parameters:
      `resource` - the name of a resource which is required to be available.

  - ### setType

    @Deprecated 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` - the type of resource

  - ### setType

    public void setType(Available.FileDir type)
    Set what type of file is required - either directory or file.
    Parameters:
      `type` - an instance of the FileDir enumeratedAttribute indicating whether the file required is to be a directory or a plain file.

  - ### setIgnoresystemclasses

    public void setIgnoresystemclasses(boolean ignore)
    Set whether the search for classes should ignore the runtime classes and just use the given classpath.
    Parameters:
      `ignore` - true if system classes are to be ignored.

  - ### execute

    public void execute() throws BuildException
    Entry point when operating as a task.
    Overrides:
      `execute` in class `Task`
    Throws:
      `BuildException` - if the task is not configured correctly.

  - ### eval

    public boolean eval() throws BuildException
    Evaluate the availability of a resource.
    Specified by:
      `eval` in interface `Condition`
    Returns:
      boolean is the resource is available.
    Throws:
      `BuildException` - if the condition is not configured correctly