Class AppYamlUtils

java.lang.Object
com.sap.cds.maven.plugin.util.AppYamlUtils

public class AppYamlUtils extends Object
  • Method Details

    • findBoundaries

      public static int[] findBoundaries(String appYaml, int startIndex)
      Finds the boundaries of a document (spring profile) within an application.yaml.
      Parameters:
      appYaml - the whole application.yaml content
      startIndex - the start position for the search, has to be inside the document for which the boundaries are identified
      Returns:
      an array with begin and end position of the document
    • findProfile

      public static Optional<org.apache.commons.lang3.tuple.Pair<String,int[]>> findProfile(String appYaml, String profile)
      Returns the content and the position of a profile in an application.yaml.
      Parameters:
      appYaml - the whole application.yaml content
      profile - the profile name
      Returns:
      an Optional containing the profile content and position within in the application.yaml
    • mergeProfiles

      public static String mergeProfiles(String existingProfile, String newProfile, List<String> toBeRemoved)
      Merges an existing profile with a new profile. A merge includes the following steps:
      1. Parse existing and new profile into properties
      2. Remove conflicting properties (provided in the toBeRemoved list) from the existing properties
      3. Set new properties and overwrite existing ones
      4. Dump the properties in yaml format into a string
      Parameters:
      existingProfile - the existing profile
      newProfile - the new profile content
      toBeRemoved - a list with properties to be removed
      Returns:
      the enhanced profile content
    • replaceProfile

      public static String replaceProfile(String yamlContent, int[] boundaries, String newProfile)
    • writeDeep

      public static void writeDeep(Map<String,Object> tree, String[] pathSegments, Object value)
    • parseYamlProperties

      public static Properties parseYamlProperties(String profile)
      Parses the given profile into flattened properties.
      Parameters:
      profile - content of a single profile
      Returns:
      the flattened properties of the profile