From 58cf8485c59126d42e400cf88668448c73acc0d6 Mon Sep 17 00:00:00 2001 From: Jacobus Martinus Kruithof Date: Tue, 4 Jan 2005 20:20:52 +0000 Subject: [PATCH] Made more consequent use of the method available in FileUtils to get the granularity. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277276 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Copy.java | 4 ++-- .../apache/tools/ant/taskdefs/DependSet.java | 12 +++++------- .../ant/types/selectors/DateSelector.java | 9 ++++----- .../ant/types/selectors/MappingSelector.java | 8 ++++---- .../org/apache/tools/ant/util/FileUtils.java | 18 +++++++++++++++--- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 100838658..514be84a9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ public class Copy extends Task { * Copy task constructor. */ public Copy() { - fileUtils = FileUtils.newFileUtils(); + fileUtils = FileUtils.getFileUtils(); granularity = fileUtils.getFileTimestampGranularity(); } diff --git a/src/main/org/apache/tools/ant/taskdefs/DependSet.java b/src/main/org/apache/tools/ant/taskdefs/DependSet.java index 565908a1c..ce5b26705 100644 --- a/src/main/org/apache/tools/ant/taskdefs/DependSet.java +++ b/src/main/org/apache/tools/ant/taskdefs/DependSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2002,2004 The Apache Software Foundation + * Copyright 2001-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.FileList; import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.util.FileUtils; /** * Examines and removes out of date target files. If any of the target files @@ -134,13 +135,10 @@ public class DependSet extends MatchingTask { long now = (new Date()).getTime(); /* - If we're on Windows, we have to munge the time up to 2 secs to - be able to check file modification times. - (Windows has a max resolution of two secs for modification times) + We have to munge the time to allow for the filesystem time + granularity. */ - if (Os.isFamily("windows")) { - now += 2000; - } + now += FileUtils.getFileUtils().getFileTimestampGranularity(); // // Grab all the target files specified via filesets diff --git a/src/main/org/apache/tools/ant/types/selectors/DateSelector.java b/src/main/org/apache/tools/ant/types/selectors/DateSelector.java index 95a5ac4e3..8a65d91d6 100644 --- a/src/main/org/apache/tools/ant/types/selectors/DateSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/DateSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2004 The Apache Software Foundation + * Copyright 2002-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.Parameter; +import org.apache.tools.ant.util.FileUtils; /** * Selector that chooses files based on their last modified date. @@ -38,7 +39,7 @@ public class DateSelector extends BaseExtendSelector { private long millis = -1; private String dateTime = null; private boolean includeDirs = false; - private int granularity = 0; + private long granularity = 0; private int cmp = 2; private String pattern; /** Key to used for parameterized custom selector */ @@ -59,9 +60,7 @@ public class DateSelector extends BaseExtendSelector { * */ public DateSelector() { - if (Os.isFamily("dos")) { - granularity = 2000; - } + granularity = FileUtils.getFileUtils().getFileTimestampGranularity(); } /** diff --git a/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java b/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java index f65bd7b7a..15eb0453f 100644 --- a/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ public abstract class MappingSelector extends BaseSelector { * */ public MappingSelector() { - granularity = (int) FileUtils.newFileUtils().getFileTimestampGranularity(); + granularity = (int) FileUtils.getFileUtils().getFileTimestampGranularity(); } @@ -128,8 +128,8 @@ public abstract class MappingSelector extends BaseSelector { /** * Sets the number of milliseconds leeway we will give before we consider - * a file out of date. Defaults to 2000 on MS-DOS derivatives as the FAT - * file system. + * a file out of date. Defaults to 2000 on MS-DOS derivatives and 1000 on + * others. * @param granularity the leeway in milliseconds */ public void setGranularity(int granularity) { diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 92066cfa9..caf162903 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 The Apache Software Foundation + * Copyright 2001-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,11 +58,14 @@ import org.apache.tools.ant.launch.Locator; */ public class FileUtils { + + private static final FileUtils PRIMARY_INSTANCE = new FileUtils(); + //get some non-crypto-grade randomness from various places. private static Random rand = new Random(System.currentTimeMillis() + Runtime.getRuntime().freeMemory()); - private boolean onNetWare = Os.isFamily("netware"); + private static boolean onNetWare = Os.isFamily("netware"); // for toURI private static boolean[] isSpecial = new boolean[256]; @@ -106,11 +109,21 @@ public class FileUtils { * Factory method. * * @return a new instance of FileUtils. + * @deprecated Use getFileUtils instead, FileUtils do not have state. */ public static FileUtils newFileUtils() { return new FileUtils(); } + /** + * Method to retrieve The FileUtils, which is shared by all users of this + * method. + * @return an instance of FileUtils. + */ + public static FileUtils getFileUtils() { + return PRIMARY_INSTANCE; + } + /** * Empty constructor. */ @@ -1356,7 +1369,6 @@ public class FileUtils { 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