On Wed, Jun 9, 2010 at 15:25, Rene Groeschke <[email protected]> wrote:
> Hi there,
>
> in my build i want to set a version property to several property files,
> which are part of my resources. Actually I'm doing this by adding a doLast{}
> to the processResources Task.
> In this closure I manually
> 1. read the text of each property file in a specific directory (a
> specific package located in the target directory of the processResources
> task)
> 2. replace a specific token in each property file if the token exists
> 3. store the changed file content back to the property file
>
> I sure there is a more gradle way to do this using filter and token. I found
> this snippet in the assemble.gradle file of the groovy gradle build:
>
> #####
> from("$projectDir/src/main/META-INF/groovy-release-info.properties") {
> filter {String line ->
> ['##ImplementationVersion##': project.version,
> '##BundleVersion##': project.groovyBundleVersion,
> '##BuildDate##': new
> SimpleDateFormat('dd-MMM-yyyy').format(buildTime),
> '##BuildTime##': new SimpleDateFormat('hh:mm
> aa').format(buildTime)].each {key, value ->
> line = line.replace(key, value)
> }
> line
> }
> }
> #####
> That has pointed me to filters in the copy spec. What I would like to do is
> to enrich the processResources task with a filter, which replaces all
> occurances of a specific token in each property file, but I'm not sure how
> to start here or if this is actually possible at all.
>
> Any Ideas?
>
> regards,
> René
>
> --
> ------------------------------------
> Rene Groeschke
>
> [email protected]
> http://www.breskeby.com
> http://twitter.com/breskeby
> ------------------------------------
I've done this in a build before, it's actually not very difficult.
Here's a snippet from my build:
Properties props = new Properties()
props.load(new FileInputStream('build.properties'))
props.load(new FileInputStream('local.build.properties'))
project.setProperty('props', props)
processResources {
from(sourceSets.main.resources.srcDirs) {
filter(ReplaceTokens, tokens: project.props)
}
from(sourceSets.main.java.srcDirs) {
include '**/*.properties'
filter(ReplaceTokens, tokens: [pricingWebServiceAddress:
project.props.getProperty('pricing.webservice.address')])
}
}
processResources is actually a task of type Copy so you can do all
your config in there.
--
Jason Porter
Software Engineer
Open Source Advocate
http://lightguard-jp.blogspot.com
http://twitter.com/lightguardjp
PGP key id: 926CCFF5
PGP key available at: keyserver.net, pgp.mit.edu
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email