Class BambooYamlParserUtils


  • public class BambooYamlParserUtils
    extends Object
    Utilities for parsing the Bamboo YAML definition.
    See Also:
    BambooYamlParser, BambooYamlDefinition
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @NotNull Node asNode​(@Nullable Object obj, @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext)
      Transforms object generated by snakeyaml into a Node structure.
      static <T> @NotNull List<T> checkListNotEmpty​(@NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext, @Nullable List<T> list)
      Checks that a list is not empty.
      static <T extends Node>
      @NotNull List<T>
      checkListType​(@NotNull List<? extends Node> list, @NotNull Class<T> expectedType)
      Check that all elements of the given list are of expected type.
      static @NotNull Map<String,​Object> checkMapType​(@NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext, @NotNull Map<?,​?> value)
      Checks that a mapping is of type String to Object.
      static <K,​V>
      @NotNull Map<K,​V>
      checkMapType​(@NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext, @NotNull Map<?,​?> value, @NotNull Class<K> expectedKeyType, @NotNull Class<V> expectedValueType)
      Checks that all keys and values of a map are of expected types.
      static <T> T checkPresent​(@NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext, @NotNull Optional<T> value)
      Check that the given optional is present.
      static <T> T checkRequired​(@NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext, T value)
      Check that the given value is not null.
      static @NotNull String checkStringNotBlank​(@NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext, @Nullable String value)
      Checks that a string is not blank.
      static <T> T checkType​(@NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext, @Nullable Object value, @NotNull Class<T> expectedType)
      Check that the given value is of expected type.
      static <T extends Node>
      T
      checkType​(@NotNull Node node, @NotNull Class<T> expectedType)
      Check that the given node is of expected type.
    • Field Detail

      • CFG_VERSION

        public static final String CFG_VERSION
        Config constant to define YAML format version in each YAML document.
      • CFG_SERVER_NAME

        public static final String CFG_SERVER_NAME
    • Method Detail

      • asNode

        @NotNull
        public static @NotNull Node asNode​(@Nullable
                                           @Nullable Object obj,
                                           @NotNull
                                           @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext)
        Transforms object generated by snakeyaml into a Node structure.

        This method will cast the property to a string if it's a scalar (non-collection), e.g. Integer or Boolean.

        Parameters:
        obj - snakeyaml result
        validationContext - root validation context
        Returns:
        Node structure
      • checkRequired

        @Contract("_, null -> fail; _, !null -> !null")
        public static <T> T checkRequired​(@NotNull
                                          @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext,
                                          @Nullable
                                          T value)
        Check that the given value is not null.
        Returns:
        the given value
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkPresent

        @NotNull
        public static <T> T checkPresent​(@NotNull
                                         @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext,
                                         @NotNull
                                         @NotNull Optional<T> value)
        Check that the given optional is present.
        Returns:
        the given value
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkType

        @NotNull
        public static <T> T checkType​(@NotNull
                                      @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext,
                                      @Nullable
                                      @Nullable Object value,
                                      @NotNull
                                      @NotNull Class<T> expectedType)
        Check that the given value is of expected type.
        Returns:
        the value cast to the expected type
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkType

        @NotNull
        public static <T extends Node> T checkType​(@NotNull
                                                   @NotNull Node node,
                                                   @NotNull
                                                   @NotNull Class<T> expectedType)
        Check that the given node is of expected type.
        Returns:
        the value cast to the expected type
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkListType

        @NotNull
        public static <T extends Node> @NotNull List<T> checkListType​(@NotNull
                                                                      @NotNull List<? extends Node> list,
                                                                      @NotNull
                                                                      @NotNull Class<T> expectedType)
        Check that all elements of the given list are of expected type.
        Returns:
        a new list with all elements cast to the expected type
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkMapType

        @NotNull
        public static @NotNull Map<String,​Object> checkMapType​(@NotNull
                                                                     @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext,
                                                                     @NotNull
                                                                     @NotNull Map<?,​?> value)
        Checks that a mapping is of type String to Object.
        Returns:
        a new map, with String keys and Object values
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkMapType

        @NotNull
        public static <K,​V> @NotNull Map<K,​V> checkMapType​(@NotNull
                                                                       @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext,
                                                                       @NotNull
                                                                       @NotNull Map<?,​?> value,
                                                                       @NotNull
                                                                       @NotNull Class<K> expectedKeyType,
                                                                       @NotNull
                                                                       @NotNull Class<V> expectedValueType)
        Checks that all keys and values of a map are of expected types.
        Returns:
        a new map, with key and value types set as expected
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkStringNotBlank

        @NotNull
        public static @NotNull String checkStringNotBlank​(@NotNull
                                                          @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext,
                                                          @Nullable
                                                          @Nullable String value)
        Checks that a string is not blank.
        Returns:
        the passed string
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure
      • checkListNotEmpty

        @NotNull
        public static <T> @NotNull List<T> checkListNotEmpty​(@NotNull
                                                             @NotNull com.atlassian.bamboo.specs.api.validators.common.ValidationContext validationContext,
                                                             @Nullable
                                                             @Nullable List<T> list)
        Checks that a list is not empty.
        Returns:
        the passed list
        Throws:
        com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException - on check failure