Apply code suggestion from review

Co-authored-by: Sebastian Stenzel <overheadhunter@users.noreply.github.com>
This commit is contained in:
Armin Schrenk
2023-06-16 13:09:41 +02:00
parent c46eeb0401
commit 4065e15aa1

View File

@@ -9,7 +9,7 @@ import java.util.regex.Pattern;
public class PropertiesPreprocessor {
private static final Logger LOG = LoggerFactory.getLogger(PropertiesPreprocessor.class);
private static final Pattern TEMPLATE = Pattern.compile("@\\((.+)\\)");
private static final Pattern TEMPLATE = Pattern.compile("@\\{(\\w+)}");
private static final LoggingEnvironment ENV = new LoggingEnvironment(System.getenv(), LOG);
public static void run() {
@@ -29,12 +29,12 @@ public class PropertiesPreprocessor {
private static String process(String value) {
return TEMPLATE.matcher(value).replaceAll(match -> //
switch (match.group().substring(2, match.group().length() - 1)) {
switch (match.group(1)) {
case "appdir" -> ENV.get("APPDIR");
case "appdata" -> ENV.get("APPDATA");
case "userhome" -> System.getProperty("user.home");
default -> {
LOG.warn("Found unknown keyword {} in property value {}. Keyword is not replaced.", match.group(), value);
LOG.warn("Found unknown variable @{{}} in property value {}.", match.group(), value);
yield match.group();
}
});