Class YamlConfigurationAdapter
java.lang.Object
com.pragma.archetype.infrastructure.adapter.out.config.YamlConfigurationAdapter
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionYamlConfigurationAdapter(YamlMerger yamlMerger) Constructor with YamlMerger dependency injection for testing. -
Method Summary
Modifier and TypeMethodDescriptionbooleanconfigurationExists(Path projectPath) Checks if a configuration file exists in the project.voiddeleteConfiguration(Path projectPath) Deletes the configuration file from the project.Merges overlay YAML into base YAML, preserving existing values.voidmergeYamlFile(Path filePath, Map<String, Object> overlay) Merges overlay YAML into an existing YAML file, preserving comments and structure.readConfiguration(Path projectPath) Reads the project configuration from the specified directory.readTemplateConfiguration(Path projectPath) Reads template configuration from .cleanarch.ymlReads YAML file and returns it as a map.voidwriteConfiguration(Path projectPath, ProjectConfig config) Writes the project configuration to the specified directory.voidWrites a map to a YAML file with 2-space indentation.
-
Constructor Details
-
YamlConfigurationAdapter
public YamlConfigurationAdapter() -
YamlConfigurationAdapter
Constructor with YamlMerger dependency injection for testing.
-
-
Method Details
-
readConfiguration
Description copied from interface:ConfigurationPortReads the project configuration from the specified directory.- Specified by:
readConfigurationin interfaceConfigurationPort- Parameters:
projectPath- the root directory of the project- Returns:
- Optional containing the configuration if it exists, empty otherwise
-
writeConfiguration
Description copied from interface:ConfigurationPortWrites the project configuration to the specified directory. Creates a .cleanarch.yml file in the project root.- Specified by:
writeConfigurationin interfaceConfigurationPort- Parameters:
projectPath- the root directory of the projectconfig- the configuration to write
-
configurationExists
Description copied from interface:ConfigurationPortChecks if a configuration file exists in the project.- Specified by:
configurationExistsin interfaceConfigurationPort- Parameters:
projectPath- the root directory of the project- Returns:
- true if configuration exists, false otherwise
-
deleteConfiguration
Description copied from interface:ConfigurationPortDeletes the configuration file from the project.- Specified by:
deleteConfigurationin interfaceConfigurationPort- Parameters:
projectPath- the root directory of the project
-
readTemplateConfiguration
Reads template configuration from .cleanarch.yml- Specified by:
readTemplateConfigurationin interfaceConfigurationPort- Parameters:
projectPath- path to project- Returns:
- template configuration or default if not specified
-
readYaml
Reads YAML file and returns it as a map.- Parameters:
filePath- path to YAML file- Returns:
- map representation of YAML content
-
writeYaml
Writes a map to a YAML file with 2-space indentation.- Parameters:
filePath- path to YAML filedata- map to write
-
mergeYaml
Merges overlay YAML into base YAML, preserving existing values. Uses YamlMerger for intelligent merging with conflict detection.- Parameters:
base- existing YAML mapoverlay- new properties to merge- Returns:
- merged YAML map
-
mergeYamlFile
Merges overlay YAML into an existing YAML file, preserving comments and structure. Adds security warnings for sensitive properties.- Parameters:
filePath- path to existing YAML fileoverlay- new properties to merge
-