I have a problem where I need to create a tar file of properties files that have been filtered. I have the code below which works great for a single tar but I now need to produce multiple tar’s one per environment we support. Struggling to see the best way to do this?
task confTar(dependsOn:‘initConfig’, type:Tar){
def fileSuffix= “conf-${environment}”
archiveName = “asss_${version}.${svnRevision}-${fileSuffix}.tar”
from { “build/target/conf/${environment}”}
from(“build/target/${version}/${svnRevision}/conf/”){
include “${version}.${svnRevision}-conf.txt”
}
into ‘conf’
doFirst{
createVersionFile(‘conf’, svnRevision)
}
doLast{
checksum(archivePath)
} }
task initConfig(type:Copy){
def filterProps
if(filterConfig){
println(‘Doing filtering’)
filterProps= new Properties()
new File(“src/assembly/filters/${environment}-filter.properties”).withInputStream {
stream -> filterProps.load(stream)
}
}
from(‘src/assembly/conf’) {
include ‘**/*.properties’
include ‘**/*.xml’
}
from(‘src/assembly/conf’) {
include ‘**/*.template’
if(filterConfig){
filter(ReplaceTokens, beginToken:’~’, endToken:’~’, tokens: filterProps)
rename (‘env-specific.properties.template’,‘env-specific.properties’)
rename (‘configuration.properties.template’,‘configuration.properties’)
rename (‘services_decoupled.xml.template’,‘services_decoupled.xml’)
}
}
from(“src/assembly/platforms/${platform}/conf”) {
include ‘**/*.template’
if(filterConfig){
filter(ReplaceTokens, beginToken:’~’, endToken:’~’, tokens: filterProps)
rename (‘wrapper.conf.template’,‘wrapper.conf’)
}
}
into ‘build/target/conf/’+environment
includeEmptyDirs = false }