1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.Project; 25 import org.apache.tools.ant.Task; 26 27 35 36 public class Copyfile extends Task { 37 38 private File srcFile; 39 private File destFile; 40 private boolean filtering = false; 41 private boolean forceOverwrite = false; 42 43 47 public void setSrc(File src) { 48 srcFile = src; 49 } 50 51 57 public void setForceoverwrite(boolean force) { 58 forceOverwrite = force; 59 } 60 61 65 public void setDest(File dest) { 66 destFile = dest; 67 } 68 69 74 public void setFiltering(String filter) { 75 filtering = Project.toBoolean(filter); 76 } 77 78 82 public void execute() throws BuildException { 83 log("DEPRECATED - The copyfile task is deprecated. Use copy instead."); 84 85 if (srcFile == null) { 86 throw new BuildException("The src attribute must be present.", 87 getLocation()); 88 } 89 90 if (!srcFile.exists()) { 91 throw new BuildException("src " + srcFile.toString() 92 + " does not exist.", getLocation()); 93 } 94 95 if (destFile == null) { 96 throw new BuildException("The dest attribute must be present.", 97 getLocation()); 98 } 99 100 if (srcFile.equals(destFile)) { 101 log("Warning: src == dest", Project.MSG_WARN); 102 } 103 104 if (forceOverwrite 105 || srcFile.lastModified() > destFile.lastModified()) { 106 try { 107 getProject().copyFile(srcFile, destFile, filtering, forceOverwrite); 108 } catch (IOException ioe) { 109 String msg = "Error copying file: " + srcFile.getAbsolutePath() 110 + " due to " + ioe.getMessage(); 111 throw new BuildException(msg); 112 } 113 } 114 } 115 } 116 | Popular Tags |