Optimierung: PropertiesConfigurationPortAdapter intern entflochten
This commit is contained in:
@@ -78,26 +78,34 @@ public class PropertiesConfigurationPortAdapter implements ConfigurationPort {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StartConfiguration loadConfiguration() {
|
public StartConfiguration loadConfiguration() {
|
||||||
|
Properties props = loadPropertiesFile();
|
||||||
|
String apiKey = getApiKey(props);
|
||||||
|
return buildStartConfiguration(props, apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties loadPropertiesFile() {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
try {
|
try {
|
||||||
// Check if file exists first to preserve FileNotFoundException behavior for tests
|
|
||||||
if (!Files.exists(configFilePath)) {
|
if (!Files.exists(configFilePath)) {
|
||||||
throw new java.io.FileNotFoundException("Config file not found: " + 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);
|
String content = Files.readString(configFilePath, StandardCharsets.UTF_8);
|
||||||
// Escape backslashes to prevent Java Properties from interpreting them as escape sequences
|
String escapedContent = escapeBackslashes(content);
|
||||||
// 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("\\", "\\\\");
|
|
||||||
props.load(new StringReader(escapedContent));
|
props.load(new StringReader(escapedContent));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Failed to load configuration from " + configFilePath, e);
|
throw new RuntimeException("Failed to load configuration from " + configFilePath, e);
|
||||||
}
|
}
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
// Apply environment variable precedence for api.key
|
private String escapeBackslashes(String content) {
|
||||||
String apiKey = getApiKey(props);
|
// 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(
|
return new StartConfiguration(
|
||||||
Paths.get(getRequiredProperty(props, "source.folder")),
|
Paths.get(getRequiredProperty(props, "source.folder")),
|
||||||
Paths.get(getRequiredProperty(props, "target.folder")),
|
Paths.get(getRequiredProperty(props, "target.folder")),
|
||||||
|
|||||||
Reference in New Issue
Block a user