From c434eba788bdbf917166cedaf80c421c401899d8 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 19 Mar 2001 13:05:45 +0000 Subject: [PATCH] Centralize method for setting last modification time of a file in Project. Submitted by: Steve Loughran git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268864 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/Project.java | 2 +- .../org/apache/tools/ant/taskdefs/Touch.java | 37 +------------------ 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index e487561de..21df69c6b 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -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); diff --git a/src/main/org/apache/tools/ant/taskdefs/Touch.java b/src/main/org/apache/tools/ant/taskdefs/Touch.java index b12fc0271..44effac94 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Touch.java +++ b/src/main/org/apache/tools/ant/taskdefs/Touch.java @@ -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); } }