Permalink
Browse files

Read properties from the environment.

Although this is generally discouraged, it is the recommended practice for production configuration for Heroku deployed applications.  This will enable an application to be deployed to Heroku without any code change from the local setup, or deployment setup on other environments.
  • Loading branch information...
1 parent 70ec330 commit d80b421cbd67c55fe41c1218495bfdcf4cad5942 @robb1e robb1e committed Mar 24, 2012
View
@@ -89,6 +89,10 @@ or version control, according to their variety:
These properties are provided by a war resource usually located at
`/conf/global.properties`.
+8. _Environment properties_: Properties which are defined at the operating system level.
+ These should not be used unless required by deployment in a restrictive hosting
+ environment, i.e. Heroku.
+
Only properties of types 3 through 7 should be provided to applications. They
should be sourced as specified, first property definition wins, in the order
@@ -275,5 +279,7 @@ And result in a `conf.toString` with contents:
# Properties from classpath:conf/global.properties
+ # Properties from System
+
Note that nonactive `datasource.connection.timeout.ms` from `global.properties`
is not reported.
@@ -35,7 +35,8 @@ private[conf] class GuardianConfigurationStrategy(
getOperationsProperties(applicationName),
getDeveloperStageBasedProperties(webappConfDirectory),
getDeveloperServiceDomainBasedProperties(webappConfDirectory),
- getDeveloperCommonProperties(webappConfDirectory))
+ getDeveloperCommonProperties(webappConfDirectory),
+ getSystemProperties)
val placeholderProcessed = new PlaceholderProcessingConfiguration(properties)
@@ -91,4 +92,9 @@ private[conf] class GuardianConfigurationStrategy(
new PropertiesBasedConfiguration(location, properties)
}
+
+ def getSystemProperties = {
+ LOG.info("Loading system properties")
+ new PropertiesBasedConfiguration("System", System.getProperties())
+ }
}
@@ -93,15 +93,15 @@ class GuardianConfigurationStrategyTest extends FunSuite with ShouldMatchers wit
configuration.hasProperty("stage") should be(false)
}
- test("should not override properties with system properties if defined") {
+ test("should contain properties from system") {
try {
System.setProperty("source", "system.override.property")
System.setProperty("random.system.property", "meh")
val configuration = strategy.getConfiguration("webapp", "conf")
configuration("source") should be("developer.account.override.properties")
- configuration.hasProperty("random.system.property") should be(false)
+ configuration.hasProperty("random.system.property") should be(true)
} finally {
System.clearProperty("source")
System.clearProperty("random.system.property")
@@ -172,6 +172,9 @@ class GuardianConfigurationStrategyTest extends FunSuite with ShouldMatchers wit
"\n" +
"# Properties from classpath:conf/global.properties\n" +
"developer.common.properties=available\n" +
+ "\n" +
+ "# Properties from System\n" +
+ "user.home=" + System.getProperty("user.home") + "\n" +
"\n")
System.setProperties(system)

0 comments on commit d80b421

Please sign in to comment.