stevel 01/11/27 11:25:44 Modified: src/main/org/apache/tools/ant/taskdefs ExecTask.java Log: PR 5025 : Execute still fails when failonerror=false and the error is program not found PR 4345 :Request for addition of "rcproperty" attribute to <exec> The property is called resultproperty; implements immutability in some code that should be replaced by a standalone method in Project. Documentation still TBD. Revision Changes Path 1.19 +31 -5 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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- ExecTask.java 2001/11/27 18:04:52 1.18 +++ ExecTask.java 2001/11/27 19:25:44 1.19 @@ -92,6 +92,7 @@ private FileOutputStream fos = null; private ByteArrayOutputStream baos = null; private String outputprop; + private String resultProperty; /** Controls whether the VM (1.3 and above) is used to execute the command */ private boolean vmLauncher = true; @@ -178,6 +179,27 @@ } /** + * fill a property in with a result. + * when no property is defined: failure to execute + * @since 1.5 + */ + public void setResultProperty(String resultProperty) { + this.resultProperty=resultProperty; + } + + /** + * helper method to set result property to the + * passed in value if appropriate + */ + protected void maybeSetResultPropertyValue(int result) { + String res=Integer.toString(result); + if(resultProperty!=null + && project.getProperty(resultProperty) == null) { + project.setProperty(resultProperty,res); + } + } + + /** * Do the work. */ public void execute() throws BuildException { @@ -257,6 +279,7 @@ int err = -1; // assume the worst err = exe.execute(); + maybeSetResultPropertyValue(err); if (err != 0) { if (failOnError) { throw new BuildException(taskType + " returned: "+err, location); @@ -287,7 +310,11 @@ try { runExecute(exe); } catch (IOException e) { - throw new BuildException("Execute failed: " + e, e, location); + if (failOnError) { + throw new BuildException("Execute failed: ",e, location); + } else { + log("Execute failed: "+e.toString(), Project.MSG_ERR); + } } finally { // close the output file if required logFlush(); @@ -309,10 +336,9 @@ throw new BuildException("Cannot write to "+out, ioe, location); } } else if (outputprop != null) { - // try { - baos = new ByteArrayOutputStream(); - log("Output redirected to ByteArray", Project.MSG_VERBOSE); - return new PumpStreamHandler(baos); + baos = new ByteArrayOutputStream(); + log("Output redirected to ByteArray", Project.MSG_VERBOSE); + return new PumpStreamHandler(baos); } else { return new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN);
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>