Phing: skeleton files
25/01/2010I use various build scripts and environments while developing, but many parts of the project stay the same.
One thing that always changes on a new build though, is configuration.
The easisest way to manage configuration is having all of the properties of an application saved in a file, and then have your build script apply those settings to any skeleton file found within the project. You might call this in typo3 terms, marker replacement.
Since my ExportProperties task has been included in Phing 2.4, it’s now a lot easier to do this using Phing, ExportProperties, Copy task and the ExpandProperties filter
<?xml version="1.0" encoding="UTF-8"?> <project name="example" basedir="." default="skel"> <!-- This is where we store the configured properties --> <property name="paths.config.phingProperties" value="${paths.config}/phing.properties" /> <!-- Check if we already have properties --> <available file="${paths.config.phingProperties}" property="hasPhingProperties" /> <target name="config"> <if> <equals arg1="${hasPhingProperties}" arg2="true" /> <then> <echo message="Reconfigure application..." /> </then> <else> <echo message="Configure application ..." /> </else> </if> <propertyprompt propertyName="db.host" defaultValue="localhost" promptText="Mysql Server Host" /> <propertyprompt propertyName="db.username" promptText="Mysql Username" /> <propertyprompt propertyName="db.password" promptText="Mysql Password" /> <propertyprompt propertyName="db.name" defaultValue="${db.username}" promptText="Mysql Database name" /> <!-- Export the properties --> <exportproperties targetFile="${paths.config.phingProperties}" /> </target> <target name="loadProperties"> <if> <equals arg1="${hasPhingProperties}" arg2="true" /> <then> </then> <else> <echo message="Missing config file ..." /> <phingcall target="config" /> </else> </if> <property file="${paths.config.phingProperties}" /> </target> <!-- Copies every file ending in .skel found in the current directory and all subdirectories to the same filename excluding .skel Also replaces property markers with actual values --> <target name="skel" depends="loadProperties"> <echo msg="Skel files..." /> <copy todir="" overwrite="true"> <mapper type="glob" from="*.skel" to="*"/> <filterchain> <expandproperties /> </filterchain> <fileset dir="."> <include name="**/*.skel" /> </fileset> </copy> </target> </project>
And then in config/env.ini.skel:
[production] ; Doctrine settings resources.doctrine.connection_string = "mysql://${db.username}:${db.password}@${db.host}/${db.name};unix_socket=/var/run/mysqld/mysqld.sock"
