jetbrains.buildServer.serverSide
Class TeamCityProperties

java.lang.Object
  extended by 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 in System.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 =).

Author:
Maxim Podkolzine (maxim.podkolzine@jetbrains.com)

Nested Class Summary
static interface TeamCityProperties.Model
          Represents properties access model.
 
Constructor Summary
TeamCityProperties()
           
 
Method Summary
static com.intellij.openapi.util.Pair<java.util.Properties,java.util.Properties> getAllProperties()
          Returns two Properties instances containing system properties: the first one contains properties from the internal file, the second one contains all Java process properties (System.getProperties()).
static boolean getBoolean(java.lang.String key)
          Returns the property value as a boolean, or false if not set.
static boolean getBooleanOrTrue(java.lang.String key)
          Returns the property value as a boolean, or true if not set.
static float getFloat(java.lang.String key)
          Returns the property value as a float, or 0.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, or 0 if not set.
static int getInteger(java.lang.String key, int defaultValue)
          Returns the property value as an integer.
static long getLong(java.lang.String key)
          Returns the property value as a long, or 0 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.lang.String getProperty(java.lang.String key)
          Returns the property value as a string, or '' 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, or null if not set.
static java.lang.String getPropertyOrNull(java.lang.String key, java.lang.String defaultValue)
          Returns the property value as a string, or null if not set.
protected static void setModel(TeamCityProperties.Model model)
          updates current TeamCity properties model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TeamCityProperties

public TeamCityProperties()
Method Detail

getBoolean

public static boolean getBoolean(@NotNull
                                 java.lang.String key)
Returns the property value as a boolean, or false 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, or true if not set.

Parameters:
key - the property key
Returns:
property value as a boolean

getInteger

public static int getInteger(@NotNull
                             java.lang.String key)
Returns the property value as an integer, or 0 if not set.

Parameters:
key - the property key
Returns:
property value as an integer

getInteger

public static int getInteger(@NotNull
                             java.lang.String key,
                             int defaultValue)
Returns the property value as an integer.

Parameters:
key - the property key
defaultValue - 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, or 0.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 key
defaultValue - 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, or 0 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 key
defaultValue - 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 '' 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, or null 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, or null if not set.

Parameters:
key - the property key
defaultValue - 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 key
defaultValue - default value
Returns:
property value as a string

getAllProperties

@NotNull
public static com.intellij.openapi.util.Pair<java.util.Properties,java.util.Properties> getAllProperties()
Returns two Properties 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

setModel

protected static void setModel(@NotNull
                               TeamCityProperties.Model model)
updates current TeamCity properties model. This method is not intended to be used explicitly in the code

Parameters:
model - new model
Since:
8.0