Uptodate

Description

Sets a property if a target file or set of target files is more up-to-date than a source file or set of source files. A single source file is specified using the srcfile attribute. A set of source files is specified using the nested <srcfiles> elements. These are FileSets, whereas multiple target files are specified using a nested <mapper> element.

By default, the value of the property is set to true if the timestamp of the source file(s) is not more recent than the timestamp of the corresponding target file(s). You can set the value to something other than the default by specifying the value attribute.

If a <srcfiles> element is used, without also specifying a <mapper> element, the default behavior is to use a merge mapper, with the to attribute set to the value of the targetfile attribute.

Normally, this task is used to set properties that are useful to avoid target execution depending on the relative age of the specified files.

Parameters

Attribute Description Required
property The name of the property to set. Yes
value The value to set the property to. No; defaults to true.
srcfile The file to check against the target file(s). Yes, unless a nested <srcfiles> or <srcresources> element is present.
targetfile The file for which we want to determine the status. Yes, unless a nested <mapper> element is present.

Parameters specified as nested elements

srcfiles

The nested <srcfiles> element is a fileset and allows you to specify a set of files to check against the target file(s).

Note: You can specify either the srcfile attribute or nested <srcfiles> elements, but not both.

Note that the task will completely ignore any directories that seem to be matched by the srcfiles fileset, it will only consider normal files. If you need logic that applies to directories as well, use a nested srcresources element and a dirset (for example).

srcresources

Since Apache Ant 1.7

The nested <srcresources> element is a union and allows you to specify a collection of resources to check against the target file(s).

mapper

The nested <mapper> element allows you to specify a set of target files to check for being up-to-date with respect to a set of source files.

The mapper to attribute is relative to the target file, or to the dir attribute of the nested srcfiles element.

Since Ant 1.6.3, one can use a filenamemapper type in place of the mapper element.

Examples

Set the property xmlBuild.notRequired to true if the ${deploy}/xmlClasses.jar file is more up-to-date than any of the DTD files in the ${src}/xml directory.

<uptodate property="xmlBuild.notRequired" targetfile="${deploy}\xmlClasses.jar">
  <srcfiles dir="${src}/xml" includes="**/*.dtd"/>
</uptodate>

This can be written as:

<uptodate property="xmlBuild.notRequired">
  <srcfiles dir= "${src}/xml" includes="**/*.dtd"/>
  <mapper type="merge" to="${deploy}\xmlClasses.jar"/>
</uptodate>

as well.

The xmlBuild.notRequired property can then be used in a <target> tag's unless attribute to conditionally run that target. For example, running the following target:

<target name="xmlBuild" depends="chkXmlBuild" unless="xmlBuild.notRequired">
  ...
</target>

will first run the chkXmlBuild target, which contains the <uptodate> task that determines whether xmlBuild.notRequired gets set. The property named in the unless attribute is then checked for being set/not set. If it did get set (ie., the jar file is up-to-date), then the xmlBuild target won't be run.

The following example shows a single source file being checked against a single target file:

<uptodate property="isUpToDate"
          srcfile="/usr/local/bin/testit"
          targetfile="${build}/.flagfile"/>

sets the property isUpToDate to true if /usr/local/bin/testit is not newer than ${build}/.flagfile.

The following shows usage of a relative mapper.

<uptodate property="checkUptodate.uptodate">
  <srcfiles dir="src" includes="*"/>
  <mapper type="merge" to="../dest/output.done"/>
</uptodate>
<echo message="checkUptodate result: ${checkUptodate.uptodate}"/>

The previous example can be a bit confusing, so it may be better to use absolute paths:

<property name="dest.dir" location="dest"/>
<uptodate property="checkUptodate.uptodate">
  <srcfiles dir="src" includes="*"/>
  <mapper type="merge" to="${dest.dir}/output.done"/>
</uptodate>