Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@jakarta.apache.org Received: (qmail 86587 invoked by uid 500); 13 Mar 2001 03:04:07 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk Reply-To: ant-dev@jakarta.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 86549 invoked by uid 500); 13 Mar 2001 03:04:07 -0000 Delivered-To: apmail-jakarta-ant-cvs@apache.org Date: 13 Mar 2001 03:04:06 -0000 Message-ID: <20010313030406.86519.qmail@apache.org> From: conor@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Chmod.java ExecTask.java ExecuteOn.java conor 01/03/12 19:04:06 Modified: src/main/org/apache/tools/ant/taskdefs Chmod.java ExecTask.java ExecuteOn.java Log: Change Chmod task so that the usage 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. Revision Changes Path 1.11 +29 -1 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Chmod.java Index: Chmod.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Chmod.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Chmod.java 2001/01/03 14:18:29 1.10 +++ Chmod.java 2001/03/13 03:04:06 1.11 @@ -71,6 +71,7 @@ public class Chmod extends ExecuteOn { private FileSet defaultSet = new FileSet(); + private boolean defaultSetDefined = false; private boolean havePerm = false; public Chmod() { @@ -98,6 +99,7 @@ * add a name entry on the include list */ public PatternSet.NameEntry createInclude() { + defaultSetDefined = true; return defaultSet.createInclude(); } @@ -105,6 +107,7 @@ * add a name entry on the exclude list */ public PatternSet.NameEntry createExclude() { + defaultSetDefined = true; return defaultSet.createExclude(); } @@ -112,6 +115,7 @@ * add a set of patterns */ public PatternSet createPatternSet() { + defaultSetDefined = true; return defaultSet.createPatternSet(); } @@ -122,6 +126,7 @@ * @param includes the string containing the include patterns */ public void setIncludes(String includes) { + defaultSetDefined = true; defaultSet.setIncludes(includes); } @@ -132,6 +137,7 @@ * @param excludes the string containing the exclude patterns */ public void setExcludes(String excludes) { + defaultSetDefined = true; defaultSet.setExcludes(excludes); } @@ -143,6 +149,7 @@ * shouldn't be used. */ public void setDefaultexcludes(boolean useDefaultExcludes) { + defaultSetDefined = true; defaultSet.setDefaultexcludes(useDefaultExcludes); } @@ -152,11 +159,32 @@ 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); 1.13 +18 -11 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java Index: ExecTask.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ExecTask.java 2001/01/21 00:41:54 1.12 +++ ExecTask.java 2001/03/13 03:04:06 1.13 @@ -218,21 +218,28 @@ } /** - * 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 { 1.12 +2 -18 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java Index: ExecuteOn.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ExecuteOn.java 2001/01/03 14:18:30 1.11 +++ ExecuteOn.java 2001/03/13 03:04:06 1.12 @@ -148,15 +148,7 @@ 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