Browse Source

Centralize method for setting last modification time of a file in Project.

Submitted by:	Steve Loughran <steve_l@iseran.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268864 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
c434eba788
2 changed files with 3 additions and 36 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/Project.java
  2. +2
    -35
      src/main/org/apache/tools/ant/taskdefs/Touch.java

+ 1
- 1
src/main/org/apache/tools/ant/Project.java View File

@@ -803,7 +803,7 @@ public class Project {
/**
* Calls File.setLastModified(long time) in a Java 1.1 compatible way.
*/
void setFileLastModified(File file, long time) throws BuildException {
public void setFileLastModified(File file, long time) throws BuildException {
if (getJavaVersion() == JAVA_1_1) {
log("Cannot change the modification time of " + file
+ " in JDK 1.1", Project.MSG_WARN);


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

@@ -81,9 +81,6 @@ public class Touch extends Task {
private long millis = -1;
private String dateTime;

private static Method setLastModified = null;
private static Object lockReflection = new Object();

/**
* The name of the file to touch.
*/
@@ -157,40 +154,10 @@ public class Touch extends Task {
return;
}

if (setLastModified == null) {
synchronized (lockReflection) {
if (setLastModified == null) {
try {
setLastModified =
java.io.File.class.getMethod("setLastModified",
new Class[] {Long.TYPE});
} catch (NoSuchMethodException nse) {
throw new BuildException("File.setlastModified not in JDK > 1.1?",
nse, location);
}
}
}
}
Long[] times = new Long[1];
if (millis < 0) {
times[0] = new Long(System.currentTimeMillis());
project.setFileLastModified(file, System.currentTimeMillis());
} else {
times[0] = new Long(millis);
}

try {
log("Setting modification time for "+file,
Project.MSG_VERBOSE);

setLastModified.invoke(file, times);
} catch (InvocationTargetException ite) {
Throwable nested = ite.getTargetException();
throw new BuildException("Exception setting the modification time of "
+ file, nested, location);
} catch (Throwable other) {
throw new BuildException("Exception setting the modification time of "
+ file, other, location);
project.setFileLastModified(file, millis);
}
}



Loading…
Cancel
Save