ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Fetzer <elstonk...@yahoo.com>
Subject Re: Merge base settings with environment specific ones
Date Wed, 13 May 2009 17:58:44 GMT
OK, so here's what I did with NAnt and a C# .Net project for this same problem.  My properties
files were all xml, so I wrote a program that read a master config file and based on what
argument was passed for <environment>, the program went into the config file it was
configuring at the designated xpath and set that node value to the specified environmental
value.  So the master config file looked something like this:

<xml...>
  <configfile file="C:\program files\myfile.xml">
    <xpath value="configuration/appSettings/key[@key="connectionString"]/@value">
      <environments>
        <env dev="myConnectionStringForDev"/>
        <env qa="myConnectionStringForQA"/>
        <env prod="myConnectionStringForProd"/>
      </environments>
    </xpath>
    <xpath value="configuration/appSettings/key[@key="dogHouse"]/@value"> 
      <environments>
        <env dev="devDogHouse"/>
        <env qa="qaDogHouse"/>
        <env prod="prodDogHouse"/>
      </environments>
    </xpath>
  </configfile>
  <configfile file="C:\program files\anotherConfigfile.xml">
    <xpath value="configuration/appSettings/key[@key="connectionString"]/@value">
      <environments>
        <env dev="myConnectionStringForDev"/>
        <env qa="myConnectionStringForQA"/>
        <env prod="myConnectionStringForProd"/>
      </environments>
    </xpath>
    <xpath value="configuration/appSettings/key[@key="dogHouse"]/@value"> 
      <environments>
        <env dev="devDogHouse"/>
        <env qa="qaDogHouse"/>
        <env prod="prodDogHouse"/>
      </environments>
    </xpath>
  </configfile>
</xml...>

Seems something similar could be done for non-xml files as well using global substitution
using regex or such...




________________________________
From: nagish <jiang.lin@citi.com>
To: user@ant.apache.org
Sent: Wednesday, May 13, 2009 11:18:00 AM
Subject: Re: Merge base settings with environment specific ones


Thanks for the reply. A couple of clarifications:

1. The setting property files are intended to be built by an Ant script as
part of an application. In other words, the properties contained in those
files are to be read by the application, not by the Ant build script itself.

2. The setting property files are unknown to the Ant script at the time of
writing the script. In other words, they cannot be directly referenced by
the Ant script.

Thanks.

Eric Fetzer wrote:
> 
> 
> 
> 
> The first statement will load in all of the env dependant properties.  The
> second will load in all of the others.  Someone correct me if I'm wrong,
> but I don't believe the second statement will overwrite any of the
> properties that were already set by the first because you would have to
> "unset" those properties first.  This seemed like a bug to me, but I'm
> sure it's by design...
> 

-- 
View this message in context: http://www.nabble.com/Merge-base-settings-with-environment-specific-ones-tp23524997p23526214.html
Sent from the Ant - Users mailing list archive at Nabble.com.



      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message