diff --git a/src/main/java/org/cryptomator/common/LazyProcessedProperties.java b/src/main/java/org/cryptomator/common/LazyProcessedProperties.java index 97248035a..c4be47f11 100644 --- a/src/main/java/org/cryptomator/common/LazyProcessedProperties.java +++ b/src/main/java/org/cryptomator/common/LazyProcessedProperties.java @@ -29,11 +29,12 @@ public class LazyProcessedProperties extends Properties { //Template and env _need_ to be instance variables, otherwise they might not be initialized at access time private final Pattern template = Pattern.compile("@\\{(\\w+)}"); - private final Map env = System.getenv(); + private final Map env; private final Properties delegate; - public LazyProcessedProperties(Properties props) { + public LazyProcessedProperties(Properties props, Map systemEnvironment) { this.delegate = props; + this.env = systemEnvironment; } @Override @@ -56,6 +57,7 @@ public class LazyProcessedProperties extends Properties { } } + //visible for testing String process(String value) { return template.matcher(value).replaceAll(match -> // switch (match.group(1)) { diff --git a/src/main/java/org/cryptomator/launcher/Cryptomator.java b/src/main/java/org/cryptomator/launcher/Cryptomator.java index 0985ee33e..d6bafa489 100644 --- a/src/main/java/org/cryptomator/launcher/Cryptomator.java +++ b/src/main/java/org/cryptomator/launcher/Cryptomator.java @@ -30,16 +30,16 @@ import java.util.concurrent.Executors; public class Cryptomator { private static final long STARTUP_TIME = System.currentTimeMillis(); - // DaggerCryptomatorComponent gets generated by Dagger. - // Run Maven and include target/generated-sources/annotations in your IDE. static { - var lazyProcessedProps = new LazyProcessedProperties(System.getProperties()); + var lazyProcessedProps = new LazyProcessedProperties(System.getProperties(), System.getenv()); System.setProperties(lazyProcessedProps); CRYPTOMATOR_COMPONENT = DaggerCryptomatorComponent.factory().create(STARTUP_TIME); LOG = LoggerFactory.getLogger(Cryptomator.class); } + // DaggerCryptomatorComponent gets generated by Dagger. + // Run Maven and include target/generated-sources/annotations in your IDE. private static final CryptomatorComponent CRYPTOMATOR_COMPONENT; private static final Logger LOG; diff --git a/src/main/java/org/cryptomator/logging/LogbackConfigurator.java b/src/main/java/org/cryptomator/logging/LogbackConfigurator.java index 41275d073..c352f52f5 100644 --- a/src/main/java/org/cryptomator/logging/LogbackConfigurator.java +++ b/src/main/java/org/cryptomator/logging/LogbackConfigurator.java @@ -59,7 +59,7 @@ public class LogbackConfigurator extends ContextAwareBase implements Configurato @Override public ExecutionStatus configure(LoggerContext context) { //we need to preprocess those, because every other class has a dependency to logging, none are initialized yet - var processedProps = new LazyProcessedProperties(System.getProperties()); + var processedProps = new LazyProcessedProperties(System.getProperties(), System.getenv()); var useCustomCfg = Optional.ofNullable(processedProps.getProperty("logback.configurationFile")).map(s -> Files.exists(Path.of(s))).orElse(false); var logDir = Optional.ofNullable(processedProps.getProperty("cryptomator.logDir")).map(Path::of).orElse(null); diff --git a/src/test/java/org/cryptomator/common/LazyProcessedPropertiesTest.java b/src/test/java/org/cryptomator/common/LazyProcessedPropertiesTest.java index 7b7e2948f..2f5be36fa 100644 --- a/src/test/java/org/cryptomator/common/LazyProcessedPropertiesTest.java +++ b/src/test/java/org/cryptomator/common/LazyProcessedPropertiesTest.java @@ -1,22 +1,21 @@ package org.cryptomator.common; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; +import java.util.Map; + public class LazyProcessedPropertiesTest { @ParameterizedTest - @CsvSource(value = """ - org.example.@{mytest1}.test, org.example.@{mytest1}.test - @{only*word*digits*under_score\\},@{only*words*digits*under_score\\} - C:\\Users\\@{appdir}\\dir, C:\\Users\\\\dir - @{@{appdir}},@{} - Longer @{appdir} text with @{appdir}., Longer text with . - """) + @CsvSource(value = {"org.example.@{mytest1}.test, org.example.@{mytest1}.test", // + "@{only*words*digits*under_score\\},@{only*words*digits*under_score\\}", // + "C:\\Users\\@{appdir}\\dir, C:\\Users\\foobar\\dir", // + "@{@{appdir}},@{foobar}", // + "Longer @{appdir} text with @{appdir}., Longer foobar text with foobar."}) public void test(String propertyValue, String expected) { - LazyProcessedProperties inTest = new LazyProcessedProperties(System.getProperties()); + LazyProcessedProperties inTest = new LazyProcessedProperties(System.getProperties(), Map.of("APPDIR", "foobar")); var result = inTest.process(propertyValue); Assertions.assertEquals(result, expected); }