From d72589dc05c30c8cdf1537247dae3a2d52fc7db9 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 5 Jul 2000 10:03:01 +0000 Subject: [PATCH] reintroduced the forseoverwrite attribute to copydir into build.xml and made it work as well. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267734 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 1 + src/main/org/apache/tools/ant/Project.java | 28 ++++++++++++++++++- .../apache/tools/ant/taskdefs/Copydir.java | 5 ++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/build.xml b/build.xml index 0ac15d8a6..3f93b5e2e 100644 --- a/build.xml +++ b/build.xml @@ -81,6 +81,7 @@ diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index f1da629aa..b28b5be5e 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -558,6 +558,19 @@ public class Project { copyFile(new File(sourceFile), new File(destFile), filtering); } + /** + * Convienence method to copy a file from a source to a + * destination specifying if token filtering must be used and if + * source files may overwrite newer destination files. + * + * @throws IOException + */ + public void copyFile(String sourceFile, String destFile, boolean filtering, + boolean overwrite) throws IOException { + copyFile(new File(sourceFile), new File(destFile), filtering, + overwrite); + } + /** * Convienence method to copy a file from a source to a destination. * No filtering is performed. @@ -577,8 +590,21 @@ public class Project { public void copyFile(File sourceFile, File destFile, boolean filtering) throws IOException { + copyFile(sourceFile, destFile, filtering, false); + } + + /** + * Convienence method to copy a file from a source to a + * destination specifying if token filtering must be used and if + * source files may overwrite newer destination files. + * + * @throws IOException + */ + public void copyFile(File sourceFile, File destFile, boolean filtering, + boolean overwrite) throws IOException { - if (destFile.lastModified() < sourceFile.lastModified()) { + if (overwrite || + destFile.lastModified() < sourceFile.lastModified()) { log("Copy: " + sourceFile.getAbsolutePath() + " > " + destFile.getAbsolutePath(), MSG_VERBOSE); diff --git a/src/main/org/apache/tools/ant/taskdefs/Copydir.java b/src/main/org/apache/tools/ant/taskdefs/Copydir.java index ea8511754..830491714 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copydir.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copydir.java @@ -112,7 +112,8 @@ public class Copydir extends MatchingTask { String fromFile = (String) enum.nextElement(); String toFile = (String) filecopyList.get(fromFile); try { - project.copyFile(fromFile, toFile, filtering); + project.copyFile(fromFile, toFile, filtering, + forceOverwrite); } catch (IOException ioe) { String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + ioe.getMessage(); @@ -130,7 +131,7 @@ public class Copydir extends MatchingTask { if (forceOverwrite || (srcFile.lastModified() > destFile.lastModified())) { filecopyList.put(srcFile.getAbsolutePath(), - destFile.getAbsolutePath()); + destFile.getAbsolutePath()); } } }