Class YamlConfigurationAdapter

java.lang.Object
com.pragma.archetype.infrastructure.adapter.out.config.YamlConfigurationAdapter
All Implemented Interfaces:
ConfigurationPort

public class YamlConfigurationAdapter extends Object implements ConfigurationPort
Adapter for reading and writing project configuration in YAML format. Uses SnakeYAML library. Supports intelligent YAML merging with comment preservation and security warnings.
  • Constructor Details

    • YamlConfigurationAdapter

      public YamlConfigurationAdapter()
    • YamlConfigurationAdapter

      public YamlConfigurationAdapter(YamlMerger yamlMerger)
      Constructor with YamlMerger dependency injection for testing.
  • Method Details

    • readConfiguration

      public Optional<ProjectConfig> readConfiguration(Path projectPath)
      Description copied from interface: ConfigurationPort
      Reads the project configuration from the specified directory.
      Specified by:
      readConfiguration in interface ConfigurationPort
      Parameters:
      projectPath - the root directory of the project
      Returns:
      Optional containing the configuration if it exists, empty otherwise
    • writeConfiguration

      public void writeConfiguration(Path projectPath, ProjectConfig config)
      Description copied from interface: ConfigurationPort
      Writes the project configuration to the specified directory. Creates a .cleanarch.yml file in the project root.
      Specified by:
      writeConfiguration in interface ConfigurationPort
      Parameters:
      projectPath - the root directory of the project
      config - the configuration to write
    • configurationExists

      public boolean configurationExists(Path projectPath)
      Description copied from interface: ConfigurationPort
      Checks if a configuration file exists in the project.
      Specified by:
      configurationExists in interface ConfigurationPort
      Parameters:
      projectPath - the root directory of the project
      Returns:
      true if configuration exists, false otherwise
    • deleteConfiguration

      public void deleteConfiguration(Path projectPath)
      Description copied from interface: ConfigurationPort
      Deletes the configuration file from the project.
      Specified by:
      deleteConfiguration in interface ConfigurationPort
      Parameters:
      projectPath - the root directory of the project
    • readTemplateConfiguration

      public TemplateConfig readTemplateConfiguration(Path projectPath)
      Reads template configuration from .cleanarch.yml
      Specified by:
      readTemplateConfiguration in interface ConfigurationPort
      Parameters:
      projectPath - path to project
      Returns:
      template configuration or default if not specified
    • readYaml

      public Map<String,Object> readYaml(Path filePath)
      Reads YAML file and returns it as a map.
      Parameters:
      filePath - path to YAML file
      Returns:
      map representation of YAML content
    • writeYaml

      public void writeYaml(Path filePath, Map<String,Object> data)
      Writes a map to a YAML file with 2-space indentation.
      Parameters:
      filePath - path to YAML file
      data - map to write
    • mergeYaml

      public Map<String,Object> mergeYaml(Map<String,Object> base, Map<String,Object> overlay)
      Merges overlay YAML into base YAML, preserving existing values. Uses YamlMerger for intelligent merging with conflict detection.
      Parameters:
      base - existing YAML map
      overlay - new properties to merge
      Returns:
      merged YAML map
    • mergeYamlFile

      public void mergeYamlFile(Path filePath, Map<String,Object> overlay)
      Merges overlay YAML into an existing YAML file, preserving comments and structure. Adds security warnings for sensitive properties.
      Parameters:
      filePath - path to existing YAML file
      overlay - new properties to merge