diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSetup.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSetup.java index c2ce8f764..773f43e87 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSetup.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSetup.java @@ -23,22 +23,22 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; /** * Locates the runtime configuration properties and stores them in the servlet * context. - * + * * This must be invoked before any listener that requires configuration * properties. - * + * * The properties are determined from a file called 'build.properties' in the * resources directory of the webapp, and a file called 'runtime.properties' in * 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 * 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 * issued and the first value is used. - * + * * The value that was determined for 'vitro.home' is also included in the * ConfigurationProperties bean. - * + * * If build.properties or runtime.properties cannot be located or loaded, a * 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 */ 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 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 createPreemptiveProperties( - String propertyVitroHome, File vitroHomeDir) { + String propertyVitroHome, File vitroHomeDir, String propertyRpfMultiple, + String rpfLocation) { Map map = new HashMap(); map.put(propertyVitroHome, vitroHomeDir.getAbsolutePath()); + map.put(propertyRpfMultiple, rpfLocation); return map; } diff --git a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSmokeTests.java b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSmokeTests.java index e5d92aeeb..7238bacfa 100644 --- a/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSmokeTests.java +++ b/api/src/main/java/edu/cornell/mannlib/vitro/webapp/config/ConfigurationPropertiesSmokeTests.java @@ -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,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: - * + * * Must build with a language in order to select languages. Can't select * languages and force language. Shouldn't build with language unless * language filtering is enabled.