Author: echatellier Date: 2013-07-17 17:58:54 +0200 (Wed, 17 Jul 2013) New Revision: 146 Url: http://nuiton.org/projects/nuiton-js/repository/revisions/146 Log: fixes #2762: Load nuiton-js.properties from classpath instead of servlet context (/WEB-INF) fixes #2613: Remove message : [FAIL] Cannot read properties file stream from default location Modified: trunk/nuiton-js-wro/src/main/java/org/nuiton/js/wro/NuitonJsWroConfigurationFactory.java Modified: trunk/nuiton-js-wro/src/main/java/org/nuiton/js/wro/NuitonJsWroConfigurationFactory.java =================================================================== --- trunk/nuiton-js-wro/src/main/java/org/nuiton/js/wro/NuitonJsWroConfigurationFactory.java 2013-07-15 21:42:59 UTC (rev 145) +++ trunk/nuiton-js-wro/src/main/java/org/nuiton/js/wro/NuitonJsWroConfigurationFactory.java 2013-07-17 15:58:54 UTC (rev 146) @@ -29,7 +29,6 @@ import javax.servlet.FilterConfig; import javax.servlet.ServletContext; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ro.isdc.wro.config.Context; @@ -72,7 +71,9 @@ /** * @return default path to configuration file relative to {@link ServletContext} location. + * @deprecated since 1.0.1 with no remplacment, will be removed in 1.1+ */ + @Deprecated protected String getUserConfigPath() { return "/WEB-INF/nuiton-js.properties"; } @@ -93,23 +94,56 @@ Properties result = getDefaultConfig(); InputStream propertyStream = null; + String file = "/nuiton-js.properties"; + try { + LOG.debug("loading config resource from: {}", file); + propertyStream = NuitonJsWroConfigurationFactory.class.getResourceAsStream(file); + if (propertyStream != null) { + Properties props = new Properties(); + props.load(propertyStream); + result.putAll(props); + } + } catch (final Exception e) { + LOG.info("Cannot read properties file stream from default location: {}. Using default configuration.", file); + } finally { + IOUtils.closeQuietly(propertyStream); + } + + return loadContextProperties(result); + } + + /** + * + * @param current + * @return + * @deprecated since 1.0.1 file moved to classpath, remove servlet context loading in 1.1+ + */ + @Deprecated + protected Properties loadContextProperties(Properties current) { + InputStream propertyStream = null; String file = getUserConfigPath(); try { LOG.debug("loading config resource from: {}", file); propertyStream = loadAsStream(file); - Validate.notNull(propertyStream); - Properties props = new Properties(); - props.load(propertyStream); - result.putAll(props); + if (propertyStream != null) { + LOG.warn("Loading configuration from deprecated {} location. Update configuration to use classpath '/nuiton-js.properties' instead", + file); + Properties props = new Properties(); + props.load(propertyStream); + current.putAll(props); + } } catch (final Exception e) { - LOG.error("[FAIL] Cannot read properties file stream from default location: {}. Using default configuration.", file); + LOG.debug("Cannot read properties file stream from servlet context location: {}.", file); } finally { IOUtils.closeQuietly(propertyStream); } - - return result; + return current; } + /** + * @deprecated since 1.0.1 with no remplacment, will be removed in 1.1+ + */ + @Deprecated protected InputStream loadAsStream(String file) throws Exception { InputStream result = getServletContext().getResourceAsStream(file); return result;