java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Ant arrow How to use Uptodate task
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use Uptodate task E-mail
User Rating: / 14
PoorBest 

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> 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 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.

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

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

  </uptodate>

sets 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.

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>
  

Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.