Package jetbrains.buildServer.parameters
Class ReferencesResolverUtil
- java.lang.Object
-
- jetbrains.buildServer.parameters.ReferencesResolverUtil
-
public class ReferencesResolverUtil extends Object
Contains utility methods simplifying references processing in build and run parameters- Author:
- Yegor.Yarko Date: 10.08.2008
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ReferencesResolverUtil.ReferencesResolverListener
-
Constructor Summary
Constructors Constructor Description ReferencesResolverUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsReference(String value)
Returns true if the specified value contains at least one reference.static boolean
containsReference(String value, String[] prefixes, boolean allowAnyCharactersInReferenceName)
Returns true if the specified value contains at least one reference that starts from one of the prefixes.static String
escape(String value)
Replaces single % with %%static Set<String>
findParametersReferringToKey(Map<String,String> parameters, Collection<String> keys)
static Pair<Boolean,String>
getLastElement(String value)
See javadoc forgetLastElement(String, String[], boolean)
static Pair<Boolean,String>
getLastElement(String value, String[] prefixes, boolean allowAnyCharactersInReferenceName)
Returns last element of the specified value.static Set<String>
getReferences(String value)
Returns all of the references present in the specified value.static Set<String>
getReferences(String value, String[] prefixes, boolean allowAnyCharactersInReferenceNames)
Finds all of the references present in the specified value that start with one of the prefixes.static boolean
isReference(String value)
Returns true if the specified value contains exactly one parameter reference without any static text.static boolean
isValidReference(String ref)
static String
makeReference(String propertyName)
Makes a TeamCity %foo% like reference from a given property namestatic boolean
mayContainReference(String value)
static void
resolve(String value, ReferencesResolverUtil.ReferencesResolverListener listener)
Processes the value calling appropriate listener methods for each found static text of reference name.static String
unescape(String value)
Accepts value which may contain escaped sequences: %%, these sequences will be unescaped, converted to one %
-
-
-
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 processlistener
- 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 checkprefixes
- 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)
-
findParametersReferringToKey
@NotNull public static Set<String> findParametersReferringToKey(@NotNull Map<String,String> parameters, @NotNull Collection<String> keys)
-
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 checkprefixes
- only return references starting with specified prefixesallowAnyCharactersInReferenceNames
- if true then reference can contain any character- Returns:
- the references found
-
getLastElement
@NotNull public static Pair<Boolean,String> getLastElement(@NotNull String value)
See javadoc forgetLastElement(String, String[], boolean)
- Since:
- 10.0
-
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 textExamples: 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 checkprefixes
- 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
-
-