Hi Federico,
${File.separator} is not needed, java.io.File will handle '/' no matter the OS.
On the other hand, I would think again if there are not better
alternatives to this. I used to prepare war files like you are doing,
and it's a headache. There are better alternatives, like using -D to
specify the environment you are interested in at runtime.
Just a suggestion.
On Fri, Feb 26, 2010 at 8:30 PM, Federico Schroder <[email protected]> wrote:
>
> I finally resolved this by replacing the file in place before doing the build
> (building the war)
> Something like this:
>
> war.doFirst {
> webInfEnvironment = 'default'
>
> // check if configuration was set.
> if (project.hasProperty('deployConfig')) {
> processEnvFiles()
> webInfEnvironment = targetEnvironment
> }
>
> processWebInfFiles(webInfEnvironment)
>
> }
>
> def processWebInfFiles(webInfEnvironment) {
> def webInfDir = new
> File("${projectDir}${File.separator}src${File.separator}main${File.separator}webapp${File.separator}WEB-INF")
> webInfDir.listFiles().each {File file ->
> replacementFile = new
> File("${file}.${webInfEnvironment}")
>
> if (replacementFile.exists() &&
> replacementFile.isFile()) {
> logger.debug(Logging.LIFECYCLE, "Overwriting:
> ${file.name} with
> ${replacementFile.name}" )
> ant.copy(file : replacementFile,
> tofile: file,
> overwrite : true)
> }
> }
> }
>
>
> This far from ideal, since every file is evaluated for a possible
> replacement and it's impossible to tell whether not having one should
> trigger an error, so a missing file might leave an unexpected file in the
> build.
> A list of "to be replaced" files could be put somewhere to make this
> behavior more predictable.
> Also you need a .default version of every configured file, since the
> original file gets replaced with every build.
>
> Federico
> --
> View this message in context:
> http://old.nabble.com/WAR---per-environment-configuration-tp27693855p27722429.html
> Sent from the gradle-user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email