Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 41108 invoked from network); 3 Aug 2004 23:18:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Aug 2004 23:18:41 -0000 Received: (qmail 93316 invoked by uid 500); 3 Aug 2004 23:18:38 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 93229 invoked by uid 500); 3 Aug 2004 23:18:37 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 93215 invoked by uid 500); 3 Aug 2004 23:18:37 -0000 Received: (qmail 93211 invoked by uid 99); 3 Aug 2004 23:18:37 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 03 Aug 2004 16:18:36 -0700 Received: (qmail 41083 invoked by uid 1365); 3 Aug 2004 23:18:35 -0000 Date: 3 Aug 2004 23:18:35 -0000 Message-ID: <20040803231835.41082.qmail@minotaur.apache.org> From: stevel@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/src/main/org/apache/tools/ant/util FileUtils.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N stevel 2004/08/03 16:18:35 Modified: src/main/org/apache/tools/ant/util FileUtils.java Log: 1. some factoring out of the timestamp checks for even more reuse. That way the granularity logic can all go in one place. 2. a refactoring of close() to ignore exceptions. I made this static because I want to use it everywhere we close things in a finally clause. NB, note that all four methods would all be unified if the writer/reader/instream/outstream classes had a base class "Closeable" with method void close(). No, I have not refactored everything to use these yet. Revision Changes Path 1.70 +96 -2 ant/src/main/org/apache/tools/ant/util/FileUtils.java Index: FileUtils.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/FileUtils.java,v retrieving revision 1.69 retrieving revision 1.70 diff -u -r1.69 -r1.70 --- FileUtils.java 18 May 2004 08:14:48 -0000 1.69 +++ FileUtils.java 3 Aug 2004 23:18:35 -0000 1.70 @@ -30,6 +30,9 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; +import java.io.PrintWriter; +import java.io.Writer; +import java.io.OutputStream; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; @@ -1340,9 +1343,10 @@ } long sourceTime=source.lastModified(); long destTime=dest.lastModified(); - return destTime>=sourceTime+granularity; + return isUpToDate(sourceTime, destTime, granularity); } + /** * returns true if the source is older than the dest * @param source source file (should be the older) @@ -1354,6 +1358,96 @@ return isUpToDate(source, dest, getFileTimestampGranularity()); } + /** + * compare two timestamps for being up to date, use granularity too., + * + * @param sourceTime timestamp of source file + * @param destTime timestamp of dest file + * @param granularity os/filesys granularity + * @return true if the dest file is considered up to date + */ + public boolean isUpToDate(long sourceTime,long destTime, long granularity) { + if(destTime==-1) { + return false; + } + return destTime >= sourceTime + granularity; + } + + /** + * compare two timestamps for being up to date, use the + * current granularity + * + * @param sourceTime timestamp of source file + * @param destTime timestamp of dest file + * @return true if the dest file is considered up to date + */ + public boolean isUpToDate(long sourceTime, long destTime) { + return isUpToDate(sourceTime, destTime,getFileTimestampGranularity()); + } + + + /** + * close a writer without throwing any exception if something went wrong. + * Do not attempt to close it if the file is null + * @param device output writer, can be null + */ + public static void close(Writer device) { + if (device != null) { + try { + device.close(); + } catch (IOException ioex) { + //ignore + } + } + } + + /** + * close a stream without throwing any exception if something went wrong. + * Do not attempt to close it if the file is null + * + * @param device stream, can be null + */ + public static void close(Reader device) { + if ( device != null ) { + try { + device.close(); + } catch (IOException ioex) { + //ignore + } + } + } + + /** + * close a stream without throwing any exception if something went wrong. + * Do not attempt to close it if the file is null + * + * @param device stream, can be null + */ + public static void close(OutputStream device) { + if ( device != null ) { + try { + device.close(); + } catch (IOException ioex) { + //ignore + } + } + } + + /** + * close a stream without throwing any exception if something went wrong. + * Do not attempt to close it if the file is null + * + * @param device stream, can be null + */ + public static void close(InputStream device) { + if ( device != null ) { + try { + device.close(); + } catch (IOException ioex) { + //ignore + } + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org