Class TeamCityProperties
- java.lang.Object
-
- jetbrains.buildServer.serverSide.TeamCityProperties
-
public class TeamCityProperties extends java.lang.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 interface
TeamCityProperties.Model
Represents 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 com.intellij.openapi.util.Pair<java.util.Properties,java.util.Properties>
getAllProperties()
Deprecated.usegetModel().getUserDefinedProperties
andgetModel().getSystemProperties()
static boolean
getBoolean(java.lang.String key)
Returns the property value as a boolean, orfalse
if not set.static boolean
getBoolean(java.lang.String key, boolean defaultValue)
Returns the property value as a boolean, or defaultValue if not set.static boolean
getBooleanOrTrue(java.lang.String key)
Returns the property value as a boolean, ortrue
if not set.static float
getFloat(java.lang.String key)
Returns the property value as a float, or0.0f
if not set.static float
getFloat(java.lang.String key, float defaultValue)
Returns the property value as a float.static int
getInteger(java.lang.String key)
Returns the property value as an integer, or0
if not set.static int
getInteger(java.lang.String key, int defaultValue)
Returns the property value as an integer.static long
getIntervalMilliseconds(java.lang.String key, long defaultMillis)
Returns the property value representing a time interval in milliseconds.static long
getLong(java.lang.String key)
Returns the property value as a long, or0
if not set.static long
getLong(java.lang.String key, long defaultValue)
Returns the property value as a long.static TeamCityProperties.Model
getModel()
static java.util.Map<java.lang.String,java.lang.String>
getPropertiesWithPrefix(java.lang.String keyPrefix)
static java.lang.String
getProperty(java.lang.String key)
Returns the property value as a string, or empty string if not set.static java.lang.String
getProperty(java.lang.String key, java.lang.String defaultValue)
Returns the property value as a string.static java.lang.String
getPropertyOrNull(java.lang.String key)
Returns the property value as a string, ornull
if not set.static java.lang.String
getPropertyOrNull(java.lang.String key, java.lang.String defaultValue)
Returns the property value as a string, ornull
if not set.static boolean
isInitialized()
protected static void
setBaseModel()
Updates current TeamCity properties model to the default.protected static void
setModel(TeamCityProperties.Model model)
Updates current TeamCity properties model.
-
-
-
Method Detail
-
getBoolean
public static boolean getBoolean(@NotNull java.lang.String key)
Returns the property value as a boolean, orfalse
if not set.- Parameters:
key
- the property key- Returns:
- property value as a boolean
-
getBooleanOrTrue
public static boolean getBooleanOrTrue(@NotNull java.lang.String key)
Returns the property value as a boolean, ortrue
if not set.- Parameters:
key
- the property key- Returns:
- property value as a boolean
-
getBoolean
public static boolean getBoolean(@NotNull java.lang.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 java.lang.String key)
Returns the property value as an integer, or0
if not set.- Parameters:
key
- the property key- Returns:
- property value as an integer
-
getIntervalMilliseconds
public static long getIntervalMilliseconds(@NotNull java.lang.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 java.lang.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 java.lang.String key)
Returns the property value as a float, or0.0f
if not set.- Parameters:
key
- the property key- Returns:
- property value as a float
-
getFloat
public static float getFloat(@NotNull java.lang.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 java.lang.String key)
Returns the property value as a long, or0
if not set.- Parameters:
key
- the property key- Returns:
- property value as a long
-
getLong
public static long getLong(@NotNull java.lang.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 java.lang.String getProperty(@NotNull java.lang.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 java.lang.String getPropertyOrNull(@NotNull java.lang.String key)
Returns the property value as a string, ornull
if not set.- Parameters:
key
- the property key- Returns:
- property value as a string
-
getPropertyOrNull
@Nullable public static java.lang.String getPropertyOrNull(@NotNull java.lang.String key, @Nullable java.lang.String defaultValue)
Returns the property value as a string, ornull
if not set.- Parameters:
key
- the property keydefaultValue
- default value- Returns:
- property value as a string
- Since:
- 7.1.1
-
getProperty
@NotNull public static java.lang.String getProperty(@NotNull java.lang.String key, @NotNull java.lang.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 java.util.Map<java.lang.String,java.lang.String> getPropertiesWithPrefix(@NotNull java.lang.String keyPrefix)
- Parameters:
keyPrefix
- key prefix- Returns:
- all properties with key starting with the specified prefix
- Since:
- 2019.1
-
getAllProperties
@NotNull @Deprecated public static com.intellij.openapi.util.Pair<java.util.Properties,java.util.Properties> getAllProperties()
Deprecated.usegetModel().getUserDefinedProperties
andgetModel().getSystemProperties()
Returns twoProperties
instances 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
-
-