Class TeamCityProperties
- java.lang.Object
-
- jetbrains.buildServer.serverSide.TeamCityProperties
-
public class TeamCityProperties extends Object
Encapsulates the access to internal properties. Those properties are read from JVM system properties or user-provided properties file.The access is provided via
get*methods, all of which first look up the key in a file, then * loop it up inSystem.getProperties(). The properties file is optional, but if it exists, it is reread on each modification (sleep interval is 10 seconds by default, and can be set manually using"teamcity.internal.properties.reread.interval.ms"property) .All access methods are thread-safe and never throw exceptions. Performance note: all access methods are never blocked to read the value from the file. In case the file is removed, last used properties map is in effect.
Also note that the errors are not reported to the log, because the log environment might be not initialized yet (it can require a system property for that =).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTeamCityProperties.ModelRepresents properties access model.
-
Constructor Summary
Constructors Constructor Description TeamCityProperties()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Pair<Properties,Properties>getAllProperties()Deprecated.usegetModel().getUserDefinedPropertiesandgetModel().getSystemProperties()static booleangetBoolean(String key)Returns the property value as a boolean, orfalseif not set.static booleangetBoolean(String key, boolean defaultValue)Returns the property value as a boolean, or defaultValue if not set.static booleangetBooleanOrTrue(String key)Returns the property value as a boolean, ortrueif not set.static floatgetFloat(String key)Returns the property value as a float, or0.0fif not set.static floatgetFloat(String key, float defaultValue)Returns the property value as a float.static intgetInteger(String key)Returns the property value as an integer, or0if not set.static intgetInteger(String key, int defaultValue)Returns the property value as an integer.static longgetIntervalMilliseconds(String key, long defaultMillis)Returns the property value representing a time interval in milliseconds.static longgetLong(String key)Returns the property value as a long, or0if not set.static longgetLong(String key, long defaultValue)Returns the property value as a long.static TeamCityProperties.ModelgetModel()static Map<String,String>getPropertiesWithPrefix(String keyPrefix)static StringgetProperty(String key)Returns the property value as a string, or empty string if not set.static StringgetProperty(String key, String defaultValue)Returns the property value as a string.static StringgetPropertyOrNull(String key)Returns the property value as a string, ornullif not set.static StringgetPropertyOrNull(String key, String defaultValue)Returns the property value as a string, ornullif not set.static booleanisInitialized()protected static voidsetBaseModel()Updates current TeamCity properties model to the default.protected static voidsetModel(TeamCityProperties.Model model)Updates current TeamCity properties model.
-
-
-
Method Detail
-
getBoolean
public static boolean getBoolean(@NotNull String key)Returns the property value as a boolean, orfalseif not set.- Parameters:
key- the property key- Returns:
- property value as a boolean
-
getBooleanOrTrue
public static boolean getBooleanOrTrue(@NotNull String key)Returns the property value as a boolean, ortrueif not set.- Parameters:
key- the property key- Returns:
- property value as a boolean
-
getBoolean
public static boolean getBoolean(@NotNull String key, boolean defaultValue)Returns the property value as a boolean, or defaultValue if not set.- Parameters:
key- the property keydefaultValue- default value for the property- Returns:
- property value as a boolean
- Since:
- 2022.10
-
getInteger
public static int getInteger(@NotNull String key)Returns the property value as an integer, or0if not set.- Parameters:
key- the property key- Returns:
- property value as an integer
-
getIntervalMilliseconds
public static long getIntervalMilliseconds(@NotNull String key, long defaultMillis)Returns the property value representing a time interval in milliseconds.The value can be defined in the properties file several ways: - {key} or {key}.millis to define interval in milliseconds - {key}.seconds to define interval in seconds - {key}.minutes to define interval in minutes - {key}.hours to define interval in hours
- Since:
- 2018.1
-
getInteger
public static int getInteger(@NotNull String key, int defaultValue)Returns the property value as an integer.- Parameters:
key- the property keydefaultValue- default value- Returns:
- property value as an integer
-
getFloat
public static float getFloat(@NotNull String key)Returns the property value as a float, or0.0fif not set.- Parameters:
key- the property key- Returns:
- property value as a float
-
getFloat
public static float getFloat(@NotNull String key, float defaultValue)Returns the property value as a float.- Parameters:
key- the property keydefaultValue- default value- Returns:
- property value as a float
-
getLong
public static long getLong(@NotNull String key)Returns the property value as a long, or0if not set.- Parameters:
key- the property key- Returns:
- property value as a long
-
getLong
public static long getLong(@NotNull String key, long defaultValue)Returns the property value as a long.- Parameters:
key- the property keydefaultValue- default value- Returns:
- property value as a long
-
getProperty
@NotNull public static String getProperty(@NotNull String key)
Returns the property value as a string, or empty string if not set.- Parameters:
key- the property key- Returns:
- property value as a string
-
getPropertyOrNull
@Nullable public static String getPropertyOrNull(@NotNull String key)
Returns the property value as a string, ornullif not set.- Parameters:
key- the property key- Returns:
- property value as a string
-
getPropertyOrNull
@Nullable public static String getPropertyOrNull(@NotNull String key, @Nullable String defaultValue)
Returns the property value as a string, ornullif not set.- Parameters:
key- the property keydefaultValue- default value- Returns:
- property value as a string
- Since:
- 7.1.1
-
getProperty
@NotNull public static String getProperty(@NotNull String key, @NotNull String defaultValue)
Returns the property value as a string.- Parameters:
key- the property keydefaultValue- default value- Returns:
- property value as a string
-
getPropertiesWithPrefix
@NotNull public static Map<String,String> getPropertiesWithPrefix(@NotNull String keyPrefix)
- Parameters:
keyPrefix- key prefix- Returns:
- all properties with key starting with the specified prefix
- Since:
- 2019.1
-
getAllProperties
@NotNull @Deprecated public static Pair<Properties,Properties> getAllProperties()
Deprecated.usegetModel().getUserDefinedPropertiesandgetModel().getSystemProperties()Returns twoPropertiesinstances containing system properties: the first one contains properties from the internal file, the second one contains all Java process properties (System.getProperties()).Note that entries from the first map overwrite the ones from the second map.
- Returns:
- all TeamCity properties in two maps
-
getModel
@NotNull public static TeamCityProperties.Model getModel()
- Returns:
- currently set properties model
- Since:
- 8.0
-
isInitialized
public static boolean isInitialized()
- Returns:
- whether the properties are initialized (model is set)
- Since:
- 2017.1
-
setModel
protected static void setModel(@NotNull TeamCityProperties.Model model)Updates current TeamCity properties model. This method is for TeamCity internal usage only.- Parameters:
model- new model- Since:
- 8.0
-
setBaseModel
protected static void setBaseModel()
Updates current TeamCity properties model to the default. This method is for TeamCity internal usage only.- Since:
- 2021.2
-
-