On 25/03/10 9:31 AM, Hans Dockter wrote:
On Wed, Mar 24, 2010 at 9:52 PM, Jason Porter <lightguard.jp
<http://lightguard.jp>@gmail.com <http://gmail.com>> wrote:
On Wed, Mar 24, 2010 at 01:25, Hans Dockter <[email protected]
<mailto:[email protected]>> wrote:
Hi Jesse,
On Wed, Mar 24, 2010 at 8:18 AM, Jesse Eichar
<[email protected]
<mailto:[email protected]>> wrote:
Hi,
I want to do the ant filter:
ant.copy (todir: "$buildDir/webappSource") {
fileset(dir: "src/main/filtered-webapp")
filterset (begintoken: '@', endtoken: '@'){
filtersfile(file:
"${project(':proxy:config').projectDir}/filters/global-resource.filter")
}
}
I can see from the API how to do this if the filters are
in memory. Something like:
task copyTask(type: Copy) {
from 'src/main/webapp'
into 'build/explodedWar'
filter(ReplaceTokens, tokens:[copyright:'2009',
version:'2.3.1'])
}
Should I use ReplaceTokens and simply pass the Properties
object to the method? Or is there a cleaner way?
The above is the supposed way of doing it.
This works fine, but there really should be a cleaner way in
Gradle to do this. It's a very common thing and maybe
some syntactic sugar is in order (at the very least something like
tokenFile: <properties file>) so there's no need to build the
properties yourself. Of course then you get into the problem of
multiple properties files.
One improvement would be to have some properties factory:
filter(ReplaceTokens, tokens: properties('propfile1', 'propfile2',
[key1: 'value1'], someMap)
I have created a Jira for this: http://jira.codehaus.org/browse/GRADLE-871
The other problem is that you always need to import the ReplaceTokens
class. We either could either provide our own ReplaceTokens
implementation or add the Ant ReplaceTokens class to the default imports.
A couple of days ago I added CopySpec.expand(Map properties), which adds
a filter that runs the input files through a SimpleTemplateEngine with
the given properties, eg
processResources {
expand(key1: 'value1', key2: 'value2')
}
Replaces property references, such as ${key1}, plus you can use all the
other good stuff that SimpleTemplateEngine provides, eg ${key1 ?:
'unspecified'} or <%= classpath.join('\n') %>
We could extend expand() to accept any number of parameters:
- A Map would be used as is.
- Anything else would be passed to uri(), and a properties file loaded
from the resulting URI.
- The effective Map of properties would be assembled by adding the above
Maps together, in the order specified (last entry wins for duplicate
properties).
This would let you do something like:
processResources {
expand(project.properties, 'staging.properties',
'http://someshared/resource', key1: 'value', key2: 'value2')
}
I guess expand() isn't the greatest name. Perhaps expandProperties()?
And we could add a corresponding expandTokens() which accepts the same
types of parameters, and runs the file through ReplaceTokens filter with
the assembled map of properties.
--
Adam Murdoch
Gradle Developer
http://www.gradle.org