1 7 package com.inversoft.savant.ant.taskdefs; 8 9 10 import java.io.File ; 11 import java.util.Enumeration ; 12 13 import org.apache.tools.ant.BuildException; 14 import org.apache.tools.ant.Project; 15 import org.apache.tools.ant.taskdefs.Copy; 16 import org.apache.tools.ant.types.FilterChain; 17 import org.apache.tools.ant.types.FilterSet; 18 19 20 34 public class UncopyTask extends Copy { 35 36 37 40 public UncopyTask() { 41 forceOverwrite = true; 42 } 43 44 45 48 public void setOverwrite(String overwrite) { 49 throw new BuildException("overwrite not supported for the un-copy task"); 50 } 51 52 55 public FilterChain createFilterChain() { 56 throw new BuildException("filterchain not supported for the un-copy task"); 57 } 58 59 62 public FilterSet createFilterSet() { 63 throw new BuildException("filterset not supported for the un-copy task"); 64 } 65 66 71 protected void doFileOperations() { 72 73 if (fileCopyMap.size() > 0) { 74 log("Un-copying " + fileCopyMap.size() 75 + " file" + (fileCopyMap.size() == 1 ? "" : "s") 76 + " to " + destDir.getAbsolutePath()); 77 78 Enumeration e = fileCopyMap.keys(); 79 while (e.hasMoreElements()) { 80 String fromFile = (String ) e.nextElement(); 81 String [] toFiles = (String []) fileCopyMap.get(fromFile); 82 83 for (int i = 0; i < toFiles.length; i++) { 84 if (fromFile.equals(toFiles[i])) { 85 log("Skipping self-un-copy of " + fromFile, Project.MSG_DEBUG); 86 continue; 87 } 88 89 log("Un-copying " + fromFile + " to " + toFiles[i], Project.MSG_DEBUG); 90 91 File remove = new File (toFiles[i]); 92 if (remove.exists()) { 93 if (!remove.delete()) { 94 throw new BuildException("Failed to un-copy " + 95 fromFile + " to " + toFiles[i]); 96 } 97 } 98 } 99 } 100 } 101 102 if (includeEmpty) { 103 Enumeration e = dirCopyMap.elements(); 104 int count = 0; 105 while (e.hasMoreElements()) { 106 String [] dirs = (String []) e.nextElement(); 107 for (int i = 0; i < dirs.length; i++) { 108 File dir = new File (dirs[i]); 109 if (dir.exists()) { 110 dir.delete(); 111 count++; 112 } 113 } 114 } 115 116 if (count > 0) { 117 log("Un-copied " + count + " empty director" + (count == 1 ? "y" : "ies") + 118 " to " + destDir.getAbsolutePath()); 119 } 120 } 121 } 122 } | Popular Tags |