Class DiagnosticScanner

java.lang.Object
java.io.OutputStream
hudson.console.LineTransformationOutputStream
io.jenkins.plugins.dotnet.console.DiagnosticScanner
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class DiagnosticScanner extends LineTransformationOutputStream
Scanner to detect diagnostic messages (warnings and errors) in the output of .NET commands. Also sees the error/warning summary lines for MSBuild-based commands and sets properties to the respective counts.

It currently uses hardcoded 'Error(s)' and 'Warning(s)' strings, so if the node has a non-English language configured, the processing will likely fail. It may be enough to have a few well-known alternatives for these string, but assumptions about message format and word order may still cause problems.

  • Constructor Details

    • DiagnosticScanner

      public DiagnosticScanner(@NonNull OutputStream out, @NonNull Charset charset)
      Creates a new scanner.
      Parameters:
      out - The output stream to decorate.
      charset - The character set in use.
  • Method Details

    • getErrors

      public int getErrors()
      Gets the number of errors reported by an MSBuild-based command in its build summary.
      Returns:
      The number of errors reported; 0 if no build summary was seen.
    • getWarnings

      public int getWarnings()
      Gets the number of warnings reported by an MSBuild-based command in its build summary.
      Returns:
      The number of warnings reported; 0 if no build summary was seen.
    • close

      public void close() throws IOException
      Closes this scanner; this forces end-of-line processing and then closes the wrapped output stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class LineTransformationOutputStream
      Throws:
      IOException - When thrown by either LineTransformationOutputStream.close() or OutputStream.close().
    • flush

      public void flush() throws IOException
      Flushes the wrapped output stream.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - When thrown by OutputStream.flush().
    • eol

      protected void eol(byte[] lineBytes, int lineLength) throws IOException
      Scans a line of output, then forwards it to the wrapped output stream.
      Specified by:
      eol in class LineTransformationOutputStream
      Parameters:
      lineBytes - The raw line contents, including any line terminator.
      lineLength - The length of the line within lineBytes.
      Throws:
      IOException - When thrown by OutputStream.write(byte[], int, int).
    • writeCompletionMessage

      public void writeCompletionMessage(int rc)
      Writes the command completion message to the stream wrapped by this scanner. This uses a specific marker (COMPLETION_MESSAGE_EXIT_CODE_MARKER) in order to add separate markup for the message text and the return code information.
      Parameters:
      rc - The command's return code.