Browse Source

Added forceoverwrite attribute to copydir.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267705 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
6d0c86e082
3 changed files with 17 additions and 2 deletions
  1. +4
    -1
      build.xml
  2. +6
    -0
      docs/index.html
  3. +7
    -1
      src/main/org/apache/tools/ant/taskdefs/Copydir.java

+ 4
- 1
build.xml View File

@@ -78,7 +78,10 @@
<filter token="VERSION" value="${version}" /> <filter token="VERSION" value="${version}" />
<filter token="DATE" value="${TODAY}" /> <filter token="DATE" value="${TODAY}" />
<filter token="TIME" value="${TSTAMP}" /> <filter token="TIME" value="${TSTAMP}" />
<copydir src="${src.dir}" dest="${build.classes}" filtering="on">
<copydir src="${src.dir}"
dest="${build.classes}"
filtering="on"
forceoverwrite="true">
<include name="**/version.txt" /> <include name="**/version.txt" />
</copydir> </copydir>
</target> </target>


+ 6
- 0
docs/index.html View File

@@ -694,6 +694,12 @@ this attribute has been replaced by the <i>excludes</i> attribute.</p>
the copy</td> the copy</td>
<td valign="top" align="center">No</td> <td valign="top" align="center">No</td>
</tr> </tr>
<tr>
<td valign="top">forceoverwrite</td>
<td valign="top">overwrite existing files even if the destination
files are newer (default is false).</td>
<td valign="top" align="center">No</td>
</tr>
</table> </table>
<h3>Examples</h3> <h3>Examples</h3>
<pre> &lt;copydir src=&quot;${src}/resources&quot; <pre> &lt;copydir src=&quot;${src}/resources&quot;


+ 7
- 1
src/main/org/apache/tools/ant/taskdefs/Copydir.java View File

@@ -70,6 +70,7 @@ public class Copydir extends MatchingTask {
private File srcDir; private File srcDir;
private File destDir; private File destDir;
private boolean filtering = false; private boolean filtering = false;
private boolean forceOverwrite = false;
private Hashtable filecopyList = new Hashtable(); private Hashtable filecopyList = new Hashtable();


public void setSrc(String src) { public void setSrc(String src) {
@@ -84,6 +85,10 @@ public class Copydir extends MatchingTask {
filtering = Project.toBoolean(filter); filtering = Project.toBoolean(filter);
} }


public void setForceoverwrite(String force) {
forceOverwrite = Project.toBoolean(force);
}

public void execute() throws BuildException { public void execute() throws BuildException {
if (srcDir == null) { if (srcDir == null) {
throw new BuildException("srcdir attribute must be set!", throw new BuildException("srcdir attribute must be set!",
@@ -122,7 +127,8 @@ public class Copydir extends MatchingTask {
String filename = files[i]; String filename = files[i];
File srcFile = new File(from, filename); File srcFile = new File(from, filename);
File destFile = new File(to, filename); File destFile = new File(to, filename);
if (srcFile.lastModified() > destFile.lastModified()) {
if (forceOverwrite ||
(srcFile.lastModified() > destFile.lastModified())) {
filecopyList.put(srcFile.getAbsolutePath(), filecopyList.put(srcFile.getAbsolutePath(),
destFile.getAbsolutePath()); destFile.getAbsolutePath());
} }


Loading…
Cancel
Save