Class ServiceMessage
- java.lang.Object
-
- jetbrains.buildServer.messages.serviceMessages.ServiceMessage
-
- Direct Known Subclasses:
BuildNumber,MessageWithAttributes,ProgressMessage,PublishArtifacts,RemoteArtifactMessage,TestNavigationInfo
public class ServiceMessage extends 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
Nested Classes Modifier and Type Class Description static classServiceMessage.Timestamp
-
Field Summary
Fields Modifier and Type Field Description static StringARG_ATTRIBUTEstatic StringDISABLEstatic StringENABLEstatic StringPARSE_SERVICE_MESSAGES_INSIDE_TAGThis tag can be used to inform that service message can have other service messages inside its attributes.static StringSERVICE_MESSAGE_ENDstatic StringSERVICE_MESSAGE_STARTstatic StringTAGS_ATRRIBUTEstatic StringTAGS_SEPARATOR
-
Constructor Summary
Constructors Modifier Constructor Description protectedServiceMessage(String messageName)protectedServiceMessage(String messageName, String argument)protectedServiceMessage(String messageName, Map<String,String> attributes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTag(String tag)Adds a new tag to service message.StringasString()Converts this service message to service message stringstatic StringasString(String messageName, String argument)Returns a string representation of a service message with a single argument.static StringasString(String messageName, Map<String,String> attributes)Returns a string representation of a service message with attribute map.StringgetArgument()Map<String,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 otherwiseprotected StringgetAttributeValue(String attrName)ServiceMessage.TimestampgetCreationTimestamp()Returns service message creation timestamp in case it was specified with attribute "timestamp".StringgetFlowId()Returns service message flow id in case it was specified and null otherwiseStringgetMessageName()Collection<String>getTags()static ServiceMessageparse(String text)If message is text message according to the pattern ##teamcity[key...], return parsed message.static voidparse(String text, ServiceMessageParserCallback parserCallback)Accepts mixed text (text that can contain service messages inside) and parser callback.static ServiceMessageparseSimple(String text, boolean shouldValidate)Creates a ServiceMessage instance out of the specified text.voidsetFlowId(String flowId)voidsetTimestamp(Date timestamp)StringtoString()protected voidvalidate()Service message validator checks that all methods which marked withRequiredAttributeannotation return not-null value after initialization.voidvisit(ServiceMessageVisitor visitor)Depending on this service message type calls corresponding method in the supplied visitor.
-
-
-
Field Detail
-
SERVICE_MESSAGE_START
@NotNull public static final String SERVICE_MESSAGE_START
- See Also:
- Constant Field Values
-
SERVICE_MESSAGE_END
@NotNull public static final String SERVICE_MESSAGE_END
- See Also:
- Constant Field Values
-
TAGS_SEPARATOR
public static final String TAGS_SEPARATOR
- See Also:
- Constant Field Values
-
ENABLE
@NonNls public static final String ENABLE
- See Also:
- Constant Field Values
-
DISABLE
@NonNls public static final String DISABLE
- See Also:
- Constant Field Values
-
ARG_ATTRIBUTE
public static final String ARG_ATTRIBUTE
- See Also:
- Constant Field Values
-
TAGS_ATRRIBUTE
public static final String TAGS_ATRRIBUTE
- See Also:
- Constant Field Values
-
PARSE_SERVICE_MESSAGES_INSIDE_TAG
public static final String PARSE_SERVICE_MESSAGES_INSIDE_TAG
This tag can be used to inform that service message can have other service messages inside its attributes.- Since:
- 10.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
parse
@Nullable public static ServiceMessage parse(@NotNull String text) throws 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:
ParseException- if parsing failed
-
parse
public static void parse(@NotNull String text, @NotNull ServiceMessageParserCallback parserCallback)Accepts mixed text (text that can contain service messages inside) and parser callback. Notifies parser callback on any occurrence of the service message or regular text.- Parameters:
text- text with service messagesparserCallback- callback- Since:
- 6.0
-
getMessageName
@NotNull public String getMessageName()
- Returns:
- name part of the service message
-
getArgument
@Nullable public 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 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 Collection<String> getTags()
-
getAttributes
@NotNull public Map<String,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 Date timestamp)
-
setFlowId
public void setFlowId(@NotNull String flowId)
-
addTag
public void addTag(@NotNull String tag)Adds a new tag to service message.- Parameters:
tag- a tag to add- Since:
- 10.0
-
parseSimple
@NotNull public static ServiceMessage parseSimple(@NotNull String text, boolean shouldValidate) throws ParseException
Creates a ServiceMessage instance out of the specified text. Currently the ServiceMessage class doesn't have anyRequiredAttributeso validation is not performed- Parameters:
text- text to parseshouldValidate- whether to validate required attributes or not (currently ignored)- Returns:
- parsed service message
- Throws:
ParseException- if parsing fails
-
validate
protected void validate() throws ParseExceptionService message validator checks that all methods which marked withRequiredAttributeannotation return not-null value after initialization.- Throws:
ParseException
-
asString
@NotNull public 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 String asString(@NotNull String messageName, @NotNull Map<String,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 messageattributes- attribute map- Returns:
- service message string
- Since:
- 6.0
-
asString
@NotNull public static String asString(@NotNull String messageName, @NotNull 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 messageargument- the argument- Returns:
- service message string
- Since:
- 6.0
-
-