ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 24877] - exec task doesn't handle error conditions well
Date Fri, 21 Nov 2003 11:53:03 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24877>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24877

exec task doesn't handle error conditions well





------- Additional Comments From peter.reilly@corvil.com  2003-11-21 11:53 -------
Opps I did a send by accidient:
One could extend ExecTask with an onerror nested element:

  <target name="init">
    <bsh:beanshelldef name="exec2" classname="Exec2">
      import org.apache.tools.ant.taskdefs.condition.Condition;
      import org.apache.tools.ant.taskdefs.ExecTask;
      import org.apache.tools.ant.taskdefs.Sequential;
      public class Exec2 extends ExecTask implements Condition {
          private boolean runOk = false;
          private Sequential onError;
          protected void maybeSetResultPropertyValue(int result) {
             super.maybeSetResultPropertyValue(result);
             runOk = (result == 0);
         }
         public void addOnError(Sequential onError) {
             this.onError = onError;
         }
         public boolean eval() {
             execute();
             return runOk;
         }
         public void execute() {
             super.execute();
             if (!runOk &amp;&amp; onError != null) {
                onError.perform();
             }
         }
      }
    </bsh:beanshelldef>
  </target>

and use it like so:

  <target name="onerror" depends="init">
    <exec2 executable="sh"
           errorproperty="sh.error.output"
           failonerror="false">
      <arg value="error.sh"/>
      <onError>
        <echo>exec failed with error output: ${sh.error.output}</echo>
      </onError>
    </exec2>
  </target>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message