Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270032 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 23 years ago
parent
commit
f15a929e0a
1 changed files with 31 additions and 5 deletions
  1. +31
    -5
      src/main/org/apache/tools/ant/taskdefs/ExecTask.java

+ 31
- 5
src/main/org/apache/tools/ant/taskdefs/ExecTask.java View File

@@ -92,6 +92,7 @@ public class ExecTask extends Task {
private FileOutputStream fos = null; private FileOutputStream fos = null;
private ByteArrayOutputStream baos = null; private ByteArrayOutputStream baos = null;
private String outputprop; private String outputprop;
private String resultProperty;


/** Controls whether the VM (1.3 and above) is used to execute the command */ /** Controls whether the VM (1.3 and above) is used to execute the command */
private boolean vmLauncher = true; private boolean vmLauncher = true;
@@ -177,6 +178,27 @@ public class ExecTask extends Task {
return cmdl.createArgument(); return cmdl.createArgument();
} }


/**
* 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. * Do the work.
*/ */
@@ -257,6 +279,7 @@ public class ExecTask extends Task {
int err = -1; // assume the worst int err = -1; // assume the worst


err = exe.execute(); err = exe.execute();
maybeSetResultPropertyValue(err);
if (err != 0) { if (err != 0) {
if (failOnError) { if (failOnError) {
throw new BuildException(taskType + " returned: "+err, location); throw new BuildException(taskType + " returned: "+err, location);
@@ -287,7 +310,11 @@ public class ExecTask extends Task {
try { try {
runExecute(exe); runExecute(exe);
} catch (IOException e) { } 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 { } finally {
// close the output file if required // close the output file if required
logFlush(); logFlush();
@@ -309,10 +336,9 @@ public class ExecTask extends Task {
throw new BuildException("Cannot write to "+out, ioe, location); throw new BuildException("Cannot write to "+out, ioe, location);
} }
} else if (outputprop != null) { } 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 { } else {
return new LogStreamHandler(this, return new LogStreamHandler(this,
Project.MSG_INFO, Project.MSG_WARN); Project.MSG_INFO, Project.MSG_WARN);


Loading…
Cancel
Save