diff --git a/docs/manual/CoreTasks/uptodate.html b/docs/manual/CoreTasks/uptodate.html index 8fb80bc9d..d7ecd188a 100644 --- a/docs/manual/CoreTasks/uptodate.html +++ b/docs/manual/CoreTasks/uptodate.html @@ -9,19 +9,24 @@

Uptodate

Description

-

Sets a property if a target files are more up to date than a set of -Source files. Source files are specified by nested <srcfiles> -elements, these are FileSets, while target -files are specified using a nested mapper -element.

-

The value part of the property being set is true if the -timestamp of the target files is more recent than the timestamp of -every corresponding source file.

-

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.

+

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 target file(s) is more recent than the timestamp of +the corresponding source 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

@@ -31,36 +36,71 @@ execution depending on the relative age of the specified files.

- + - - + + + + + + + - - + +
propertythe name of the property to set.The name of the property to set. Yes
valuethe value to set the property to. Defaults to "true".NoThe value to set the property to.No; defaults to true.
srcfileThe file to check against the target file.Yes, unless a nested + <srcfiles> element is present.
targetfilethe file for which we want to determine the status.Yes, unless a nested mapper element is - present.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.

+ +

Note: The nested <mapper> element is +only valid when used with the <srcfiles> element. +

Examples

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

sets the property xmlBuild.notRequired to the value "true" -if the ${deploy}/xmlClasses.jar 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"  >
+

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.

+as well. +

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

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

+

+
-

Copyright © 2001 Apache Software Foundation. All rights -Reserved.

+

Copyright © 2001,2002 Apache Software Foundation. +All rights Reserved.

diff --git a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java index f66e6eaf5..86985a0f5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java +++ b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java @@ -83,26 +83,27 @@ public class UpToDate extends MatchingTask implements Condition { private String _property; private String _value; + private File _sourceFile; private File _targetFile; private Vector sourceFileSets = new Vector(); protected Mapper mapperElement = null; /** - * The property to set if the target file is more up to date than each of - * the source files. + * The property to set if the target file is more up-to-date than + * (each of) the source file(s). * - * @param property the name of the property to set if Target is up to date. + * @param property the name of the property to set if Target is up-to-date. */ public void setProperty(String property) { _property = property; } /** - * The value to set the named property to if the target file is more up to - * date than each of the source files. Defaults to 'true'. + * The value to set the named property to if the target file is more + * up-to-date than (each of) the source file(s). Defaults to 'true'. * - * @param value the value to set the property to if Target is up to date + * @param value the value to set the property to if Target is up-to-date */ public void setValue(String value) { _value = value; @@ -116,15 +117,25 @@ public class UpToDate extends MatchingTask implements Condition { } /** - * The file which must be more up to date than each of the source files + * The file which must be more up-to-date than (each of) the source file(s) * if the property is to be set. * - * @param file the file which we are checking against. + * @param file the file we are checking against. */ public void setTargetFile(File file) { _targetFile = file; } + /** + * The file that must be older than the target file + * if the property is to be set. + * + * @param file the file we are checking against the target file. + */ + public void setSrcfile(File file) { + _sourceFile = file; + } + /** * Nested <srcfiles> element. */ @@ -145,47 +156,66 @@ public class UpToDate extends MatchingTask implements Condition { } /** - * Evaluate all target and source files, see if the targets are up-to-date. + * Evaluate (all) target and source file(s) to + * see if the target(s) is/are up-to-date. */ public boolean eval() { - if (sourceFileSets.size() == 0) { - throw new BuildException("At least one element must be set"); + if (sourceFileSets.size() == 0 && _sourceFile == null) { + throw new BuildException("At least one srcfile or a nested element must be set."); + } + + if (sourceFileSets.size() > 0 && _sourceFile != null) { + throw new BuildException("Cannot specify both the srcfile attribute and a nested element."); } if (_targetFile == null && mapperElement == null) { - throw new BuildException("The targetfile attribute or a nested mapper element must be set"); + throw new BuildException("The targetfile attribute or a nested mapper element must be set."); + } + + if (_sourceFile != null && mapperElement != null) { + throw new BuildException("Cannot specify both the srcfile attribute and a nested mapper element."); } - // if not there then it can't be up to date + // if the target file is not there, then it can't be up-to-date if (_targetFile != null && !_targetFile.exists()) { return false; } + // if the source file isn't there, throw an exception + if (_sourceFile != null && !_sourceFile.exists()) { + throw new BuildException(_sourceFile.getAbsolutePath() + " not found."); + } + Enumeration enum = sourceFileSets.elements(); boolean upToDate = true; while (upToDate && enum.hasMoreElements()) { FileSet fs = (FileSet) enum.nextElement(); DirectoryScanner ds = fs.getDirectoryScanner(project); - upToDate = upToDate && scanDir(fs.getDir(project), - ds.getIncludedFiles()); + upToDate = upToDate && scanDir(fs.getDir(project), + ds.getIncludedFiles()); + } + if (_sourceFile != null) { + File srcfile = new File(_sourceFile.getAbsolutePath()); + File tgtfile = new File(_targetFile.getAbsolutePath()); + upToDate = (tgtfile.lastModified() > srcfile.lastModified()); } return upToDate; } /** - * Sets property to true if target files have a more recent timestamp than - * each of the corresponding source files. + * Sets property to true if target file(s) have a more recent timestamp + * than (each of) the corresponding source file(s). */ public void execute() throws BuildException { boolean upToDate = eval(); if (upToDate) { this.project.setProperty(_property, this.getValue()); if (mapperElement == null) { - log("File \"" + _targetFile.getAbsolutePath() + "\" is up to date.", + log("File \"" + _targetFile.getAbsolutePath() + "\" is up-to-date.", Project.MSG_VERBOSE); } else { - log("All target files have been up to date.", + log("All target files are up-to-date.", Project.MSG_VERBOSE); } }