Browse Source

reset state in <copydir>, cleanup

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272366 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
f52d3009e6
2 changed files with 41 additions and 27 deletions
  1. +29
    -21
      src/main/org/apache/tools/ant/taskdefs/Copydir.java
  2. +12
    -6
      src/main/org/apache/tools/ant/taskdefs/Copyfile.java

+ 29
- 21
src/main/org/apache/tools/ant/taskdefs/Copydir.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* Copyright (c) 2000,2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -60,13 +60,16 @@ import java.util.Hashtable;
import java.util.Enumeration;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;

/**
* Copies a directory.
*
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
*
* @deprecated The copydir task is deprecated. Use copy instead.
* @since Ant 1.1
*
* @deprecated The copydir task is deprecated since Ant 1.2. Use copy instead.
*/

public class Copydir extends MatchingTask {
@@ -112,34 +115,39 @@ public class Copydir extends MatchingTask {
}

if (destDir == null) {
throw new BuildException("The dest attribute must be set.", location);
throw new BuildException("The dest attribute must be set.",
location);
}

if (srcDir.equals(destDir)) {
log("Warning: src == dest");
log("Warning: src == dest", Project.MSG_WARN);
}

DirectoryScanner ds = super.getDirectoryScanner(srcDir);

String[] files = ds.getIncludedFiles();
scanDir(srcDir, destDir, files);
if (filecopyList.size() > 0) {
log("Copying " + filecopyList.size() + " file"
+ (filecopyList.size() == 1 ? "" : "s")
+ " to " + destDir.getAbsolutePath());
Enumeration enum = filecopyList.keys();
while (enum.hasMoreElements()) {
String fromFile = (String) enum.nextElement();
String toFile = (String) filecopyList.get(fromFile);
try {
project.copyFile(fromFile, toFile, filtering,
forceOverwrite);
} catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " + toFile
+ " due to " + ioe.getMessage();
throw new BuildException(msg, ioe, location);
try {
String[] files = ds.getIncludedFiles();
scanDir(srcDir, destDir, files);
if (filecopyList.size() > 0) {
log("Copying " + filecopyList.size() + " file"
+ (filecopyList.size() == 1 ? "" : "s")
+ " to " + destDir.getAbsolutePath());
Enumeration enum = filecopyList.keys();
while (enum.hasMoreElements()) {
String fromFile = (String) enum.nextElement();
String toFile = (String) filecopyList.get(fromFile);
try {
project.copyFile(fromFile, toFile, filtering,
forceOverwrite);
} catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to "
+ toFile + " due to " + ioe.getMessage();
throw new BuildException(msg, ioe, location);
}
}
}
} finally {
filecopyList.clear();
}
}



+ 12
- 6
src/main/org/apache/tools/ant/taskdefs/Copyfile.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* Copyright (c) 2000,2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -66,7 +66,10 @@ import org.apache.tools.ant.BuildException;
*
* @author duncan@x180.com
*
* @deprecated The copyfile task is deprecated. Use copy instead.
* @since Ant 1.1
*
* @deprecated The copyfile task is deprecated since Ant 1.2. Use
* copy instead.
*/

public class Copyfile extends Task {
@@ -96,7 +99,8 @@ public class Copyfile extends Task {
log("DEPRECATED - The copyfile task is deprecated. Use copy instead.");

if (srcFile == null) {
throw new BuildException("The src attribute must be present.", location);
throw new BuildException("The src attribute must be present.",
location);
}
if (!srcFile.exists()) {
@@ -105,14 +109,16 @@ public class Copyfile extends Task {
}

if (destFile == null) {
throw new BuildException("The dest attribute must be present.", location);
throw new BuildException("The dest attribute must be present.",
location);
}

if (srcFile.equals(destFile)) {
log("Warning: src == dest");
log("Warning: src == dest", Project.MSG_WARN);
}

if (forceOverwrite || srcFile.lastModified() > destFile.lastModified()) {
if (forceOverwrite
|| srcFile.lastModified() > destFile.lastModified()) {
try {
project.copyFile(srcFile, destFile, filtering, forceOverwrite);
} catch (IOException ioe) {


Loading…
Cancel
Save