<chmod dir="${build.dir}" perm="ug+rwx"/>
works. This was being used in the Alexandria project and seems
reasonable usage but was not in fact supported.
Catching this usage is somewhat messy however.
I factored out the code for executing the command into a final method
runExecute so that I could invoke it from chmod. This means ExecTask has
runExec and runExecute which may be confusing.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268815 13f79535-47bb-0310-9956-ffa450edef68
remotes/1764475186634205561/tmp_c5133337751719b6f1a8e921697e1ed980c64cfd
| @@ -71,6 +71,7 @@ import java.util.*; | |||
| public class Chmod extends ExecuteOn { | |||
| private FileSet defaultSet = new FileSet(); | |||
| private boolean defaultSetDefined = false; | |||
| private boolean havePerm = false; | |||
| public Chmod() { | |||
| @@ -98,6 +99,7 @@ public class Chmod extends ExecuteOn { | |||
| * add a name entry on the include list | |||
| */ | |||
| public PatternSet.NameEntry createInclude() { | |||
| defaultSetDefined = true; | |||
| return defaultSet.createInclude(); | |||
| } | |||
| @@ -105,6 +107,7 @@ public class Chmod extends ExecuteOn { | |||
| * add a name entry on the exclude list | |||
| */ | |||
| public PatternSet.NameEntry createExclude() { | |||
| defaultSetDefined = true; | |||
| return defaultSet.createExclude(); | |||
| } | |||
| @@ -112,6 +115,7 @@ public class Chmod extends ExecuteOn { | |||
| * add a set of patterns | |||
| */ | |||
| public PatternSet createPatternSet() { | |||
| defaultSetDefined = true; | |||
| return defaultSet.createPatternSet(); | |||
| } | |||
| @@ -122,6 +126,7 @@ public class Chmod extends ExecuteOn { | |||
| * @param includes the string containing the include patterns | |||
| */ | |||
| public void setIncludes(String includes) { | |||
| defaultSetDefined = true; | |||
| defaultSet.setIncludes(includes); | |||
| } | |||
| @@ -132,6 +137,7 @@ public class Chmod extends ExecuteOn { | |||
| * @param excludes the string containing the exclude patterns | |||
| */ | |||
| public void setExcludes(String excludes) { | |||
| defaultSetDefined = true; | |||
| defaultSet.setExcludes(excludes); | |||
| } | |||
| @@ -143,6 +149,7 @@ public class Chmod extends ExecuteOn { | |||
| * shouldn't be used. | |||
| */ | |||
| public void setDefaultexcludes(boolean useDefaultExcludes) { | |||
| defaultSetDefined = true; | |||
| defaultSet.setDefaultexcludes(useDefaultExcludes); | |||
| } | |||
| @@ -152,12 +159,33 @@ public class Chmod extends ExecuteOn { | |||
| location); | |||
| } | |||
| if (defaultSet.getDir(project) != null) { | |||
| if (defaultSetDefined && defaultSet.getDir(project) != null) { | |||
| addFileset(defaultSet); | |||
| } | |||
| super.checkConfiguration(); | |||
| } | |||
| public void execute() throws BuildException { | |||
| if (defaultSetDefined) { | |||
| super.execute(); | |||
| } | |||
| else if (!defaultSetDefined && defaultSet.getDir(project) != null) { | |||
| // we are chmodding the given directory | |||
| createArg().setValue(defaultSet.getDir(project).getPath()); | |||
| Execute execute = prepareExec(); | |||
| try { | |||
| execute.setCommandline(cmdl.getCommandline()); | |||
| runExecute(execute); | |||
| } catch (IOException e) { | |||
| throw new BuildException("Execute failed: " + e, e, location); | |||
| } finally { | |||
| // close the output file if required | |||
| logFlush(); | |||
| } | |||
| } | |||
| } | |||
| public void setExecutable(String e) { | |||
| throw new BuildException(taskType+" doesn\'t support the executable attribute", location); | |||
| } | |||
| @@ -218,21 +218,28 @@ public class ExecTask extends Task { | |||
| } | |||
| /** | |||
| * Run the command using the given Execute instance. | |||
| * A Utility method for this classes and subclasses to run an Execute instance (an external command). | |||
| */ | |||
| protected void runExec(Execute exe) throws BuildException { | |||
| protected final void runExecute(Execute exe) throws IOException { | |||
| int err = -1; // assume the worst | |||
| try { | |||
| exe.setCommandline(cmdl.getCommandline()); | |||
| err = exe.execute(); | |||
| if (err != 0) { | |||
| if (failOnError) { | |||
| throw new BuildException("Exec returned: "+err, location); | |||
| } else { | |||
| log("Result: " + err, Project.MSG_ERR); | |||
| } | |||
| err = exe.execute(); | |||
| if (err != 0) { | |||
| if (failOnError) { | |||
| throw new BuildException(taskType + " returned: "+err, location); | |||
| } else { | |||
| log("Result: " + err, Project.MSG_ERR); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * Run the command using the given Execute instance. This may be overidden by subclasses | |||
| */ | |||
| protected void runExec(Execute exe) throws BuildException { | |||
| exe.setCommandline(cmdl.getCommandline()); | |||
| try { | |||
| runExecute(exe); | |||
| } catch (IOException e) { | |||
| throw new BuildException("Execute failed: " + e, e, location); | |||
| } finally { | |||
| @@ -148,15 +148,7 @@ public class ExecuteOn extends ExecTask { | |||
| log("Executing " + Commandline.toString(command), | |||
| Project.MSG_VERBOSE); | |||
| exe.setCommandline(command); | |||
| err = exe.execute(); | |||
| if (err != 0) { | |||
| if (failOnError) { | |||
| throw new BuildException("Exec returned: "+err, | |||
| location); | |||
| } else { | |||
| log("Result: " + err, Project.MSG_ERR); | |||
| } | |||
| } | |||
| runExecute(exe); | |||
| } else { | |||
| for (int j=0; j<s.length; j++) { | |||
| @@ -164,15 +156,7 @@ public class ExecuteOn extends ExecTask { | |||
| log("Executing " + Commandline.toString(command), | |||
| Project.MSG_VERBOSE); | |||
| exe.setCommandline(command); | |||
| err = exe.execute(); | |||
| if (err != 0) { | |||
| if (failOnError) { | |||
| throw new BuildException("Exec returned: "+err, | |||
| location); | |||
| } else { | |||
| log("Result: " + err, Project.MSG_ERR); | |||
| } | |||
| } | |||
| runExecute(exe); | |||
| } | |||
| } | |||
| } | |||