Mercurial > public > develkit
comparison init.gradle @ 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 |
comparison
equal
deleted
inserted
replaced
105:f7b0f9d286b8 | 106:34bb1f5b9027 |
---|---|
120 def loadEnvironments() { | 120 def loadEnvironments() { |
121 def developerPrivate = new Properties() | 121 def developerPrivate = new Properties() |
122 if (file('private.properties').exists()) { | 122 if (file('private.properties').exists()) { |
123 developerPrivate.load(file('private.properties').newReader()) | 123 developerPrivate.load(file('private.properties').newReader()) |
124 } | 124 } |
125 gradle.ext.env = (hasProperty('env') ? getProperty('env') : (developerPrivate.env ?: 'dev')) | 125 def envOverrides = [:] |
126 println "Environment is: $gradle.env" | 126 |
127 if ( !hasProperty('env') ) { | |
128 gradle.ext.env = developerPrivate.env ?: 'dev' | |
129 } else { | |
130 def values = getProperty('env').split(',') | |
131 gradle.ext.env = values.first() | |
132 values.tail().each { | |
133 def (k,v) = it.split('=') | |
134 envOverrides.put(k,v) | |
135 } | |
136 } | |
137 | |
138 println "Environment is: $gradle.env ($envOverrides)" | |
127 def slurper = new ConfigSlurper(gradle.env) | 139 def slurper = new ConfigSlurper(gradle.env) |
128 def environment = new ConfigObject() | 140 def environment = new ConfigObject() |
129 def environments = [] | 141 def environments = [] |
130 | 142 |
131 file('.').eachFileMatch(~/^environment.*\.groovy$/) { envFile -> | 143 file('.').eachFileMatch(~/^environment.*\.groovy$/) { envFile -> |
138 def (k,v) = p.split('=') | 150 def (k,v) = p.split('=') |
139 logger.info("$envName: overriding " + k + "=" + v) | 151 logger.info("$envName: overriding " + k + "=" + v) |
140 envCfg.put(k,v) | 152 envCfg.put(k,v) |
141 } | 153 } |
142 } | 154 } |
143 environment.merge(envCfg) | 155 envOverrides.each { k,v -> |
144 if (envName != 'environment' ) { | 156 logger.info("$envName: overriding " + k + "=" + v) |
157 envCfg.put(k,v) | |
158 } | |
159 environment.merge(envCfg) | |
160 if (envName != 'environment' ) { | |
145 gradle.ext[envName] =envCfg | 161 gradle.ext[envName] =envCfg |
146 environments << envName | 162 environments << envName |
147 } | 163 } |
148 } | 164 } |
149 environment.merge(slurper.parse(developerPrivate)) | 165 environment.merge(slurper.parse(developerPrivate)) |