Browse Source

Further development for 7330. Allow errors to be sent to the

Ant log when redirecting output.

PR:	7330


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274004 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
e562c76491
3 changed files with 30 additions and 4 deletions
  1. +9
    -0
      docs/manual/CoreTasks/exec.html
  2. +20
    -3
      src/main/org/apache/tools/ant/taskdefs/ExecTask.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java

+ 9
- 0
docs/manual/CoreTasks/exec.html View File

@@ -64,6 +64,15 @@ Windows executable and is not aware of Cygwin conventions.
redirected. </td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">logError</td>
<td valign="top">This attribute is used when you wish to see error output in Ant's
log and you are redirecting output to a file/property. The error
output will not be included in the output file/property. If you
redirect error with the &quot;error&quot; or &quot;errorProperty&quot;
attributes, this will have no effect.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">append</td>
<td valign="top">whether output and error files should be appended to or overwritten.


+ 20
- 3
src/main/org/apache/tools/ant/taskdefs/ExecTask.java View File

@@ -89,6 +89,8 @@ public class ExecTask extends Task {
private String os;
private File out;
private File error;

private boolean logError = false;
private File dir;
protected boolean failOnError = false;
@@ -173,6 +175,15 @@ public class ExecTask extends Task {
this.out = out;
}

/**
* Controls whether error output of exec is logged. This is only useful
* when output is being redirected and error output is desired in the
* Ant log
*/
public void setLogError(boolean logError) {
this.logError = logError;
}
/**
* File the error stream of the process is redirected to.
*
@@ -485,7 +496,8 @@ public class ExecTask extends Task {
if (outputprop != null) {
baos = new ByteArrayOutputStream();
log("Output redirected to ByteArray", Project.MSG_VERBOSE);
log("Output redirected to property: " + outputprop,
Project.MSG_VERBOSE);
if (out == null) {
outputStream = baos;
} else {
@@ -498,11 +510,15 @@ public class ExecTask extends Task {
errorStream = outputStream;
}

if (logError) {
errorStream = new LogOutputStream(this, Project.MSG_WARN);
}
if (error != null) {
try {
errorStream
= new FileOutputStream(error.getAbsolutePath(), append);
log("Error redirected to " + out, Project.MSG_VERBOSE);
log("Error redirected to " + error, Project.MSG_VERBOSE);
} catch (FileNotFoundException fne) {
throw new BuildException("Cannot write to " + error, fne,
getLocation());
@@ -514,7 +530,8 @@ public class ExecTask extends Task {
if (errorProperty != null) {
errorBaos = new ByteArrayOutputStream();
log("Error redirected to ByteArray", Project.MSG_VERBOSE);
log("Error redirected to property: " + errorProperty,
Project.MSG_VERBOSE);
if (error == null) {
errorStream = errorBaos;
} else {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java View File

@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without


Loading…
Cancel
Save