mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 23:28:55 +00:00
#1338 - Regression since 11.12.1 - resolve expressions in Properties given to serverConfig.loadFromProperties()
This commit is contained in:
@@ -2642,7 +2642,8 @@ public class ServerConfig {
|
||||
* Load settings from ebean.properties.
|
||||
*/
|
||||
public void loadFromProperties() {
|
||||
loadFromProperties(PropertiesLoader.load());
|
||||
this.properties = PropertiesLoader.load();
|
||||
configureFromProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2650,7 +2651,14 @@ public class ServerConfig {
|
||||
*/
|
||||
public void loadFromProperties(Properties properties) {
|
||||
// keep the properties used for configuration so that these are available for plugins
|
||||
this.properties = properties;
|
||||
this.properties = PropertiesLoader.eval(properties);
|
||||
configureFromProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the settings from the given properties
|
||||
*/
|
||||
private void configureFromProperties() {
|
||||
autoConfiguration();
|
||||
PropertiesWrapper p = new PropertiesWrapper("ebean", name, properties);
|
||||
loadSettings(p);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebean.config.properties;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -66,4 +67,19 @@ public class PropertiesLoader {
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of the properties with 'eval' run on all the values.
|
||||
* This resolves expressions like ${HOME} etc.
|
||||
*/
|
||||
public static Properties eval(Properties properties) {
|
||||
Properties evalCopy = new Properties();
|
||||
|
||||
Enumeration<?> names = properties.propertyNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = (String)names.nextElement();
|
||||
String value = PropertyEval.eval(properties.getProperty(name));
|
||||
evalCopy.setProperty(name, value);
|
||||
}
|
||||
return evalCopy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.properties.PropertiesLoader;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
@@ -50,6 +51,9 @@ public class PropertiesWrapperTest {
|
||||
@Test
|
||||
public void testGetProperties() {
|
||||
|
||||
String home = System.getenv("HOME");
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put("someBasic", "hello");
|
||||
properties.put("someInt", "42");
|
||||
@@ -57,16 +61,20 @@ public class PropertiesWrapperTest {
|
||||
properties.put("somePath", "${HOME}/hello");
|
||||
properties.put("someSystemProp", "/aaa/${java.io.tmpdir}/bbb");
|
||||
|
||||
PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", properties);
|
||||
Properties evalCopy = PropertiesLoader.eval(properties);
|
||||
PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", evalCopy);
|
||||
|
||||
assertEquals(42, pw.getInt("someInt", 99));
|
||||
assertEquals(Double.valueOf(5.5D), (Double.valueOf(pw.getDouble("someDouble", 99.9D))));
|
||||
assertEquals(home + "/hello", pw.get("somePath", null));
|
||||
assertEquals(tmpDir, "/aaa/" + tmpDir + "/bbb", pw.get("someSystemProp"));
|
||||
|
||||
|
||||
pw = new PropertiesWrapper(properties);
|
||||
pw = new PropertiesWrapper(evalCopy);
|
||||
|
||||
assertEquals(42, pw.getInt("someInt", 99));
|
||||
assertEquals(Double.valueOf(5.5D), (Double.valueOf(pw.getDouble("someDouble", 99.9D))));
|
||||
assertEquals(home + "/hello", pw.get("somePath", null));
|
||||
assertEquals(tmpDir, "/aaa/" + tmpDir + "/bbb", pw.get("someSystemProp"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -24,6 +25,21 @@ public class ServerConfigTest {
|
||||
assertNotNull(serverConfig.getProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evalPropertiesInput() {
|
||||
|
||||
String home = System.getenv("HOME");
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty("ddl.initSql", "${HOME}/initSql");
|
||||
|
||||
ServerConfig serverConfig = new ServerConfig();
|
||||
serverConfig.loadFromProperties(props);
|
||||
|
||||
String ddlInitSql = serverConfig.getDdlInitSql();
|
||||
assertThat(ddlInitSql).isEqualTo(home+"/initSql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadWithProperties() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user