Browse Source

Migrate across the move task

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271241 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
d50c71d4f6
2 changed files with 54 additions and 1 deletions
  1. +6
    -1
      proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java
  2. +48
    -0
      proposal/myrmidon/src/java/org/apache/antlib/file/MoveTask.java

+ 6
- 1
proposal/myrmidon/src/java/org/apache/antlib/file/CopyTask.java View File

@@ -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
{


+ 48
- 0
proposal/myrmidon/src/java/org/apache/antlib/file/MoveTask.java View File

@@ -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 <a href="mailto:peter@apache.org">Peter Donald</a>
* @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 );
}
}

Loading…
Cancel
Save