Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 43133 invoked from network); 27 Nov 2001 19:42:50 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 27 Nov 2001 19:42:50 -0000 Received: (qmail 18618 invoked by uid 97); 27 Nov 2001 19:42:36 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 18505 invoked by uid 97); 27 Nov 2001 19:42:34 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 18418 invoked by uid 97); 27 Nov 2001 19:42:33 -0000 Date: 27 Nov 2001 19:25:44 -0000 Message-ID: <20011127192544.1855.qmail@icarus.apache.org> From: stevel@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs ExecTask.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 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: For additional commands, e-mail: