jetbrains.buildServer.messages.serviceMessages
Class ServiceMessage

java.lang.Object
  extended by jetbrains.buildServer.messages.serviceMessages.ServiceMessage
Direct Known Subclasses:
BuildNumber, MessageWithAttributes, ProgressMessage, PublishArtifacts, TestNavigationInfo

public class ServiceMessage
extends java.lang.Object

Utility class to parse messages like ##teamcity[<message name> <param name>='<param value>' <param name>='<param value>'...] or ##teamcity[<message name> '< argument>'] Argument is optional.


Nested Class Summary
static class ServiceMessage.Timestamp
           
 
Field Summary
static java.lang.String ARG_ATTRIBUTE
           
static java.lang.String DISABLE
           
static java.lang.String ENABLE
           
static java.lang.String SERVICE_MESSAGE_START
           
static java.lang.String TAGS_ATRRIBUTE
           
static java.lang.String TAGS_SEPARATOR
           
 
Constructor Summary
protected ServiceMessage(java.lang.String messageName)
           
protected ServiceMessage(java.lang.String messageName, java.util.Map<java.lang.String,java.lang.String> attributes)
           
protected ServiceMessage(java.lang.String messageName, java.lang.String argument)
           
 
Method Summary
 java.lang.String asString()
          Converts this service message to service message string
static java.lang.String asString(java.lang.String messageName, java.util.Map<java.lang.String,java.lang.String> attributes)
          Returns a string representation of a service message with attribute map.
static java.lang.String asString(java.lang.String messageName, java.lang.String argument)
          Returns a string representation of a service message with a single argument.
 java.lang.String getArgument()
           
 java.util.Map<java.lang.String,java.lang.String> getAttributes()
          Returns map of parameters of the message in format ##teamcity[<message name> <param name>='<param value>' <param name>='<param value>'...] if parameters were specified, and empty map otherwise
protected  java.lang.String getAttributeValue(java.lang.String attrName)
           
 ServiceMessage.Timestamp getCreationTimestamp()
          Returns service message creation timestamp in case it was specified with attribute "timestamp".
 java.lang.String getFlowId()
          Returns service message flow id in case it was specified and null otherwise
 java.lang.String getMessageName()
           
 java.util.Collection<java.lang.String> getTags()
           
static ServiceMessage parse(java.lang.String text)
          If message is text message according to the pattern ##teamcity[key...], return parsed message.
static void parse(java.lang.String mixedText, ServiceMessageParserCallback parserCallback)
          Accepts mixed text (text that can contain service messages inside) and parser callback.
 void setFlowId(java.lang.String flowId)
           
 void setTimestamp(java.util.Date timestamp)
           
static java.util.List<java.lang.String> splitTextToPotentialMessages(java.lang.String text)
          Deprecated. will be removed in further versions
 java.lang.String toString()
           
 void visit(ServiceMessageVisitor visitor)
          Depending on this service message type calls corresponding method in the supplied visitor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SERVICE_MESSAGE_START

@NotNull
public static final java.lang.String SERVICE_MESSAGE_START
See Also:
Constant Field Values

TAGS_SEPARATOR

public static final java.lang.String TAGS_SEPARATOR
See Also:
Constant Field Values

ENABLE

@NonNls
public static final java.lang.String ENABLE
See Also:
Constant Field Values

DISABLE

@NonNls
public static final java.lang.String DISABLE
See Also:
Constant Field Values

ARG_ATTRIBUTE

public static final java.lang.String ARG_ATTRIBUTE
See Also:
Constant Field Values

TAGS_ATRRIBUTE

public static final java.lang.String TAGS_ATRRIBUTE
See Also:
Constant Field Values
Constructor Detail

ServiceMessage

protected ServiceMessage(@NotNull
                         java.lang.String messageName)

ServiceMessage

protected ServiceMessage(@NotNull
                         java.lang.String messageName,
                         @Nullable
                         java.lang.String argument)

ServiceMessage

protected ServiceMessage(@NotNull
                         java.lang.String messageName,
                         @NotNull
                         java.util.Map<java.lang.String,java.lang.String> attributes)
Method Detail

parse

@Nullable
public static ServiceMessage parse(@NotNull
                                            java.lang.String text)
                            throws java.text.ParseException
If message is text message according to the pattern ##teamcity[key...], return parsed message. Otherwise, return null Throws ParseException if message is a service message but its arguments cannot be parsed.

Parameters:
text - text to parse
Returns:
see above
Throws:
java.text.ParseException - if parse failed

parse

public static void parse(@NotNull
                         java.lang.String mixedText,
                         @NotNull
                         ServiceMessageParserCallback parserCallback)
Accepts mixed text (text that can contain service messages inside) and parser callback. Notifies parser callback on any occurence of the service message or regular text.

Parameters:
mixedText - text with service messages
parserCallback - callback
Since:
6.0

splitTextToPotentialMessages

@NotNull
public static java.util.List<java.lang.String> splitTextToPotentialMessages(@NotNull
                                                                                    java.lang.String text)
Deprecated. will be removed in further versions

Finds "##teamcity[...]" substrings in the specified text and splits the text to potential service messages (doesn't parse them) and regular text between them

Parameters:
text - specified text
Returns:
splitted text

getMessageName

@NotNull
public java.lang.String getMessageName()
Returns:
name part of the service message

getArgument

@Nullable
public java.lang.String getArgument()
Returns:
argument text for message ##teamcity[<message name> '< argument>'] or null

getCreationTimestamp

@Nullable
public ServiceMessage.Timestamp getCreationTimestamp()
Returns service message creation timestamp in case it was specified with attribute "timestamp". If it was not returns null. The format of timestamp has to be "yyyy-MM-dd'T'HH:mm:ss.SSSZ" or "yyyy-MM-dd'T'HH:mm:ss.SSS". Returns null if attribute value does not match the format.

Returns:
service message creation timestamp in case it was correctly specified with attribute "timestamp", null otherwise.

getFlowId

@Nullable
public java.lang.String getFlowId()
Returns service message flow id in case it was specified and null otherwise

Returns:
service message flow id in case it was specified and null otherwise

getTags

@NotNull
public java.util.Collection<java.lang.String> getTags()

getAttributes

@NotNull
public java.util.Map<java.lang.String,java.lang.String> getAttributes()
Returns map of parameters of the message in format ##teamcity[<message name> <param name>='<param value>' <param name>='<param value>'...] if parameters were specified, and empty map otherwise

Returns:
see above

visit

public void visit(@NotNull
                  ServiceMessageVisitor visitor)
Depending on this service message type calls corresponding method in the supplied visitor.

Parameters:
visitor - visitor

setTimestamp

public void setTimestamp(@NotNull
                         java.util.Date timestamp)

setFlowId

public void setFlowId(@NotNull
                      java.lang.String flowId)

getAttributeValue

@Nullable
protected java.lang.String getAttributeValue(@NotNull
                                                      java.lang.String attrName)

asString

@NotNull
public java.lang.String asString()
Converts this service message to service message string

Returns:
serialized service message object with ##teamcity[ prefix
Since:
6.0

asString

@NotNull
public static java.lang.String asString(@NotNull
                                                java.lang.String messageName,
                                                @NotNull
                                                java.util.Map<java.lang.String,java.lang.String> attributes)
Returns a string representation of a service message with attribute map. This method is useful when there is a need of outputting service text without creating a ServiceMessage instance.

Parameters:
messageName - name of the message
attributes - attribute map
Returns:
service message string
Since:
6.0

asString

@NotNull
public static java.lang.String asString(@NotNull
                                                java.lang.String messageName,
                                                @NotNull
                                                java.lang.String argument)
Returns a string representation of a service message with a single argument. This method is useful when there is a need of outputting service text without creating a ServiceMessage instance.

Parameters:
messageName - name of the message
argument - the argument
Returns:
service message string
Since:
6.0

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object