diff --git a/proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java b/proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java index b3c1628ea..623cd07ec 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java @@ -120,6 +120,11 @@ public class CopyTask m_mapper = mapper; } + protected final boolean isPreserveLastModified() + { + return m_preserveLastModified; + } + public void execute() throws TaskException { @@ -417,7 +422,7 @@ public class CopyTask * Utility method to perform operation to transform a single source file * to a destination. */ - private void doOperation( final String sourceFilename, + protected void doOperation( final String sourceFilename, final String destinationFilename ) throws IOException { diff --git a/proposal/myrmidon/src/java/org/apache/antlib/file/MoveTask.java b/proposal/myrmidon/src/java/org/apache/antlib/file/MoveTask.java new file mode 100644 index 000000000..08fcfb748 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/file/MoveTask.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.file; + +import java.io.File; +import java.io.IOException; +import org.apache.avalon.excalibur.io.FileUtil; + +/** + * A task used to move files. + * + * @ant:task name="move" + * @author Peter Donald + * @version $Revision$ $Date$ + */ +public class MoveTask + extends CopyTask +{ + /** + * Utility method to perform operation to transform a single source file + * to a destination. + */ + protected void doOperation( final String sourceFilename, + final String destinationFilename ) + throws IOException + { + final File source = new File( sourceFilename ); + final File destination = new File( destinationFilename ); + + if( destination.exists() ) + { + FileUtil.forceDelete( destination ); + } + FileUtil.copyFile( source, destination ); + + if( isPreserveLastModified() ) + { + destination.setLastModified( source.lastModified() ); + } + + FileUtil.forceDelete( source ); + } +}