Skip to content

Commit

Permalink
fix: Update configuration delimiter logic and generator comment
Browse files Browse the repository at this point in the history
Add distinct delimiters for YAML and properties configurations to handle serialization appropriately. Also update the generated comment to reflect the new project name from "gutil" to "coma".
  • Loading branch information
Metaphoriker committed Nov 21, 2024
1 parent c1696ed commit 7a6b893
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/main/java/de/metaphoriker/coma/BaseConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public abstract class BaseConfiguration {

private static final String COMMENT_PREFIX = "#";
private static final String YAML_EXTENSION = ".yml";
private static final String YAML_DELIMITER = ":";
private static final String PROPERTIES_EXTENSION = ".properties";
private static final String PROPERTIES_DELIMITER = "=";

private static final Gson GSON = new Gson();

Expand Down Expand Up @@ -300,7 +302,7 @@ private void writeConfigHeader(PrintWriter writer) {
*/
private void writeDefaultHeader(PrintWriter writer) {
writeComment(writer, "Configuration File");
writeComment(writer, "Generated by gutil");
writeComment(writer, "Generated by coma");
}

/**
Expand All @@ -312,7 +314,26 @@ private void writeDefaultHeader(PrintWriter writer) {
private void writeValue(PrintWriter writer, String key, ConfigurationOption<?> option) {
Object value = option.getValue();
String serializedValue = GSON.toJson(value);
writer.printf("%s: %s%n", key, serializedValue);
String delimiter = getDelimiter();
writer.printf("%s" + delimiter + " %s%n", key, serializedValue);
}

/**
* Determines the appropriate delimiter based on the type of configuration.
*
* @return The delimiter string corresponding to the configuration type.
* @throws IllegalArgumentException if the configuration type is not supported.
*/
private String getDelimiter() {
Configuration configuration = retrieveConfigurationAnnotation();
switch (configuration.type()) {
case YAML:
return YAML_DELIMITER;
case PROPERTIES:
return PROPERTIES_DELIMITER;
default:
throw new IllegalArgumentException("Configuration type not supported");
}
}

/**
Expand Down

0 comments on commit 7a6b893

Please sign in to comment.