Edit Configuration file using Ant xmltask

332 views Asked by At
<configuration>
  <userSettings>
        <IntegrationTests.Resources.IntegrationTests>
            <setting name="UserAppPath" serializeAs="String">
                <value>C:\Program Files (x86)\App\</value>
            </setting>
            <setting name="LogFilePath" serializeAs="String">
                <value>C:\logfiles\</value>
            </setting>
        </IntegrationTests.Resources.IntegrationTests>
  </userSettings>
</configuration>

I have the above xml file, I want my build job to edit these path values dynamically during the job run...so if setting name is UserAppPath then update the value tag of the same with correct path same if setting is LogFilePath then edit the logfile path based on the slave I have chosen...like wise i might have n number of settings but may be interested to change only few of them. I have tried replace,insert ask of ant xmltask. but did not solve my problem.... any help will be appreciated

1

There are 1 answers

0
ewan.chalmers On

You could do this using copy with filterset.

Put your variables in a properties file, e.g.

user.app.path=C:\\Program Files (x86)\\App\\
logfile.path=C:\\logfiles\\

Create a template version of your configuration file, e.g.

<configuration>
  <userSettings>
        <IntegrationTests.Resources.IntegrationTests>
            <setting name="UserAppPath" serializeAs="String">
                <value>@user.app.path@</value>
            </setting>
            <setting name="LogFilePath" serializeAs="String">
                <value>@logfile.path@</value>
            </setting>
        </IntegrationTests.Resources.IntegrationTests>
  </userSettings>
</configuration>

In your build file, create a version of the configuration file, substituting the placeholders in the template version with filterset:

<project name="test" default="test">
  <target name="test">
    <copy file="config_template.xml" tofile="config.xml">
      <filterset begintoken="@" endtoken="@">
        <filtersfile file="config.properties" />
      </filterset>
    </copy>
  </target>
</project>