1 17 package net.sourceforge.groboutils.codecoverage.v2.ant.zip; 18 19 import java.io.File ; 20 import java.util.Stack ; 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.DirectoryScanner; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.types.Reference; 25 26 import org.apache.tools.ant.types.FileSet; 28 import org.apache.tools.ant.types.AbstractFileSet; 30 31 44 public class ZipFileSet extends FileSet { 45 46 51 public static final int DEFAULT_DIR_MODE = 52 UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM; 53 54 59 public static final int DEFAULT_FILE_MODE = 60 UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM; 61 62 private File srcFile = null; 63 private String prefix = ""; 64 private String fullpath = ""; 65 private boolean hasDir = false; 66 private int fileMode = DEFAULT_FILE_MODE; 67 private int dirMode = DEFAULT_DIR_MODE; 68 69 private boolean fileModeHasBeenSet = false; 70 private boolean dirModeHasBeenSet = false; 71 72 public ZipFileSet() { 73 super(); 74 } 75 76 protected ZipFileSet(FileSet fileset) { 77 super(fileset); 78 } 79 80 protected ZipFileSet(ZipFileSet fileset) { 81 super(fileset); 82 srcFile = fileset.srcFile; 83 prefix = fileset.prefix; 84 fullpath = fileset.fullpath; 85 hasDir = fileset.hasDir; 86 fileMode = fileset.fileMode; 87 dirMode = fileset.dirMode; 88 fileModeHasBeenSet = fileset.fileModeHasBeenSet; 89 dirModeHasBeenSet = fileset.dirModeHasBeenSet; 90 } 91 92 96 public void setDir(File dir) throws BuildException { 97 if (isReference()) { 98 throw tooManyAttributes(); 99 } 100 if (srcFile != null) { 101 throw new BuildException("Cannot set both dir and src attributes"); 102 } else { 103 super.setDir(dir); 104 hasDir = true; 105 } 106 } 107 108 114 public void setSrc(File srcFile) { 115 if (isReference()) { 116 throw tooManyAttributes(); 117 } 118 if (hasDir) { 119 throw new BuildException("Cannot set both dir and src attributes"); 120 } 121 this.srcFile = srcFile; 122 } 123 124 129 public File getSrc(Project p) { 130 if (isReference()) { 131 return ((ZipFileSet) getRef(p)).getSrc(p); 132 } 133 return srcFile; 134 } 135 136 142 public void setPrefix(String prefix) { 143 if (!prefix.equals("") && !fullpath.equals("")) { 144 throw new BuildException("Cannot set both fullpath and prefix attributes"); 145 } 146 this.prefix = prefix; 147 } 148 149 152 public String getPrefix(Project p) { 153 if (isReference()) { 154 return ((ZipFileSet) getRef(p)).getPrefix(p); 155 } 156 return prefix; 157 } 158 159 165 public void setFullpath(String fullpath) { 166 if (!prefix.equals("") && !fullpath.equals("")) { 167 throw new BuildException("Cannot set both fullpath and prefix attributes"); 168 } 169 this.fullpath = fullpath; 170 } 171 172 175 public String getFullpath(Project p) { 176 if (isReference()) { 177 return ((ZipFileSet) getRef(p)).getFullpath(p); 178 } 179 return fullpath; 180 } 181 182 187 public DirectoryScanner getDirectoryScanner(Project p) { 188 if (isReference()) { 189 return getRef(p).getDirectoryScanner(p); 190 } 191 if (srcFile != null) { 192 ZipScanner zs = new ZipScanner(); 193 zs.setSrc(srcFile); 194 super.setDir(p.getBaseDir()); 195 setupDirectoryScanner(zs, p); 196 zs.init(); 197 return zs; 198 } else { 199 return super.getDirectoryScanner(p); 200 } 201 } 202 203 210 public void setFileMode(String octalString) { 211 fileModeHasBeenSet = true; 212 this.fileMode = 213 UnixStat.FILE_FLAG | Integer.parseInt(octalString, 8); 214 } 215 216 219 public int getFileMode(Project p) { 220 if (isReference()) { 221 return ((ZipFileSet) getRef(p)).getFileMode(p); 222 } 223 return fileMode; 224 } 225 226 231 public boolean hasFileModeBeenSet() { 232 if (isReference()) { 233 return ((ZipFileSet) getRef(getProject())).hasFileModeBeenSet(); 234 } 235 return fileModeHasBeenSet; 236 } 237 238 245 public void setDirMode(String octalString) { 246 dirModeHasBeenSet = true; 247 this.dirMode = 248 UnixStat.DIR_FLAG | Integer.parseInt(octalString, 8); 249 } 250 251 254 public int getDirMode(Project p) { 255 if (isReference()) { 256 return ((ZipFileSet) getRef(p)).getDirMode(p); 257 } 258 return dirMode; 259 } 260 261 266 public boolean hasDirModeBeenSet() { 267 if (isReference()) { 268 return ((ZipFileSet) getRef(getProject())).hasDirModeBeenSet(); 269 } 270 return dirModeHasBeenSet; 271 } 272 273 277 protected AbstractFileSet getRef(Project p) { 278 if (!isChecked()) { 279 Stack stk = new Stack (); 280 stk.push(this); 281 dieOnCircularReference(stk, p); 282 } 283 Object o = getRefid().getReferencedObject(p); 284 if (o instanceof ZipFileSet) { 285 return (AbstractFileSet) o; 286 } else if (o instanceof FileSet) { 287 ZipFileSet zfs = new ZipFileSet((FileSet) o); 288 zfs.setPrefix(prefix); 289 zfs.setFullpath(fullpath); 290 zfs.fileModeHasBeenSet = fileModeHasBeenSet; 291 zfs.fileMode = fileMode; 292 zfs.dirModeHasBeenSet = dirModeHasBeenSet; 293 zfs.dirMode = dirMode; 294 return zfs; 295 } else { 296 String msg = getRefid().getRefId() + " doesn\'t denote a zipfileset or a fileset"; 297 throw new BuildException(msg); 298 } 299 } 300 305 public Object clone() { 306 if (isReference()) { 307 return ((ZipFileSet) getRef(getProject())).clone(); 308 } else { 309 return super.clone(); 310 } 311 } 312 313 314 public Reference getRefid() { 316 return this.ref; 317 } 318 319 public boolean isChecked() { 321 return this.checked; 322 } 323 } 324 | Popular Tags |