Class ReferencesResolverUtil


  • public class ReferencesResolverUtil
    extends Object
    Contains utility methods simplifying references processing in build and run parameters
    Author:
    Yegor.Yarko Date: 10.08.2008
    • Constructor Detail

      • ReferencesResolverUtil

        public ReferencesResolverUtil()
    • Method Detail

      • makeReference

        @NotNull
        public static String makeReference​(@NotNull
                                           String propertyName)
        Makes a TeamCity %foo% like reference from a given property name
        Parameters:
        propertyName - parameter name
        Returns:
        reference to a given parameter
        Since:
        6.5.4
      • resolve

        public static void resolve​(@NotNull
                                   String value,
                                   @NotNull
                                   ReferencesResolverUtil.ReferencesResolverListener listener)
        Processes the value calling appropriate listener methods for each found static text of reference name. This method considers as reference any non-empty text enclosed with "%" symbols. A reference can contain spaces.
        Parameters:
        value - value to process
        listener - listener to be used
      • unescape

        @NotNull
        public static String unescape​(@NotNull
                                      String value)
        Accepts value which may contain escaped sequences: %%, these sequences will be unescaped, converted to one %
        Parameters:
        value - value
        Returns:
        unescaped value
      • escape

        @NotNull
        public static String escape​(@NotNull
                                    String value)
        Replaces single % with %%
        Parameters:
        value - value
        Returns:
        escaped value
      • containsReference

        public static boolean containsReference​(@NotNull
                                                String value)
        Returns true if the specified value contains at least one reference. Only references that do not contain spaces in the name are found.
        Parameters:
        value - value to check
        Returns:
        true if at least one reference found
      • containsReference

        public static boolean containsReference​(@NotNull
                                                String value,
                                                @NotNull
                                                String[] prefixes,
                                                boolean allowAnyCharactersInReferenceName)
        Returns true if the specified value contains at least one reference that starts from one of the prefixes.
        Parameters:
        value - value to check
        prefixes - prefixes of the references searched. If array is empty, any token between "%" is considered a reference.
        allowAnyCharactersInReferenceName - true to allow spaces or any other characters in the references (compatibility mode) and false otherwise.
        Returns:
        true if at least one reference found
      • isReference

        public static boolean isReference​(@NotNull
                                          String value)
        Returns true if the specified value contains exactly one parameter reference without any static text.
        Parameters:
        value - value to check
        Returns:
        true if single reference found
      • mayContainReference

        public static boolean mayContainReference​(@NotNull
                                                  String value)
      • getReferences

        public static Set<String> getReferences​(@NotNull
                                                String value)
        Returns all of the references present in the specified value. Only references that do not contain spaces in the name are found.
        Parameters:
        value - value to check
        Returns:
        all of the references present in the specified value
      • getReferences

        public static Set<String> getReferences​(@NotNull
                                                String value,
                                                @NotNull
                                                String[] prefixes,
                                                boolean allowAnyCharactersInReferenceNames)
        Finds all of the references present in the specified value that start with one of the prefixes.
        Parameters:
        value - value to check
        prefixes - only return references starting with specified prefixes
        allowAnyCharactersInReferenceNames - if true then reference can contain any character
        Returns:
        the references found
      • getLastElement

        @NotNull
        public static Pair<Boolean,​String> getLastElement​(@NotNull
                                                                String value,
                                                                @NotNull
                                                                String[] prefixes,
                                                                boolean allowAnyCharactersInReferenceName)
        Returns last element of the specified value. Pair.first is true if element is reference, false otherwise Pair.second is element string: reference key in case of reference or simple text

        Examples: for "a%b%c" last element is Pair(false, "c") for "a%b%" last element is Pair(true, "b") for "abc" last element is Pair(false, "abc")

        Parameters:
        value - value to check
        prefixes - prefixes of the references searched. If array is empty, any token between "%" is considered a reference.
        allowAnyCharactersInReferenceName - true to allow spaces or any other characters in the references and false otherwise.
        Returns:
        Pair representing last part of input string, see above.
        Since:
        10.0
      • isValidReference

        public static boolean isValidReference​(@NotNull
                                               String ref)
        Parameters:
        ref - reference key to check
        Returns:
        true if specified string can be used as a reference: %ref%
        Since:
        2018.1