|
@@ -107,6 +107,9 @@ public class Project { |
|
|
|
|
|
|
|
|
private Vector listeners = new Vector(); |
|
|
private Vector listeners = new Vector(); |
|
|
|
|
|
|
|
|
|
|
|
private static java.lang.reflect.Method setLastModified = null; |
|
|
|
|
|
private static Object lockReflection = new Object(); |
|
|
|
|
|
|
|
|
static { |
|
|
static { |
|
|
|
|
|
|
|
|
// Determine the Java version by looking at available classes |
|
|
// Determine the Java version by looking at available classes |
|
@@ -672,6 +675,22 @@ public class Project { |
|
|
overwrite); |
|
|
overwrite); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Convienence method to copy a file from a source to a |
|
|
|
|
|
* destination specifying if token filtering must be used, if |
|
|
|
|
|
* source files may overwrite newer destination files and the |
|
|
|
|
|
* last modified time of <code>destFile</code> file should be made equal |
|
|
|
|
|
* to the last modified time of <code>sourceFile</code>. |
|
|
|
|
|
* |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
*/ |
|
|
|
|
|
public void copyFile(String sourceFile, String destFile, boolean filtering, |
|
|
|
|
|
boolean overwrite, boolean preserveLastModified) |
|
|
|
|
|
throws IOException { |
|
|
|
|
|
copyFile(new File(sourceFile), new File(destFile), filtering, |
|
|
|
|
|
overwrite, preserveLastModified); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Convienence method to copy a file from a source to a destination. |
|
|
* Convienence method to copy a file from a source to a destination. |
|
|
* No filtering is performed. |
|
|
* No filtering is performed. |
|
@@ -689,8 +708,7 @@ public class Project { |
|
|
* @throws IOException |
|
|
* @throws IOException |
|
|
*/ |
|
|
*/ |
|
|
public void copyFile(File sourceFile, File destFile, boolean filtering) |
|
|
public void copyFile(File sourceFile, File destFile, boolean filtering) |
|
|
throws IOException |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
throws IOException { |
|
|
copyFile(sourceFile, destFile, filtering, false); |
|
|
copyFile(sourceFile, destFile, filtering, false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -703,7 +721,22 @@ public class Project { |
|
|
*/ |
|
|
*/ |
|
|
public void copyFile(File sourceFile, File destFile, boolean filtering, |
|
|
public void copyFile(File sourceFile, File destFile, boolean filtering, |
|
|
boolean overwrite) throws IOException { |
|
|
boolean overwrite) throws IOException { |
|
|
|
|
|
copyFile(sourceFile, destFile, filtering, overwrite, false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Convienence method to copy a file from a source to a |
|
|
|
|
|
* destination specifying if token filtering must be used, if |
|
|
|
|
|
* source files may overwrite newer destination files and the |
|
|
|
|
|
* last modified time of <code>destFile</code> file should be made equal |
|
|
|
|
|
* to the last modified time of <code>sourceFile</code>. |
|
|
|
|
|
* |
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
*/ |
|
|
|
|
|
public void copyFile(File sourceFile, File destFile, boolean filtering, |
|
|
|
|
|
boolean overwrite, boolean preserveLastModified) |
|
|
|
|
|
throws IOException { |
|
|
|
|
|
|
|
|
if (overwrite || |
|
|
if (overwrite || |
|
|
destFile.lastModified() < sourceFile.lastModified()) { |
|
|
destFile.lastModified() < sourceFile.lastModified()) { |
|
|
log("Copy: " + sourceFile.getAbsolutePath() + " > " |
|
|
log("Copy: " + sourceFile.getAbsolutePath() + " > " |
|
@@ -750,6 +783,52 @@ public class Project { |
|
|
in.close(); |
|
|
in.close(); |
|
|
out.close(); |
|
|
out.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (preserveLastModified) { |
|
|
|
|
|
setFileLastModified(destFile, sourceFile.lastModified()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Calls File.setLastModified(long time) in a Java 1.1 compatible way. |
|
|
|
|
|
*/ |
|
|
|
|
|
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); |
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Long[] times = new Long[1]; |
|
|
|
|
|
if (time < 0) { |
|
|
|
|
|
times[0] = new Long(System.currentTimeMillis()); |
|
|
|
|
|
} else { |
|
|
|
|
|
times[0] = new Long(time); |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
log("Setting modification time for " + file, MSG_VERBOSE); |
|
|
|
|
|
setLastModified.invoke(file, times); |
|
|
|
|
|
} catch (java.lang.reflect.InvocationTargetException ite) { |
|
|
|
|
|
Throwable nested = ite.getTargetException(); |
|
|
|
|
|
throw new BuildException("Exception setting the modification time " |
|
|
|
|
|
+ "of " + file, nested); |
|
|
|
|
|
} catch (Throwable other) { |
|
|
|
|
|
throw new BuildException("Exception setting the modification time " |
|
|
|
|
|
+ "of " + file, other); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|