[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:
parent
b406f99fec
commit
c9ce576f6b
2 changed files with 73 additions and 13 deletions
|
@ -23,22 +23,22 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
/**
|
/**
|
||||||
* Locates the runtime configuration properties and stores them in the servlet
|
* Locates the runtime configuration properties and stores them in the servlet
|
||||||
* context.
|
* context.
|
||||||
*
|
*
|
||||||
* This must be invoked before any listener that requires configuration
|
* This must be invoked before any listener that requires configuration
|
||||||
* properties.
|
* properties.
|
||||||
*
|
*
|
||||||
* The properties are determined from a file called 'build.properties' in the
|
* The properties are determined from a file called 'build.properties' in the
|
||||||
* resources directory of the webapp, and a file called 'runtime.properties' in
|
* resources directory of the webapp, and a file called 'runtime.properties' in
|
||||||
* the Vitro home directory. In case of conflict, runtime.properties wins.
|
* the Vitro home directory. In case of conflict, runtime.properties wins.
|
||||||
*
|
*
|
||||||
* The path to the Vitro home directory can be specifed by an JNDI value, or by
|
* The path to the Vitro home directory can be specifed by an JNDI value, or by
|
||||||
* a System property, or by a property in build.properties, in that order. If
|
* a System property, or by a property in build.properties, in that order. If
|
||||||
* the Vitro home directory is specified in more than one way, a warning is
|
* the Vitro home directory is specified in more than one way, a warning is
|
||||||
* issued and the first value is used.
|
* issued and the first value is used.
|
||||||
*
|
*
|
||||||
* The value that was determined for 'vitro.home' is also included in the
|
* The value that was determined for 'vitro.home' is also included in the
|
||||||
* ConfigurationProperties bean.
|
* ConfigurationProperties bean.
|
||||||
*
|
*
|
||||||
* If build.properties or runtime.properties cannot be located or loaded, a
|
* If build.properties or runtime.properties cannot be located or loaded, a
|
||||||
* fatal error is registered to abort the startup.
|
* fatal error is registered to abort the startup.
|
||||||
*/
|
*/
|
||||||
|
@ -52,6 +52,9 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
|
||||||
/** Configuration property to store the Vitro home directory */
|
/** Configuration property to store the Vitro home directory */
|
||||||
private static final String VHD_CONFIGURATION_PROPERTY = "vitro.home";
|
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
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
ServletContext ctx = sce.getServletContext();
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
@ -63,12 +66,18 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
|
||||||
File vitroHomeDir = ApplicationUtils.instance()
|
File vitroHomeDir = ApplicationUtils.instance()
|
||||||
.getHomeDirectory().getPath().toFile();
|
.getHomeDirectory().getPath().toFile();
|
||||||
|
|
||||||
|
File vitroHomeDirConfig = new File(vitroHomeDir.getPath()
|
||||||
|
.concat(File.separator).concat("config"));
|
||||||
|
|
||||||
|
String rpfLocation = findMultipleRuntimePropertiesFiles(
|
||||||
|
vitroHomeDir, vitroHomeDirConfig);
|
||||||
|
|
||||||
File runtimePropertiesFile = locateRuntimePropertiesFile(
|
File runtimePropertiesFile = locateRuntimePropertiesFile(
|
||||||
vitroHomeDir, ss);
|
vitroHomeDir, vitroHomeDirConfig, ss);
|
||||||
stream = new FileInputStream(runtimePropertiesFile);
|
stream = new FileInputStream(runtimePropertiesFile);
|
||||||
|
|
||||||
Map<String, String> preempts = createPreemptiveProperties(
|
Map<String, String> preempts = createPreemptiveProperties(
|
||||||
VHD_CONFIGURATION_PROPERTY, vitroHomeDir);
|
VHD_CONFIGURATION_PROPERTY, vitroHomeDir, RP_MULTIPLE, rpfLocation);
|
||||||
|
|
||||||
ConfigurationPropertiesImpl bean = new ConfigurationPropertiesImpl(
|
ConfigurationPropertiesImpl bean = new ConfigurationPropertiesImpl(
|
||||||
stream, preempts, new BuildProperties(ctx).getMap());
|
stream, preempts, new BuildProperties(ctx).getMap());
|
||||||
|
@ -90,14 +99,36 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File locateRuntimePropertiesFile(File vitroHomeDir, StartupStatus ss) {
|
private String findMultipleRuntimePropertiesFiles(File vitroHomeDir,
|
||||||
File rpf = new File(vitroHomeDir, FILE_RUNTIME_PROPERTIES);
|
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 '"
|
throw new IllegalStateException("Did not find '"
|
||||||
+ FILE_RUNTIME_PROPERTIES + "' in vitro home directory '"
|
+ 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()) {
|
if (!rpf.isFile()) {
|
||||||
throw new IllegalStateException("'" + rpf.getPath()
|
throw new IllegalStateException("'" + rpf.getPath()
|
||||||
+ "' is not a file.");
|
+ "' is not a file.");
|
||||||
|
@ -111,9 +142,11 @@ public class ConfigurationPropertiesSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> createPreemptiveProperties(
|
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<String, String> map = new HashMap<String, String>();
|
||||||
map.put(propertyVitroHome, vitroHomeDir.getAbsolutePath());
|
map.put(propertyVitroHome, vitroHomeDir.getAbsolutePath());
|
||||||
|
map.put(propertyRpfMultiple, rpfLocation);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class ConfigurationPropertiesSmokeTests implements
|
||||||
StartupStatus ss = StartupStatus.getBean(ctx);
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
|
||||||
checkDefaultNamespace(ctx, props, ss);
|
checkDefaultNamespace(ctx, props, ss);
|
||||||
|
checkMultipleRPFs(ctx, props, ss);
|
||||||
checkLanguages(props, ss);
|
checkLanguages(props, ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +73,35 @@ 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:
|
* Warn if we set up the languages incorrectly:
|
||||||
*
|
*
|
||||||
* Must build with a language in order to select languages. Can't select
|
* Must build with a language in order to select languages. Can't select
|
||||||
* languages and force language. Shouldn't build with language unless
|
* languages and force language. Shouldn't build with language unless
|
||||||
* language filtering is enabled.
|
* language filtering is enabled.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue