1. /*
  2. * Copyright 2000,2002,2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs;
  18. import java.io.File;
  19. import java.io.IOException;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.Project;
  22. import org.apache.tools.ant.Task;
  23. /**
  24. * Copies a file.
  25. *
  26. *
  27. * @since Ant 1.1
  28. *
  29. * @deprecated The copyfile task is deprecated since Ant 1.2. Use
  30. * copy instead.
  31. */
  32. public class Copyfile extends Task {
  33. private File srcFile;
  34. private File destFile;
  35. private boolean filtering = false;
  36. private boolean forceOverwrite = false;
  37. public void setSrc(File src) {
  38. srcFile = src;
  39. }
  40. public void setForceoverwrite(boolean force) {
  41. forceOverwrite = force;
  42. }
  43. public void setDest(File dest) {
  44. destFile = dest;
  45. }
  46. public void setFiltering(String filter) {
  47. filtering = Project.toBoolean(filter);
  48. }
  49. public void execute() throws BuildException {
  50. log("DEPRECATED - The copyfile task is deprecated. Use copy instead.");
  51. if (srcFile == null) {
  52. throw new BuildException("The src attribute must be present.",
  53. getLocation());
  54. }
  55. if (!srcFile.exists()) {
  56. throw new BuildException("src " + srcFile.toString()
  57. + " does not exist.", getLocation());
  58. }
  59. if (destFile == null) {
  60. throw new BuildException("The dest attribute must be present.",
  61. getLocation());
  62. }
  63. if (srcFile.equals(destFile)) {
  64. log("Warning: src == dest", Project.MSG_WARN);
  65. }
  66. if (forceOverwrite
  67. || srcFile.lastModified() > destFile.lastModified()) {
  68. try {
  69. getProject().copyFile(srcFile, destFile, filtering, forceOverwrite);
  70. } catch (IOException ioe) {
  71. String msg = "Error copying file: " + srcFile.getAbsolutePath()
  72. + " due to " + ioe.getMessage();
  73. throw new BuildException(msg);
  74. }
  75. }
  76. }
  77. }