changeset 106:34bb1f5b9027

support setting env and overriding of specific properties
author smith@nwoca.org
date Wed, 16 May 2012 18:24:23 +0100
parents f7b0f9d286b8
children 167745cd8af9
files init.gradle
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/init.gradle	Tue May 15 19:02:25 2012 +0100
+++ b/init.gradle	Wed May 16 18:24:23 2012 +0100
@@ -122,8 +122,20 @@
     if (file('private.properties').exists()) {
         developerPrivate.load(file('private.properties').newReader())
     }
-    gradle.ext.env = (hasProperty('env') ? getProperty('env') : (developerPrivate.env ?: 'dev'))
-    println "Environment is: $gradle.env"
+    def envOverrides = [:]
+    
+    if ( !hasProperty('env') ) {
+        gradle.ext.env = developerPrivate.env ?: 'dev'
+    } else {
+        def values = getProperty('env').split(',')
+        gradle.ext.env = values.first()
+        values.tail().each {
+            def (k,v) = it.split('=')
+            envOverrides.put(k,v)
+        }
+    }
+    
+    println "Environment is: $gradle.env ($envOverrides)"
     def slurper = new ConfigSlurper(gradle.env)
     def environment = new ConfigObject()
     def environments = []
@@ -140,8 +152,12 @@
                 envCfg.put(k,v)
             }
         }
-        environment.merge(envCfg)        
-        if (envName != 'environment' ) { 
+        envOverrides.each { k,v ->
+            logger.info("$envName: overriding " + k + "=" + v)
+            envCfg.put(k,v)
+        }
+        environment.merge(envCfg)
+        if (envName != 'environment' ) {
            gradle.ext[envName] =envCfg 
            environments << envName
         }