[VIVO-1488] Look in vitro.home/config directory for runtime.properties at startup (#63)

* Look in vitro.home/config directory for runtime.properties at startup

* Show deprecation warning on startup if runtime.properties in vivo.home

* Reuse string variable, use .equals()
This commit is contained in:
Ben 2018-05-07 08:21:03 -06:00 committed by Jim Blake
parent b406f99fec
commit c9ce576f6b
2 changed files with 73 additions and 13 deletions

View file

@ -52,6 +52,9 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
/** Configuration property to store the Vitro home directory */
private static final String VHD_CONFIGURATION_PROPERTY = "vitro.home";
/** Configuration property used to determine if there are runtime.properties files in multiple locations **/
static final String RP_MULTIPLE = "rp.multiple";
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
@ -63,12 +66,18 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
File vitroHomeDir = ApplicationUtils.instance()
.getHomeDirectory().getPath().toFile();
File vitroHomeDirConfig = new File(vitroHomeDir.getPath()
.concat(File.separator).concat("config"));
String rpfLocation = findMultipleRuntimePropertiesFiles(
vitroHomeDir, vitroHomeDirConfig);
File runtimePropertiesFile = locateRuntimePropertiesFile(
vitroHomeDir, ss);
vitroHomeDir, vitroHomeDirConfig, ss);
stream = new FileInputStream(runtimePropertiesFile);
Map<String, String> preempts = createPreemptiveProperties(
VHD_CONFIGURATION_PROPERTY, vitroHomeDir);
VHD_CONFIGURATION_PROPERTY, vitroHomeDir, RP_MULTIPLE, rpfLocation);
ConfigurationPropertiesImpl bean = new ConfigurationPropertiesImpl(
stream, preempts, new BuildProperties(ctx).getMap());
@ -90,14 +99,36 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
}
}
private File locateRuntimePropertiesFile(File vitroHomeDir, StartupStatus ss) {
File rpf = new File(vitroHomeDir, FILE_RUNTIME_PROPERTIES);
private String findMultipleRuntimePropertiesFiles(File vitroHomeDir,
File vitroHomeDirConfig) {
if (!rpf.exists()) {
File rpf = new File(vitroHomeDir, FILE_RUNTIME_PROPERTIES);
File rpfc = new File(vitroHomeDirConfig, FILE_RUNTIME_PROPERTIES);
if (rpf.exists() && !rpfc.exists()) {
return "home";
} else if (rpf.exists() && rpfc.exists()) {
return "both";
} else if (rpfc.exists()) {
return "config";
} else {
throw new IllegalStateException("Did not find '"
+ FILE_RUNTIME_PROPERTIES + "' in vitro home directory '"
+ vitroHomeDir + "'");
+ vitroHomeDir + "' or config directory '" + vitroHomeDirConfig + "'");
}
}
private File locateRuntimePropertiesFile(File vitroHomeDir,
File vitroHomeDirConfig, StartupStatus ss) {
File rpf = new File(vitroHomeDir, FILE_RUNTIME_PROPERTIES);
File rpfc = new File(vitroHomeDirConfig, FILE_RUNTIME_PROPERTIES);
if (!rpf.exists()) {
rpf = rpfc;
}
if (!rpf.isFile()) {
throw new IllegalStateException("'" + rpf.getPath()
+ "' is not a file.");
@ -111,9 +142,11 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
}
private Map<String, String> createPreemptiveProperties(
String propertyVitroHome, File vitroHomeDir) {
String propertyVitroHome, File vitroHomeDir, String propertyRpfMultiple,
String rpfLocation) {
Map<String, String> map = new HashMap<String, String>();
map.put(propertyVitroHome, vitroHomeDir.getAbsolutePath());
map.put(propertyRpfMultiple, rpfLocation);
return map;
}

View file

@ -37,6 +37,7 @@ public class ConfigurationPropertiesSmokeTests implements
StartupStatus ss = StartupStatus.getBean(ctx);
checkDefaultNamespace(ctx, props, ss);
checkMultipleRPFs(ctx, props, ss);
checkLanguages(props, ss);
}
@ -72,6 +73,32 @@ public class ConfigurationPropertiesSmokeTests implements
}
}
/**
* Warn if runtime.properties exists in multiple locations
* or is located vivo.home instead of vivo.home/config
*/
private void checkMultipleRPFs(ServletContext ctx,
ConfigurationProperties props, StartupStatus ss) {
String rpfStatus = props.getProperty(ConfigurationPropertiesSetup.RP_MULTIPLE);
if (rpfStatus.equals("both")) {
ss.warning(this,
"Deprecation warning: Files matching the name 'runtime.properties' "
+ "were found in both vivo.home and vivo.home/config. Using "
+ "the file in vivo.home. Future releases may require "
+ "runtime.properties be placed in vivo.home/config.");
}
if (rpfStatus.equals("home")) {
ss.warning(this,
"Deprecation warning: runtime.properties was found in the "
+ "vivo.home directory. The recommended directory for "
+ "runtime.properties is now vivo.home/config. Future releases "
+ "may require runtime.properties be placed in "
+ "vivo.home/config.");
}
}
/**
* Warn if we set up the languages incorrectly:
*