Optimierung: PropertiesConfigurationPortAdapter intern entflochten
This commit is contained in:
@@ -78,26 +78,34 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
|
||||
|
||||
@Override
|
||||
public StartConfiguration loadConfiguration() {
|
||||
Properties props = loadPropertiesFile();
|
||||
String apiKey = getApiKey(props);
|
||||
return buildStartConfiguration(props, apiKey);
|
||||
}
|
||||
|
||||
private Properties loadPropertiesFile() {
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
// Check if file exists first to preserve FileNotFoundException behavior for tests
|
||||
if (!Files.exists(configFilePath)) {
|
||||
throw new java.io.FileNotFoundException("Config file not found: " + configFilePath);
|
||||
}
|
||||
// Read file content as string to avoid escape sequence interpretation issues
|
||||
String content = Files.readString(configFilePath, StandardCharsets.UTF_8);
|
||||
// Escape backslashes to prevent Java Properties from interpreting them as escape sequences
|
||||
// This is needed because Windows paths use backslashes (e.g., C:\temp\...)
|
||||
// and Java Properties interprets \t as tab, \n as newline, etc.
|
||||
String escapedContent = content.replace("\\", "\\\\");
|
||||
String escapedContent = escapeBackslashes(content);
|
||||
props.load(new StringReader(escapedContent));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load configuration from " + configFilePath, e);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
// Apply environment variable precedence for api.key
|
||||
String apiKey = getApiKey(props);
|
||||
private String escapeBackslashes(String content) {
|
||||
// Escape backslashes to prevent Java Properties from interpreting them as escape sequences.
|
||||
// This is needed because Windows paths use backslashes (e.g., C:\temp\...)
|
||||
// and Java Properties interprets \t as tab, \n as newline, etc.
|
||||
return content.replace("\\", "\\\\");
|
||||
}
|
||||
|
||||
private StartConfiguration buildStartConfiguration(Properties props, String apiKey) {
|
||||
return new StartConfiguration(
|
||||
Paths.get(getRequiredProperty(props, "source.folder")),
|
||||
Paths.get(getRequiredProperty(props, "target.folder")),
|
||||
|
||||
Reference in New Issue
Block a user