public abstract class AntLogger extends Object
AntEvent
s during
one or more AntSession
s.
There can be several loggers active on a given session,
so AntEvent.consume()
may be used to cooperate.
Implementations may be registered to default Lookup
.
Loggers are notified of events in the order of their registration in lookup.
A logger will always first be asked if it is interested in a given session;
if it declines, it will receive no further events for that session.
Otherwise it will normally receive buildStarted(org.apache.tools.ant.module.spi.AntEvent)
; then some combination of
target, task, and message logged events; then buildFinished(org.apache.tools.ant.module.spi.AntEvent)
.
(Or it may receive just buildInitializationFailed(org.apache.tools.ant.module.spi.AntEvent)
.)
A logger may not assume that target and task events are properly
nested in any way, due to Ant's <parallel>
task and
other complexities such as <import>
handling. Events may
also be delivered from the originating script or any subscripts, again with
no guaranteed nesting behavior. A logger may not assume that it will not
receive any events after buildFinished(org.apache.tools.ant.module.spi.AntEvent)
.
Various mask methods permit loggers to declare themselves uninterested in
some kinds of events. Such events will not be delivered to them. Loggers should
declare themselves interested only in events they will actually use in some way,
to permit the Ant engine to minimize the number of events delivered. Note that
loggers which do not declare themselves interested in the given session will
not receive buildStarted(org.apache.tools.ant.module.spi.AntEvent)
, buildFinished(org.apache.tools.ant.module.spi.AntEvent)
, or
buildInitializationFailed(org.apache.tools.ant.module.spi.AntEvent)
at all, and loggers not additionally interested
in all scripts will not receive buildInitializationFailed(org.apache.tools.ant.module.spi.AntEvent)
.
A logger should not keep any state as a rule; this would be a memory leak, and
also a logger may be called from multiple threads with different sessions.
Use AntSession.getCustomData(org.apache.tools.ant.module.spi.AntLogger)
and AntSession.putCustomData(org.apache.tools.ant.module.spi.AntLogger, java.lang.Object)
instead.
Loggers may not make calls to the session, event, or task structure objects outside
the dynamic scope of an event callback.
This is an abstract class so that new event types or masks may be added in the future.
To prevent possible conflicts, implementors are forbidden to define other methods
which take a single parameter of type AntEvent
or which have a name beginning
with the string interested
.
The Ant module registers one logger at position 100 in META-INF/services lookup which may or may not handle any events which have not already been consumed (marking them consumed itself) and will typically process message logged events by printing them to the output somehow, using hyperlinks for common file error patterns such as /path/to/File.java:34: some message. It may also handle sequences of messages logged within a task in the format
/path/to/File.java:34: you cannot throw a bogus exception here throw new Exception("bogus!"); ^
by linking to the column number indicated by the caret (^).
Please Note: Using System.out
or System.err
in your subclass
will add the messages to the build's output, not IDE log file. The behaviour is not part of the
API contract though and can be changed in the future.
Modifier and Type | Field and Description |
---|---|
static String[] |
ALL_TARGETS
Special constant indicating the logger is interested in receiving
all target events.
|
static String[] |
ALL_TASKS
Special constant indicating the logger is interested in receiving
all task events.
|
static String[] |
NO_TARGETS
Special constant indicating the logger is not interested in receiving
any target events.
|
static String[] |
NO_TASKS
Special constant indicating the logger is not interested in receiving
any task events.
|
Modifier | Constructor and Description |
---|---|
protected |
AntLogger()
No-op constructor for implementors.
|
Modifier and Type | Method and Description |
---|---|
void |
buildFinished(AntEvent event)
Fired once when a build is finished.
|
void |
buildInitializationFailed(AntEvent event)
Fired only if the build could not even be started.
|
void |
buildStarted(AntEvent event)
Fired once when a build is started.
|
boolean |
interestedInAllScripts(AntSession session)
Mark whether this logger is interested in any Ant script.
|
int[] |
interestedInLogLevels(AntSession session)
Mark which kinds of message log events this logger is interested in.
|
boolean |
interestedInScript(File script,
AntSession session)
Mark whether this logger is interested in a given Ant script.
|
boolean |
interestedInSession(AntSession session)
Mark whether this logger is interested in a given Ant session.
|
String[] |
interestedInTargets(AntSession session)
Mark which kinds of targets this logger is interested in.
|
String[] |
interestedInTasks(AntSession session)
Mark which kinds of tasks this logger is interested in.
|
void |
messageLogged(AntEvent event)
Fired when a message is logged.
|
void |
targetFinished(AntEvent event)
Fired when a target is finished.
|
void |
targetStarted(AntEvent event)
Fired when a target is started.
|
void |
taskFinished(AntEvent event)
Fired when a task is finished.
|
void |
taskStarted(AntEvent event)
Fired when a task is started.
|
public static final String[] NO_TARGETS
public static final String[] ALL_TARGETS
public static final String[] NO_TASKS
public static final String[] ALL_TASKS
public void buildInitializationFailed(AntEvent event)
AntEvent.getException()
will be non-null.
The default implementation does nothing.event
- the associated event objectpublic void buildStarted(AntEvent event)
event
- the associated event objectpublic void buildFinished(AntEvent event)
event
- the associated event objectAntEvent.getException()
public void targetStarted(AntEvent event)
AntEvent.getTargetName()
will be non-null (as can happen in some circumstances with
<import>
, for example).
The default implementation does nothing.event
- the associated event objectpublic void targetFinished(AntEvent event)
AntEvent.getTargetName()
will be non-null.
The default implementation does nothing.event
- the associated event objectpublic void taskStarted(AntEvent event)
AntEvent.getTaskName()
or
AntEvent.getTaskStructure()
will be non-null, though they will
usually be defined.
AntEvent.getTargetName()
might also be null.
The default implementation does nothing.event
- the associated event objectpublic void taskFinished(AntEvent event)
AntEvent.getTaskName()
or
AntEvent.getTaskStructure()
will be non-null.
AntEvent.getTargetName()
might also be null.
The default implementation does nothing.event
- the associated event objectpublic void messageLogged(AntEvent event)
event
- the associated event objectpublic boolean interestedInSession(AntSession session)
session
- a session which is about to be startpublic boolean interestedInAllScripts(AntSession session)
session
- the relevant sessionpublic boolean interestedInScript(File script, AntSession session)
interestedInAllScripts(org.apache.tools.ant.module.spi.AntSession)
is false.
Only events with a defined script according to AntEvent.getScriptLocation()
which this logger is interested in will be delivered.
Note that a few events have no defined script and so will only
be delivered to loggers interested in all scripts; typically this
applies to debugging messages when a project is just being configured.
Note also that a single session can involve many different scripts.script
- a particular build scriptsession
- the relevant sessionpublic String[] interestedInTargets(AntSession session)
AntEvent.getTargetName()
is not null, such as task
start and finish events, and message log events.
If NO_TARGETS
, no events with specific targets will be sent to it.
If a specific list, only events with defined target names included in the list
will be sent to it.
If ALL_TARGETS
, all events not otherwise excluded will be sent to it.session
- the relevant sessionNO_TARGETS
public String[] interestedInTasks(AntSession session)
AntEvent.getTaskName()
is not null, such as
message log events.
If NO_TASKS
, no events with specific tasks will be sent to it.
If a specific list, only events with defined task names included in the list
will be sent to it.
If ALL_TASKS
, all events not otherwise excluded will be sent to it.session
- the relevant sessionNO_TASKS
public int[] interestedInLogLevels(AntSession session)
session
- the relevant sessionAntEvent.LOG_INFO
; by default, an empty listAntSession.getVerbosity()
Built on June 4 2024. | Copyright © 2017-2024 Apache Software Foundation. All Rights Reserved.