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.taskdefs.condition.Os; 26 import org.apache.tools.ant.types.Commandline; 27 import org.apache.tools.ant.types.FileSet; 28 import org.apache.tools.ant.types.PatternSet; 29 30 39 public class Chmod extends ExecuteOn { 40 41 private FileSet defaultSet = new FileSet(); 42 private boolean defaultSetDefined = false; 43 private boolean havePerm = false; 44 45 48 public Chmod() { 49 super.setExecutable("chmod"); 50 super.setParallel(true); 51 super.setSkipEmptyFilesets(true); 52 } 53 54 60 public void setProject(Project project) { 61 super.setProject(project); 62 defaultSet.setProject(project); 63 } 64 65 69 public void setFile(File src) { 70 FileSet fs = new FileSet(); 71 fs.setFile(src); 72 addFileset(fs); 73 } 74 75 79 public void setDir(File src) { 80 defaultSet.setDir(src); 81 } 82 83 87 public void setPerm(String perm) { 88 createArg().setValue(perm); 89 havePerm = true; 90 } 91 92 96 public PatternSet.NameEntry createInclude() { 97 defaultSetDefined = true; 98 return defaultSet.createInclude(); 99 } 100 101 105 public PatternSet.NameEntry createExclude() { 106 defaultSetDefined = true; 107 return defaultSet.createExclude(); 108 } 109 110 114 public PatternSet createPatternSet() { 115 defaultSetDefined = true; 116 return defaultSet.createPatternSet(); 117 } 118 119 125 public void setIncludes(String includes) { 126 defaultSetDefined = true; 127 defaultSet.setIncludes(includes); 128 } 129 130 136 public void setExcludes(String excludes) { 137 defaultSetDefined = true; 138 defaultSet.setExcludes(excludes); 139 } 140 141 148 public void setDefaultexcludes(boolean useDefaultExcludes) { 149 defaultSetDefined = true; 150 defaultSet.setDefaultexcludes(useDefaultExcludes); 151 } 152 153 156 protected void checkConfiguration() { 157 if (!havePerm) { 158 throw new BuildException("Required attribute perm not set in chmod", 159 getLocation()); 160 } 161 162 if (defaultSetDefined && defaultSet.getDir(getProject()) != null) { 163 addFileset(defaultSet); 164 } 165 super.checkConfiguration(); 166 } 167 168 172 public void execute() throws BuildException { 173 179 if (defaultSetDefined || defaultSet.getDir(getProject()) == null) { 180 try { 181 super.execute(); 182 } finally { 183 if (defaultSetDefined && defaultSet.getDir(getProject()) != null) { 184 filesets.removeElement(defaultSet); 185 } 186 } 187 } else if (isValidOs()) { 188 Execute execute = prepareExec(); 190 Commandline cloned = (Commandline) cmdl.clone(); 191 cloned.createArgument().setValue(defaultSet.getDir(getProject()) 192 .getPath()); 193 try { 194 execute.setCommandline(cloned.getCommandline()); 195 runExecute(execute); 196 } catch (IOException e) { 197 throw new BuildException("Execute failed: " + e, e, getLocation()); 198 } finally { 199 logFlush(); 201 } 202 } 203 } 204 205 212 public void setExecutable(String e) { 213 throw new BuildException(getTaskType() 214 + " doesn\'t support the executable attribute", getLocation()); 215 } 216 217 224 public void setCommand(Commandline cmdl) { 225 throw new BuildException(getTaskType() 226 + " doesn\'t support the command attribute", getLocation()); 227 } 228 229 235 public void setSkipEmptyFilesets(boolean skip) { 236 throw new BuildException(getTaskType() 237 + " doesn\'t support the skipemptyfileset attribute", getLocation()); 238 } 239 240 246 public void setAddsourcefile(boolean b) { 247 throw new BuildException(getTaskType() 248 + " doesn\'t support the addsourcefile attribute", getLocation()); 249 } 250 251 256 protected boolean isValidOs() { 257 return Os.isFamily(Os.FAMILY_UNIX) && super.isValidOs(); 258 } 259 } 260 | Popular Tags |