Class AppendTextBadgeSummaryAction

java.lang.Object
com.jenkinsci.plugins.badge.action.AbstractBadgeAction
com.jenkinsci.plugins.badge.action.BadgeSummaryAction
org.jvnet.hudson.plugins.groovypostbuild.AppendTextBadgeSummaryAction
All Implemented Interfaces:
Action, ModelObject, Serializable

public class AppendTextBadgeSummaryAction extends com.jenkinsci.plugins.badge.action.BadgeSummaryAction
A BadgeSummaryAction that restores the appendText methods badge 2.8 offered, which badge 3.x dropped in favor of AbstractBadgeAction.setText(String).

The three overloads below reproduce badge 2.8's behavior exactly, byte for byte, except that they build on top of AbstractBadgeAction.getText() rather than a private field, since badge 3.x exposes no other way to read back the text already set. getText() returns the markup-formatter-translated value (or the raw value when blank), so appended text is layered onto that translated value, same as it always was.

AppendTextBadgeSummaryActionConverter substitutes a plain BadgeSummaryAction for this class when Run.XSTREAM2 marshals it, so the fields written to build.xml are the plain badge action's, not this class's own extra state. The outer XML element is still tagged with this class's fully qualified name - that is how XStream remembers this is what actually ran when the build happened - but it carries a resolves-to attribute pointing at BadgeSummaryAction. XStream's HierarchicalStreams.readClassType() consults resolves-to before ever trying to resolve the element name to a real class, so the element stays readable even after this class is gone: on a downgrade to a controller that never had it, or the day this deprecated shim is removed, which is the entire point of a deprecation path. Verified empirically, not assumed: renaming the outer tag to a class that exists nowhere on the classpath still deserializes correctly, purely from resolves-to.

This substitution is deliberately an XStream Converter rather than a writeReplace() method: writeReplace() is honored by any Java serialization, not just Run.XSTREAM2, and Pipeline's CPS interpreter persists a running program's local variables with plain ObjectOutputStream across every durability checkpoint. A writeReplace()-based shim would come back from that round trip as a plain BadgeSummaryAction too, silently losing appendText the next time a script called it after a controller restart. See AppendTextBadgeSummaryActionConverter for the detail.

rawIcon/rawText/rawLink shadow the values actually passed to the constructor and to setIcon(java.lang.String)/setText(java.lang.String)/setLink(java.lang.String), because toPlainBadgeSummaryAction() must not read them back through getIcon()/ getText()/getLink(): those getters return a transformed view (backwards-compatible icon name rewriting, markup-formatter translation, and silently dropping a link that fails a pattern check, respectively), not the value that was actually stored, and baking the transformed view into the "raw" field of the replacement would corrupt the badge on every subsequent read. These fields do not need to be transient and there is no readResolve(): nothing about this class's own state is ever written to XML in the first place - the converter substitutes a plain BadgeSummaryAction, which does not have these fields, before any of this class's own fields would be walked. The one case that does not round-trip is a shim element authored or migrated some other way - with badge's own fields but none of these three - since the superclass's real values are then reachable only through the same transforming getters this class must not launder as "raw"; deliberately, that leaves the shadow fields null rather than fabricating a value, so a save before the next appendText/setText/ setIcon/setLink call on such an object would persist an empty badge instead of silently corrupting its icon, text, or link.

See Also:
  • Constructor Details

  • Method Details

    • setIcon

      public void setIcon(String icon)
      Overrides:
      setIcon in class com.jenkinsci.plugins.badge.action.AbstractBadgeAction
    • setText

      public void setText(String text)
      Overrides:
      setText in class com.jenkinsci.plugins.badge.action.AbstractBadgeAction
    • setLink

      public void setLink(String link)
      Overrides:
      setLink in class com.jenkinsci.plugins.badge.action.AbstractBadgeAction
    • appendText

      public void appendText(String text)
    • appendText

      public void appendText(String text, boolean escapeHtml)
    • appendText

      public void appendText(String text, boolean escapeHtml, boolean bold, boolean italic, String color)