From 686d04d125202806c4f41a9a76ef614d6f5d6966 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 17 Feb 2003 14:35:44 +0000 Subject: [PATCH] Add a Resource version of isOutOfDate git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274105 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/types/selectors/SelectorUtils.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java b/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java index 170139482..35560ee6e 100644 --- a/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java +++ b/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java @@ -58,6 +58,8 @@ import java.io.File; import java.util.StringTokenizer; import java.util.Vector; +import org.apache.tools.ant.types.Resource; + /** *

This is a utility class used by selectors and DirectoryScanner. The * functionality more properly belongs just to selectors, but unfortunately @@ -555,6 +557,34 @@ strLoop: return false; } + /** + * Returns dependency information on these two resources. If src has been + * modified later than target, it returns true. If target doesn't exist, + * it likewise returns true. Otherwise, target is newer than src and + * is not out of date, thus the method returns false. It also returns + * false if the src file doesn't even exist, since how could the + * target then be out of date. + * + * @param src the original resource + * @param target the resource being compared against + * @param granularity the amount in seconds of slack we will give in + * determining out of dateness + * @return whether the target is out of date + */ + public static boolean isOutOfDate(Resource src, Resource target, + int granularity) { + if (!src.isExists()) { + return false; + } + if (!target.isExists()) { + return true; + } + if ((src.getLastModified() - granularity) > target.getLastModified()) { + return true; + } + return false; + } + /** * "Flattens" a string by removing all whitespace (space, tab, linefeed, * carriage return, and formfeed). This uses StringTokenizer and the