org.apache.catalina.ant
abstract public class: BaseRedirectorHelperTask [javadoc |
source]
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.catalina.ant.BaseRedirectorHelperTask
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
JMXAccessorQueryTask, JMXAccessorTask, ResourcesTask, RemoveTask, ServerinfoTask, AbstractCatalinaTask, JMXQueryTask, UndeployTask, ValidatorTask, JMXGetTask, JMXAccessorSetTask, ListTask, InstallTask, JMXSetTask, SessionsTask, ReloadTask, StopTask, JMXAccessorGetTask, JMXAccessorUnregisterTask, JKStatusUpdateTask, RolesTask, DeployTask, StartTask, JMXAccessorInvokeTask, JMXAccessorCreateTask
Abstract base class to add output redirection support for Catalina
Ant tasks. These tasks require Ant 1.5 or later.
WARNING: due to depends chain, Ant could call a Task
more than once and this can affect the output redirection when configured.
If you are collecting the output in a property, it will collect the output
of only the first run, since Ant properties are immutable and once created
they cannot be changed.
If you are collecting output in a file the file will be overwritten with the
output of the last run, unless you set append="true", in which case each run
will append it's output to the file.
- author:
Gabriele - Garuglieri
- version:
$ - Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
- since:
5.5 -
| Field Summary |
|---|
| protected Redirector | redirector | Redirector helper |
| protected RedirectorElement | redirectorElement | Redirector element for this task |
| protected OutputStream | redirectOutStream | The stream for info output |
| protected OutputStream | redirectErrStream | The stream for error output |
| PrintStream | redirectOutPrintStream | The print stream for info output |
| PrintStream | redirectErrPrintStream | The print stream for error output |
| protected boolean | failOnError | Whether to fail (with a BuildException) if
ManagerServlet returns an error. The default behavior is
to do so.
This flag does not control parameters checking. If the task is called
with wrong or invalid parameters, it will throw BuildException
independently from the setting of this flag. |
| protected boolean | redirectOutput | true true when output redirection is requested for this task .
Default is to log on Ant log. |
| protected boolean | redirectorConfigured | will be set to true when the configuration of the Redirector is
complete. |
| protected boolean | alwaysLog | Flag which indicates that, if redirected, output should also be
always sent to the log. Default is that otput is sent only to
redirected streams. |
| Method from org.apache.catalina.ant.BaseRedirectorHelperTask Summary: |
|---|
|
addConfiguredRedirector, closeRedirector, handleErrorFlush, handleErrorOutput, handleFlush, handleFlush, handleOutput, handleOutput, isFailOnError, openRedirector, setAlwaysLog, setAppend, setCreateEmptyFiles, setError, setErrorProperty, setFailonerror, setLogError, setOutput, setOutputproperty |
| Methods from org.apache.tools.ant.Task: |
|---|
|
bindToOwner, execute, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, init, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType |
| Method from org.apache.catalina.ant.BaseRedirectorHelperTask Detail: |
public void addConfiguredRedirector(RedirectorElement redirectorElement) {
if (this.redirectorElement != null) {
throw new BuildException("Cannot have > 1 nested < redirector >s");
} else {
this.redirectorElement = redirectorElement;
}
}
Add a RedirectorElement to this task. |
protected void closeRedirector() {
try {
if (redirectOutput) {
redirector.complete();
}
} catch (IOException ioe) {
log("Error closing redirector: "
+ ioe.getMessage(), Project.MSG_ERR);
}
/*
* Due to depends chain, Ant could call the Task more than once,
* this is to prevent that we attempt to reuse the previuosly
* closed Streams.
*/
redirectOutStream = null;
redirectOutPrintStream = null;
redirectErrStream = null;
redirectErrPrintStream = null;
}
Ask redirector to close all the streams. It is necessary to call this method
before leaving the Task to have the Streams flush their contents. If you are
collecting output in a property, it will be created only if this method is
called, otherwise you'll find it unset. |
protected void handleErrorFlush(String output) {
handleErrorOutput(output);
redirectErrPrintStream.flush();
}
Handles error output with the ERR priority and flushes the stream. |
protected void handleErrorOutput(String output) {
if (redirectOutput) {
if (redirectErrPrintStream == null) {
openRedirector();
}
redirectErrPrintStream.println(output);
if (alwaysLog) {
log(output, Project.MSG_ERR);
}
} else {
log(output, Project.MSG_ERR);
}
}
Handles error output with the ERR priority. |
protected void handleFlush(String output) {
handleOutput(output);
redirectOutPrintStream.flush();
}
Handles output with the INFO priority and flushes the stream. |
protected void handleFlush(String output,
int priority) {
if (priority == Project.MSG_ERR) {
handleErrorFlush(output);
} else {
handleFlush(output);
}
}
Handles output with ERR priority to error stream and all other
pritorities to output stream, then flushes the stream. |
protected void handleOutput(String output) {
if (redirectOutput) {
if (redirectOutPrintStream == null) {
openRedirector();
}
redirectOutPrintStream.println(output);
if (alwaysLog) {
log(output, Project.MSG_INFO);
}
} else {
log(output, Project.MSG_INFO);
}
}
Handles output with the INFO priority. |
protected void handleOutput(String output,
int priority) {
if (priority == Project.MSG_ERR) {
handleErrorOutput(output);
} else {
handleOutput(output);
}
}
Handles output with ERR priority to error stream and all other
pritorities to output stream. |
public boolean isFailOnError() {
return failOnError;
}
Returns the value of the failOnError
property. |
protected void openRedirector() {
if (! redirectorConfigured) {
configureRedirector();
}
if (redirectOutput) {
redirector.createStreams();
redirectOutStream = redirector.getOutputStream();
redirectOutPrintStream = new PrintStream(redirectOutStream);
redirectErrStream = redirector.getErrorStream();
redirectErrPrintStream = new PrintStream(redirectErrStream);
}
}
Set up properties on the Redirector and create output streams. |
public void setAlwaysLog(boolean alwaysLog) {
this.alwaysLog = alwaysLog;
//redirector.setAlwaysLog(alwaysLog);
redirectOutput = true;
}
If true, (error and non-error) output will be redirected
as specified while being sent to Ant's logging mechanism as if no
redirection had taken place. Defaults to false.
Actually handled internally, with Ant 1.6.3 it will be handled by
the Redirector itself. |
public void setAppend(boolean append) {
redirector.setAppend(append);
redirectOutput = true;
}
If true, append output to existing file. |
public void setCreateEmptyFiles(boolean createEmptyFiles) {
redirector.setCreateEmptyFiles(createEmptyFiles);
redirectOutput = true;
}
Whether output and error files should be created even when empty.
Defaults to true. |
public void setError(File error) {
redirector.setError(error);
redirectOutput = true;
}
File the error output of the task is redirected to. |
public void setErrorProperty(String errorProperty) {
redirector.setErrorProperty(errorProperty);
redirectOutput = true;
}
Property name whose value should be set to the error of
the task.. |
public void setFailonerror(boolean fail) {
failOnError = fail;
}
Whether to fail (with a BuildException) if
ManagerServlet returns an error. The default behavior is
to do so. |
public void setLogError(boolean logError) {
redirector.setLogError(logError);
redirectOutput = true;
}
Controls whether error output is logged. This is only useful
when output is being redirected and error output is desired in the
Ant log |
public void setOutput(File out) {
redirector.setOutput(out);
redirectOutput = true;
}
File the output of the task is redirected to. |
public void setOutputproperty(String outputProperty) {
redirector.setOutputProperty(outputProperty);
redirectOutput = true;
}
Property name whose value should be set to the output of
the task. |