1 18 package org.apache.tools.ant.types; 19 20 import org.apache.tools.ant.BuildException; 21 import org.apache.tools.ant.Project; 22 23 32 public class TarFileSet extends ArchiveFileSet { 33 34 private boolean userNameSet; 35 private boolean groupNameSet; 36 private boolean userIdSet; 37 private boolean groupIdSet; 38 39 private String userName = ""; 40 private String groupName = ""; 41 private int uid; 42 private int gid; 43 44 45 public TarFileSet() { 46 super(); 47 } 48 49 53 protected TarFileSet(FileSet fileset) { 54 super(fileset); 55 } 56 57 61 protected TarFileSet(TarFileSet fileset) { 62 super(fileset); 63 } 64 65 70 public void setUserName(String userName) { 71 checkTarFileSetAttributesAllowed(); 72 userNameSet = true; 73 this.userName = userName; 74 } 75 76 79 public String getUserName() { 80 if (isReference()) { 81 return ((TarFileSet) getCheckedRef()).getUserName(); 82 } 83 return userName; 84 } 85 86 89 public boolean hasUserNameBeenSet() { 90 return userNameSet; 91 } 92 93 98 public void setUid(int uid) { 99 checkTarFileSetAttributesAllowed(); 100 userIdSet = true; 101 this.uid = uid; 102 } 103 104 107 public int getUid() { 108 if (isReference()) { 109 return ((TarFileSet) getCheckedRef()).getUid(); 110 } 111 return uid; 112 } 113 114 117 public boolean hasUserIdBeenSet() { 118 return userIdSet; 119 } 120 121 126 public void setGroup(String groupName) { 127 checkTarFileSetAttributesAllowed(); 128 groupNameSet = true; 129 this.groupName = groupName; 130 } 131 132 135 public String getGroup() { 136 if (isReference()) { 137 return ((TarFileSet) getCheckedRef()).getGroup(); 138 } 139 return groupName; 140 } 141 142 145 public boolean hasGroupBeenSet() { 146 return groupNameSet; 147 } 148 149 154 public void setGid(int gid) { 155 checkTarFileSetAttributesAllowed(); 156 groupIdSet = true; 157 this.gid = gid; 158 } 159 160 163 public int getGid() { 164 if (isReference()) { 165 return ((TarFileSet) getCheckedRef()).getGid(); 166 } 167 return gid; 168 } 169 170 173 public boolean hasGroupIdBeenSet() { 174 return groupIdSet; 175 } 176 177 181 protected ArchiveScanner newArchiveScanner() { 182 TarScanner zs = new TarScanner(); 183 return zs; 184 } 185 186 194 public void setRefid(Reference r) throws BuildException { 195 if (userNameSet || userIdSet || groupNameSet || groupIdSet) { 196 throw tooManyAttributes(); 197 } 198 super.setRefid(r); 199 } 200 201 207 protected AbstractFileSet getRef(Project p) { 208 dieOnCircularReference(p); 209 Object o = getRefid().getReferencedObject(p); 210 if (o instanceof TarFileSet) { 211 return (AbstractFileSet) o; 212 } else if (o instanceof FileSet) { 213 TarFileSet zfs = new TarFileSet((FileSet) o); 214 configureFileSet(zfs); 215 return zfs; 216 } else { 217 String msg = getRefid().getRefId() + " doesn\'t denote a tarfileset or a fileset"; 218 throw new BuildException(msg); 219 } 220 } 221 222 228 protected void configureFileSet(ArchiveFileSet zfs) { 229 super.configureFileSet(zfs); 230 if (zfs instanceof TarFileSet) { 231 TarFileSet tfs = (TarFileSet) zfs; 232 tfs.setUserName(userName); 233 tfs.setGroup(groupName); 234 tfs.setUid(uid); 235 tfs.setGid(gid); 236 } 237 } 238 239 244 public Object clone() { 245 if (isReference()) { 246 return ((TarFileSet) getRef(getProject())).clone(); 247 } else { 248 return super.clone(); 249 } 250 } 251 252 258 private void checkTarFileSetAttributesAllowed() { 259 if (getProject() == null 260 || (isReference() 261 && (getRefid().getReferencedObject( 262 getProject()) 263 instanceof TarFileSet))) { 264 checkAttributesAllowed(); 265 } 266 } 267 268 } 269 | Popular Tags |