mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-18 16:46:53 -04:00
renamed class
This commit is contained in:
@@ -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<String, String> env;
|
||||
|
||||
public LazyProcessedProperties(Properties props, Map<String, String> systemEnvironment) {
|
||||
public SubstitutingProperties(Properties props, Map<String, String> 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("\\", "\\\\");
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
Reference in New Issue
Block a user