Browse Source

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
master
Jacobus Martinus Kruithof 20 years ago
parent
commit
58cf8485c5
5 changed files with 30 additions and 21 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  2. +5
    -7
      src/main/org/apache/tools/ant/taskdefs/DependSet.java
  3. +4
    -5
      src/main/org/apache/tools/ant/types/selectors/DateSelector.java
  4. +4
    -4
      src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
  5. +15
    -3
      src/main/org/apache/tools/ant/util/FileUtils.java

+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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. * Copy task constructor.
*/ */
public Copy() { public Copy() {
fileUtils = FileUtils.newFileUtils();
fileUtils = FileUtils.getFileUtils();
granularity = fileUtils.getFileTimestampGranularity(); granularity = fileUtils.getFileTimestampGranularity();
} }




+ 5
- 7
src/main/org/apache/tools/ant/taskdefs/DependSet.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.taskdefs.condition.Os;
import org.apache.tools.ant.types.FileList; import org.apache.tools.ant.types.FileList;
import org.apache.tools.ant.types.FileSet; 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 * 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(); 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 // Grab all the target files specified via filesets


+ 4
- 5
src/main/org/apache/tools/ant/types/selectors/DateSelector.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.taskdefs.condition.Os;
import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Parameter; import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.util.FileUtils;


/** /**
* Selector that chooses files based on their last modified date. * Selector that chooses files based on their last modified date.
@@ -38,7 +39,7 @@ public class DateSelector extends BaseExtendSelector {
private long millis = -1; private long millis = -1;
private String dateTime = null; private String dateTime = null;
private boolean includeDirs = false; private boolean includeDirs = false;
private int granularity = 0;
private long granularity = 0;
private int cmp = 2; private int cmp = 2;
private String pattern; private String pattern;
/** Key to used for parameterized custom selector */ /** Key to used for parameterized custom selector */
@@ -59,9 +60,7 @@ public class DateSelector extends BaseExtendSelector {
* *
*/ */
public DateSelector() { public DateSelector() {
if (Os.isFamily("dos")) {
granularity = 2000;
}
granularity = FileUtils.getFileUtils().getFileTimestampGranularity();
} }


/** /**


+ 4
- 4
src/main/org/apache/tools/ant/types/selectors/MappingSelector.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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() { 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 * 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 * @param granularity the leeway in milliseconds
*/ */
public void setGranularity(int granularity) { public void setGranularity(int granularity) {


+ 15
- 3
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 { public class FileUtils {
private static final FileUtils PRIMARY_INSTANCE = new FileUtils();
//get some non-crypto-grade randomness from various places. //get some non-crypto-grade randomness from various places.
private static Random rand = new Random(System.currentTimeMillis() private static Random rand = new Random(System.currentTimeMillis()
+ Runtime.getRuntime().freeMemory()); + Runtime.getRuntime().freeMemory());


private boolean onNetWare = Os.isFamily("netware");
private static boolean onNetWare = Os.isFamily("netware");


// for toURI // for toURI
private static boolean[] isSpecial = new boolean[256]; private static boolean[] isSpecial = new boolean[256];
@@ -106,11 +109,21 @@ public class FileUtils {
* Factory method. * Factory method.
* *
* @return a new instance of FileUtils. * @return a new instance of FileUtils.
* @deprecated Use getFileUtils instead, FileUtils do not have state.
*/ */
public static FileUtils newFileUtils() { public static FileUtils newFileUtils() {
return new FileUtils(); 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. * Empty constructor.
*/ */
@@ -1356,7 +1369,6 @@ public class FileUtils {
return isUpToDate(sourceTime, destTime, getFileTimestampGranularity()); return isUpToDate(sourceTime, destTime, getFileTimestampGranularity());
} }



/** /**
* close a writer without throwing any exception if something went wrong. * close a writer without throwing any exception if something went wrong.
* Do not attempt to close it if the file is null * Do not attempt to close it if the file is null


Loading…
Cancel
Save