Class 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 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 =).

    • Constructor Detail

      • TeamCityProperties

        public TeamCityProperties()
    • Method Detail

      • getBoolean

        public static boolean getBoolean​(@NotNull
                                         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
                                               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
      • 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 key
        defaultValue - 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, or 0 if 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 key
        defaultValue - default value
        Returns:
        property value as an integer
      • getFloat

        public static float getFloat​(@NotNull
                                     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
                                     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
                                   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
                                   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 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, or null if 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, 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 String getProperty​(@NotNull
                                         String key,
                                         @NotNull
                                         String defaultValue)
        Returns the property value as a string.
        Parameters:
        key - the property key
        defaultValue - 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.
        use getModel().getUserDefinedProperties and getModel().getSystemProperties()
        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
      • 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