mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-19 03:01:27 +00:00
make process function reliable testable and adjust unit test
This commit is contained in:
@@ -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<String, String> env = System.getenv();
|
||||
private final Map<String, String> env;
|
||||
private final Properties delegate;
|
||||
|
||||
public LazyProcessedProperties(Properties props) {
|
||||
public LazyProcessedProperties(Properties props, Map<String, String> 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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user