diff --git a/src/main/java/org/cryptomator/common/LazyProcessedProperties.java b/src/main/java/org/cryptomator/common/SubstitutingProperties.java similarity index 77% rename from src/main/java/org/cryptomator/common/LazyProcessedProperties.java rename to src/main/java/org/cryptomator/common/SubstitutingProperties.java index 3e2e60f94..bf98c25f4 100644 --- a/src/main/java/org/cryptomator/common/LazyProcessedProperties.java +++ b/src/main/java/org/cryptomator/common/SubstitutingProperties.java @@ -6,13 +6,13 @@ import java.util.Map; import java.util.Properties; import java.util.regex.Pattern; -public class LazyProcessedProperties extends PropertiesDecorator { +public class SubstitutingProperties extends PropertiesDecorator { private static final Pattern TEMPLATE = Pattern.compile("@\\{(\\w+)}"); private final Map env; - public LazyProcessedProperties(Properties props, Map systemEnvironment) { + public SubstitutingProperties(Properties props, Map systemEnvironment) { super(props); this.env = systemEnvironment; } @@ -46,7 +46,7 @@ public class LazyProcessedProperties extends PropertiesDecorator { case "localappdata" -> resolveFrom("LOCALAPPDATA", Source.ENV); case "userhome" -> resolveFrom("user.home", Source.PROPS); default -> { - LoggerFactory.getLogger(LazyProcessedProperties.class).warn("Unknown variable {} in property value {}.", match.group(), value); + LoggerFactory.getLogger(SubstitutingProperties.class).warn("Unknown variable {} in property value {}.", match.group(), value); yield match.group(); } }); @@ -58,7 +58,7 @@ public class LazyProcessedProperties extends PropertiesDecorator { case PROPS -> delegate.getProperty(key); }; if (val == null) { - LoggerFactory.getLogger(LazyProcessedProperties.class).warn("Variable {} used for substitution not found in {}. Replaced with empty string.", key, src); + LoggerFactory.getLogger(SubstitutingProperties.class).warn("Variable {} used for substitution not found in {}. Replaced with empty string.", key, src); return ""; } else { return val.replace("\\", "\\\\"); diff --git a/src/main/java/org/cryptomator/launcher/Cryptomator.java b/src/main/java/org/cryptomator/launcher/Cryptomator.java index f395abf52..a8d38c312 100644 --- a/src/main/java/org/cryptomator/launcher/Cryptomator.java +++ b/src/main/java/org/cryptomator/launcher/Cryptomator.java @@ -9,7 +9,7 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import dagger.Lazy; import org.apache.commons.lang3.SystemUtils; import org.cryptomator.common.Environment; -import org.cryptomator.common.LazyProcessedProperties; +import org.cryptomator.common.SubstitutingProperties; import org.cryptomator.common.ShutdownHook; import org.cryptomator.ipc.IpcCommunicator; import org.cryptomator.logging.DebugMode; @@ -32,7 +32,7 @@ public class Cryptomator { private static final long STARTUP_TIME = System.currentTimeMillis(); static { - var lazyProcessedProps = new LazyProcessedProperties(System.getProperties(), System.getenv()); + var lazyProcessedProps = new SubstitutingProperties(System.getProperties(), System.getenv()); System.setProperties(lazyProcessedProps); CRYPTOMATOR_COMPONENT = DaggerCryptomatorComponent.factory().create(STARTUP_TIME); LOG = LoggerFactory.getLogger(Cryptomator.class); diff --git a/src/test/java/org/cryptomator/common/LazyProcessedPropertiesTest.java b/src/test/java/org/cryptomator/common/SubstitutingPropertiesTest.java similarity index 84% rename from src/test/java/org/cryptomator/common/LazyProcessedPropertiesTest.java rename to src/test/java/org/cryptomator/common/SubstitutingPropertiesTest.java index b55e3bda4..964ae7188 100644 --- a/src/test/java/org/cryptomator/common/LazyProcessedPropertiesTest.java +++ b/src/test/java/org/cryptomator/common/SubstitutingPropertiesTest.java @@ -12,9 +12,9 @@ import org.mockito.Mockito; import java.util.Map; import java.util.Properties; -public class LazyProcessedPropertiesTest { +public class SubstitutingPropertiesTest { - LazyProcessedProperties inTest; + SubstitutingProperties inTest; @Nested public class Processing { @@ -27,7 +27,7 @@ public class LazyProcessedPropertiesTest { "@{@{appdir}},@{foobar}", // "Longer @{appdir} text with @{appdir}., Longer foobar text with foobar."}) public void test(String propertyValue, String expected) { - LazyProcessedProperties inTest = new LazyProcessedProperties(new Properties(), Map.of("APPDIR", "foobar")); + SubstitutingProperties inTest = new SubstitutingProperties(new Properties(), Map.of("APPDIR", "foobar")); var result = inTest.process(propertyValue); Assertions.assertEquals(result, expected); } @@ -38,7 +38,7 @@ public class LazyProcessedPropertiesTest { var props = new Properties(); props.setProperty("user.home", "OneUponABit"); - inTest = new LazyProcessedProperties(props, Map.of()); + inTest = new SubstitutingProperties(props, Map.of()); var result = inTest.process("@{userhome}"); Assertions.assertEquals(result, "OneUponABit"); } @@ -47,7 +47,7 @@ public class LazyProcessedPropertiesTest { @ParameterizedTest(name = "Token \"{0}\" replaced with content of {1}") @CsvSource(value = {"appdir, APPDIR, foobar", "appdata, APPDATA, bazbaz", "localappdata, LOCALAPPDATA, boboAlice"}) public void testEnvSubstitutions(String token, String envName, String expected) { - inTest = new LazyProcessedProperties(new Properties(), Map.of(envName, expected)); + inTest = new SubstitutingProperties(new Properties(), Map.of(envName, expected)); var result = inTest.process("@{" + token + "}"); Assertions.assertEquals(result, expected); } @@ -61,7 +61,7 @@ public class LazyProcessedPropertiesTest { @Test @DisplayName("Undefined properties are not processed") public void testNoProcessingOnNull() { - inTest = Mockito.spy(new LazyProcessedProperties(new Properties(), Map.of())); + inTest = Mockito.spy(new SubstitutingProperties(new Properties(), Map.of())); var result = inTest.getProperty("some.prop"); Assertions.assertNull(result); @@ -74,7 +74,7 @@ public class LazyProcessedPropertiesTest { public void testNoProcessingOnNotCryptomator(String propKey) { var props = new Properties(); props.setProperty(propKey, "someValue"); - inTest = Mockito.spy(new LazyProcessedProperties(props, Map.of())); + inTest = Mockito.spy(new SubstitutingProperties(props, Map.of())); var result = inTest.getProperty("some.prop"); Assertions.assertNull(result); @@ -86,7 +86,7 @@ public class LazyProcessedPropertiesTest { public void testProcessing() { var props = new Properties(); props.setProperty("cryptomator.prop", "someValue"); - inTest = Mockito.spy(new LazyProcessedProperties(props, Map.of())); + inTest = Mockito.spy(new SubstitutingProperties(props, Map.of())); Mockito.doReturn("someValue").when(inTest).process(Mockito.anyString()); inTest.getProperty("cryptomator.prop");