code_junkie

Is there a way to dynamically load a properties file in NAnt?

Nov 10th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <property name="environment" value="local" />
  2.  
  3. <target name="config">
  4. <!-- configuration logic goes here -->
  5. </target>
  6.  
  7. <target name="buildmyproject" depends="config">
  8. <!-- this target builds your project, but runs the config target first -->
  9. </target>
  10.  
  11. <target name="config">
  12. <property name="configFile" value="${environment}.config.xml" />
  13. <if test="${file::exists(configFile)}">
  14. <echo message="Loading ${configFile}..." />
  15. <include buildfile="${configFile}" />
  16. </if>
  17. <if test="${not file::exists(configFile) and environment != 'local'}">
  18. <fail message="Configuration file '${configFile}' could not be found." />
  19. </if>
  20. </target>
  21.  
  22. <include buildfile="devPropertyFile.build" if="${buildEnvironment == 'DEV'}"/>
  23. <include buildfile="testPropertyFile.build" if="${buildEnvironment == 'TEST'}"/>
  24. <include buildfile="prodPropertyFile.build" if="${buildEnvironment == 'PROD'}"/>
  25.  
  26. <target name="dev">
  27. <property name="environment" value="dev"/>
  28. <call target="importProperties" cascade="false"/>
  29. </target>
  30.  
  31. <target name="test">
  32. <property name="environment" value="test"/>
  33. <call target="importProperties" cascade="false"/>
  34. </target>
  35.  
  36. <target name="stage">
  37. <property name="environment" value="stage"/>
  38. <call target="importProperties" cascade="false"/>
  39. </target>
  40.  
  41. <target name="importProperties">
  42. <property name="propertiesFile" value="properties.${environment}.build"/>
  43. <if test="${file::exists(propertiesFile)}">
  44. <include buildfile="${propertiesFile}"/>
  45. </if>
  46. <if test="${not file::exists(propertiesFile)}">
  47. <fail message="Properties file ${propertiesFile} could not be found."/>
  48. </if>
  49. </target>
  50.  
  51. <project default="all">
  52. <include buildfile="wip.build"/>
  53. <target name="all">
  54. <echo message="Building default target " />
  55.  
  56. <call target="WipTarget" />
  57. </target>
  58. </project>
Add Comment
Please, Sign In to add comment