Class ServiceMessage

    • Constructor Detail

      • ServiceMessage

        protected ServiceMessage​(@NotNull
                                 String messageName)
      • ServiceMessage

        protected ServiceMessage​(@NotNull
                                 String messageName,
                                 @Nullable
                                 String argument)
      • ServiceMessage

        protected ServiceMessage​(@NotNull
                                 String messageName,
                                 @NotNull
                                 Map<String,​String> attributes)
    • 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 messages
        parserCallback - 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
      • 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
      • getAttributeValue

        @Nullable
        protected String getAttributeValue​(@NotNull
                                           String attrName)
      • 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 any RequiredAttribute so validation is not performed
        Parameters:
        text - text to parse
        shouldValidate - whether to validate required attributes or not (currently ignored)
        Returns:
        parsed service message
        Throws:
        ParseException - if parsing fails
      • validate

        protected void validate()
                         throws ParseException
        Service message validator checks that all methods which marked with RequiredAttribute annotation 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 message
        attributes - 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 message
        argument - the argument
        Returns:
        service message string
        Since:
        6.0