|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecthudson.console.ConsoleNote<T>
T
- Contextual model object that this console is associated with, such as Run
.public abstract class ConsoleNote<T>
Data that hangs off from a console output.
A ConsoleNote
can be put into a console output while it's being written, and it represents
a machine readable information about a particular position of the console output.
When Hudson is reading back a console output for display, a ConsoleNote
is used
to trigger ConsoleAnnotator
, which in turn uses the information in the note to
generate markup. In this way, we can overlay richer information on top of the console output.
ConsoleAnnotatorFactory
Compared to ConsoleAnnotatorFactory
, the main advantage of ConsoleNote
is that
it can be emitted into the output by the producer of the output (or by a filter), which can
have a much better knowledge about the context of what's being executed.
ConsoleNote
that indicates an error, instead of printing an error message as plain text. The annotate(Object, MarkupText, int)
method will then generate the proper error message, with all the HTML markup that makes error message
more user friendly.
BuildListener
can place a ConsoleNote
every time a new target execution starts. These notes can be then later used to build the outline
that shows what targets are executed, hyperlinked to their corresponding locations in the build output.
Doing these things by ConsoleAnnotatorFactory
would be a lot harder, as they can only rely
on the pattern matching of the output.
ConsoleNote
s are serialized and gzip compressed into a byte sequence and then embedded into the
console output text file, with a bit of preamble/postamble to allow tools to ignore them. In this way
ConsoleNote
always sticks to a particular point in the console output.
This design allows descendant processes of Hudson to emit ConsoleNote
s. For example, Ant forked
by a shell forked by Hudson can put an encoded note in its stdout, and Hudson will correctly understands that.
The preamble and postamble includes a certain ANSI escape sequence designed in such a way to minimize garbage
if this output is observed by a human being directly.
Because of this persistence mechanism, ConsoleNote
s need to be serializable, and care should be taken
to reduce footprint of the notes, if you are putting a lot of notes. Serialization format compatibility
is also important, although ConsoleNote
s that failed to deserialize will be simply ignored, so the
worst thing that can happen is that you just lose some notes.
ConsoleNote
can have associated script.js and style.css (put them
in the same resource directory that you normally put Jelly scripts), which will be loaded into
the HTML page whenever the console notes are used. This allows you to use minimal markup in
code generation, and do the styling in CSS and perform the rest of the interesting work as a CSS behaviour/JavaScript.
ConsoleAnnotationDescriptor
,
Functions.generateConsoleAnnotationScriptAndStylesheet()
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from interface hudson.ExtensionPoint |
---|
ExtensionPoint.LegacyInstancesAreScopedToHudson |
Field Summary | |
---|---|
static byte[] |
POSTAMBLE
Post amble is the ANSI escape sequence that brings back the echo. |
static String |
POSTAMBLE_STR
|
static byte[] |
PREAMBLE
Preamble of the encoded form. |
static String |
PREAMBLE_STR
|
Constructor Summary | |
---|---|
ConsoleNote()
|
Method Summary | |
---|---|
abstract ConsoleAnnotator |
annotate(T context,
MarkupText text,
int charPos)
When the line of a console output that this annotation is attached is read by someone, a new ConsoleNote is de-serialized and this method is invoked to annotate that line. |
String |
encode()
Works like encodeTo(Writer) but obtain the result as a string. |
void |
encodeTo(OutputStream out)
Prints this note into a stream. |
void |
encodeTo(Writer out)
Prints this note into a writer. |
static int |
findPreamble(byte[] buf,
int start,
int len)
Locates the preamble in the given buffer. |
ConsoleAnnotationDescriptor |
getDescriptor()
Gets the descriptor for this instance. |
static ConsoleNote |
readFrom(DataInputStream in)
Reads a note back from its encoded form. |
static List<String> |
removeNotes(Collection<String> logLines)
Removes the embedded console notes in the given log lines. |
static String |
removeNotes(String line)
Removes the embedded console notes in the given log line. |
static void |
skip(DataInputStream in)
Skips the encoded console note. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PREAMBLE_STR
public static final String POSTAMBLE_STR
public static final byte[] PREAMBLE
public static final byte[] POSTAMBLE
Constructor Detail |
---|
public ConsoleNote()
Method Detail |
---|
public abstract ConsoleAnnotator annotate(T context, MarkupText text, int charPos)
ConsoleNote
is de-serialized and this method is invoked to annotate that line.
context
- The object that owns the console output in question.text
- Represents a line of the console output being annotated.charPos
- The character position in 'text' where this annotation is attached.
public ConsoleAnnotationDescriptor getDescriptor()
Describable
Descriptor
is a singleton for every concrete Describable
implementation, so if a.getClass()==b.getClass() then
a.getDescriptor()==b.getDescriptor() must hold.
getDescriptor
in interface Describable<ConsoleNote<?>>
public void encodeTo(OutputStream out) throws IOException
The most typical use of this is n.encodedTo(System.out)
where stdout is connected to Hudson.
The encoded form doesn't include any new line character to work better in the line-oriented nature
of ConsoleAnnotator
.
IOException
public void encodeTo(Writer out) throws IOException
Technically, this method only works if the Writer
to OutputStream
encoding is ASCII compatible.
IOException
public String encode() throws IOException
encodeTo(Writer)
but obtain the result as a string.
IOException
public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException
in
- Must point to the beginning of a preamble.
IOException
ClassNotFoundException
public static void skip(DataInputStream in) throws IOException
IOException
public static int findPreamble(byte[] buf, int start, int len)
public static List<String> removeNotes(Collection<String> logLines)
public static String removeNotes(String line)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |