Limit (Ant Contrib)
Date: 2016-06-25

net.sf.antcontrib.process

## Class Limit

- java.lang.Object
- - org.apache.tools.ant.ProjectComponent
  - - org.apache.tools.ant.Task
    - - net.sf.antcontrib.process.Limit

- All Implemented Interfaces:
    java.lang.Cloneable, org.apache.tools.ant.TaskContainer

      public class Limit
      extends org.apache.tools.ant.Task
      implements org.apache.tools.ant.TaskContainer

  Limits the amount of time that a task or set of tasks can run. This is useful for tasks that may "hang" or otherwise not complete in a timely fashion. This task is done when either the maxwait time has expired or all nested tasks are complete, whichever is first.

  Developed for use with Antelope, migrated to ant-contrib Oct 2003.

  Since:
    Ant 1.5
  Version:
    $Revision: 1.6 $
  Author:
    Dale Anson, Robert D. Rice

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Limit.TimeUnit` The enumeration of units: millisecond, second, minute, hour, day, week Todo: we use timestamps in many places, why not factor this out

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Limit.TimeUnit` | `unit`

    - ### Fields inherited from class org.apache.tools.ant.Task

      `target, taskName, taskType, wrapper`

    - ### Fields inherited from class org.apache.tools.ant.ProjectComponent

      `description, location, project`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Limit()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addTask(org.apache.tools.ant.Task task)` Add a task to wait on.
    `void` | `execute()` Execute all nested tasks, but stopping execution of nested tasks after maxwait or when all tasks are done, whichever is first.
    `void` | `setDays(int value)` Set a day wait value.
    `void` | `setFailonerror(boolean fail)` Determines whether the build should fail if the time limit has expired on this task.
    `void` | `setHours(int value)` Set an hours wait value.
    `void` | `setMaxwait(int wait)` How long to wait for all nested tasks to complete, in units.
    `void` | `setMaxWaitUnit(Limit.TimeUnit unit)` Set the max wait time unit, default is minutes.
    `void` | `setMilliseconds(int value)` Set a millisecond wait value.
    `void` | `setMinutes(int value)` Set a minute wait value.
    `void` | `setProperty(java.lang.String p)` Name the property to set after a timeout.
    `void` | `setSeconds(int value)` Set a second wait value.
    `void` | `setUnit(java.lang.String unit)` Sets the unit for the max wait.
    `void` | `setValue(java.lang.String v)` The value for the property to set after a timeout, defaults to true.
    `void` | `setWeeks(int value)` Set a week wait value.

    - ### Methods inherited from class org.apache.tools.ant.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`

    - ### Methods inherited from class org.apache.tools.ant.ProjectComponent

      `clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject`

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### unit

          protected Limit.TimeUnit unit

  - ### Constructor Detail

    - #### Limit

          public Limit()

  - ### Method Detail

    - #### addTask

          public void addTask(org.apache.tools.ant.Task task)
                       throws org.apache.tools.ant.BuildException

      Add a task to wait on.
      Specified by:
        `addTask` in interface `org.apache.tools.ant.TaskContainer`
      Parameters:
        `task` - A task to execute
      Throws:
        `org.apache.tools.ant.BuildException` - won't happen

    - #### setMaxwait

          public void setMaxwait(int wait)

      How long to wait for all nested tasks to complete, in units. Default is to wait 3 minutes.
      Parameters:
        `wait` - time to wait, set to 0 to wait forever.

    - #### setUnit

          public void setUnit(java.lang.String unit)

      Sets the unit for the max wait. Default is minutes.
      Parameters:
        `unit` - valid values are "millisecond", "second", "minute", "hour", "day", and "week".

    - #### setMilliseconds

          public void setMilliseconds(int value)

      Set a millisecond wait value.
      Parameters:
        `value` - the number of milliseconds to wait.

    - #### setSeconds

          public void setSeconds(int value)

      Set a second wait value.
      Parameters:
        `value` - the number of seconds to wait.

    - #### setMinutes

          public void setMinutes(int value)

      Set a minute wait value.
      Parameters:
        `value` - the number of milliseconds to wait.

    - #### setHours

          public void setHours(int value)

      Set an hours wait value.
      Parameters:
        `value` - the number of hours to wait.

    - #### setDays

          public void setDays(int value)

      Set a day wait value.
      Parameters:
        `value` - the number of days to wait.

    - #### setWeeks

          public void setWeeks(int value)

      Set a week wait value.
      Parameters:
        `value` - the number of weeks to wait.

    - #### setMaxWaitUnit

          public void setMaxWaitUnit(Limit.TimeUnit unit)

      Set the max wait time unit, default is minutes.

    - #### setFailonerror

          public void setFailonerror(boolean fail)

      Determines whether the build should fail if the time limit has expired on this task. Default is no.
      Parameters:
        `fail` - if true, fail the build if the time limit has been reached.

    - #### setProperty

          public void setProperty(java.lang.String p)

      Name the property to set after a timeout.
      Parameters:
        `p` - of property to set if the time limit has been reached.

    - #### setValue

          public void setValue(java.lang.String v)

      The value for the property to set after a timeout, defaults to true.
      Parameters:
        `v` - for the property to set if the time limit has been reached.

    - #### execute

          public void execute()
                       throws org.apache.tools.ant.BuildException

      Execute all nested tasks, but stopping execution of nested tasks after maxwait or when all tasks are done, whichever is first.
      Overrides:
        `execute` in class `org.apache.tools.ant.Task`
      Throws:
        `org.apache.tools.ant.BuildException` - Description of the Exception