Fixing an issue where setting a custom property on a handler will not propagate it...
[castle.git] / common-project.xml
blob91cdbf67550d384029e73831326a5f6fc37c4fc9
1 <?xml version="1.0" ?>
2 <project name="Castle" xmlns="http://nant.sf.net/release/0.85/nant.xsd">
4         <description>
5                 This file contains common tasks tailored specifically for the Castle
6                 build process. The goal was to define all the actions in this file, so
7                 that actual project build files only have to configure a few variables
8                 and call tasks in this file.
10                 Usage
12                 &lt;property name="root.dir" value="../.." /&gt;
13                 &lt;include buildfile="${root.dir}/build-common/common-project.xml" /&gt;
15                 These lines should be placed at the top level under the &lt;project&gt;
16                 element. Property root.dir defines a relative path to the root of the
17                 distribution, that is, Castle directory.
19                 After including the file, a target should be defined to initialize
20                 configuration variables according to the project being built.
21                 The standard of this target is init (but any other name can be chosen).
22                 The init target should depend on (or call) target common.init defined
23                 in this file.
25                 Other predefined targets are:
27                         - common.compile-tests
28                                 compile NUnit tests and copy App.config file to the output directory,
29                                 if it exists.
31                         - common.compile-dll
32                                 compile a DLL, generating the documentation and using Clover if enabled.
34                         - common.generate-assemblyinfo, common.generate-assemblyinfoversion
35                                 generate an AssemblyInfo.cs or AssemblyInfoVersion.cs file from
36                                 assembly.* NAnt properties.
38                         - common.run-tests
39                                 run compiled NUnit tests.
41                 All compile/run targets put the output in build.dir. Common.compile*
42                 targets use source fileset with id="project.sources", assembly fileset
43                 with id="project.references" and resource fileset with id="project.resources"
44                 to compile the project. The source and resource filesets are optional.
46         </description>
48         <include buildfile="common.xml" />
50         <target name="common.build">
52                 <nant>
53                         <buildfiles refid="buildfiles.all" />
54                 </nant>
56         </target>
58         <target name="common.compile-tests"
59                 description="Compile NUnit tests and copy App.config file to the output directory, if it exists.">
61                 <property name="istestsproject" value="true" />
62                 <call target="common.compile-dll" />
64                 <!-- Check if there is a framework specific config file and use that -->
65                 <property name="app.config.src" value="${src.dir}/App-${framework::get-target-framework()}.config" />
66                 <if test="${file::exists(app.config.src)}">
67                         <copy 
68                                 file="${app.config.src}"
69                                 tofile="${build.dir}/${project::get-name()}.dll.config"
70                         />
72                         <call target="common.configure-tests" />
73                         <property name="app.config.src.found" value="true" />
74                 </if>
75                 <!-- In case there was no framework specific config check if there is a framework neutral file and use that. -->
76                 <property name="app.config.src" value="${src.dir}/App.config" />
77                 <if test="${file::exists(app.config.src)}" unless="${property::exists('app.config.src.found')}">
78                         <copy 
79                                 file="${app.config.src}"
80                                 tofile="${build.dir}/${project::get-name()}.dll.config"
81                         />
83                         <call target="common.configure-tests" />
84                 </if>
86         </target>
88         <target name="common.configure-tests"
89                 description="Configure tests for running NUnit tests.">
91                 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
93                 <!-- make sure the config file is writable -->
94                 <attrib file="${app.config}" readonly="false" />
95                 
96                 <xmlpoke
97                         file="${app.config}"
98                         xpath="/configuration/appSettings/add[@key='tests.src']/@value"
99                         value="${src.dir}"
100                         failonerror="false"
101                 />
102         </target>
104         <target name="common.compile-dll"
105                 description="Compile sources into a DLL">
107                 <property name="istestsproject" value="false" overwrite="false" />
109                 <if test="${build.msbuild}">
110                         <property name="msbuildlogger" value="" overwrite="false" unless="${property::exists('CCNetLabel')}" />
111                         <property name="msbuildlogger" value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger" overwrite="false" if="${property::exists('CCNetLabel')}" />
112                         <property name="msbuild.defines" value="${string::replace(current.build.defines, ',', ';')}" />
114                         <exec program="${framework::get-framework-directory(framework::get-target-framework())}/MSBuild.exe" workingdir="${build.dir}">
115                                 <arg file="${src.dir}/${project.vsproj}" />
116                                 <arg value="/p:Configuration=${project.config}" />
117                                 <arg value="/p:OutputPath=${build.dir}" />
118                                 <arg value="/p:TreatWarningsAsErrors=${build.warnaserrors}" unless="${istestsproject}" />
119                                 <arg value='/p:DefineConstants="${msbuild.defines}"' />
120                                 <arg value='/t:Rebuild' if="${build.rebuild}" />
121                                 <arg value="/p:DocumentationFile=${build.dir}/${project::get-name()}.xml" unless="${istestsproject}" />
122                                 <arg value="/p:NoWarn=1591" unless="${build.warnmissingdocs}" />
123                                 <arg line="/p:SignAssembly=${assembly.sign} /p:AssemblyOriginatorKeyFile=${key.file}" />
124                                 <arg value="${msbuildlogger}" />
125                         </exec>
126                 </if>
127                 
128                 <if test="${not build.msbuild}">
129                         <property name="warnaserror" value="false" if="${istestsproject}" />
130                         <property name="warnaserror" value="${build.warnaserrors}" if="${not istestsproject}" />
131                         <csc
132                                 target="library" 
133                                 define="${current.build.defines}" 
134                                 debug="${build.debug}" 
135                                 optimize="${build.optimize}"
136                                 warnaserror="${warnaserror}"
137                                 output="${build.dir}/${project::get-name()}.dll" 
138                                 doc="${build.dir}/${project::get-name()}.xml"
139                                 rebuild="${build.rebuild}"
140                                 unless="${build.msbuild}"
141                         >
142                                 <nowarn>
143                                         <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
144                                 </nowarn>
145                                 <sources refid="project.sources" />
146                                 <references refid="project.references" />
147                                 <resources refid="project.resources" />
148                                 <arg line="${csc.keyfile}" if="${assembly.sign}" />
149                                 <arg line="${csc.args}" />
150                         </csc>
151                 </if>
152         </target>
154         <target name="common.compile-website">
155                 <property name="bin.dir" value="${src.dir}/bin" />
156                 <mkdir dir="${bin.dir}" />
157                 <delete file="${bin.dir}/${project::get-name()}.pdb" failonerror="false" /> <!-- To prevent 1.1 compiler from crashing when switching from a 2.0 build -->
158                 <property name="build.dir" value="${bin.dir}" />
160                 <call target="common.compile-dll" />
161                 <call target="common.copy-references" />
162         </target>
164         <target name="common.copy-references">
165                 <foreach item="File" property="reference">
166                         <in>
167                                 <items refid="project.references" />
168                         </in>
169                         <do>
170                                 <copy file="${reference}" todir="${bin.dir}" overwrite="${build.rebuild}" />
171                         </do>
172                 </foreach>
173         </target>
175         <target name="common.compile-exe"
176                 description="Compile sources into a console executable">
178                 <csc
179                         target="exe"
180                         define="${current.build.defines}" 
181                         debug="${build.debug}"
182                         optimize="${build.optimize}"
183                         warnaserror="${build.warnaserrors}"
184                         output="${build.dir}/${project::get-name()}.exe" 
185                 >
186                         <nowarn>
187                                 <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
188                         </nowarn>
189                         <sources refid="project.sources" />
190                         <references refid="project.references" />
191                         <resources refid="project.resources" />
192                         <arg line="${csc.keyfile}" if="${assembly.sign}" />
193                         <arg line="${csc.args}" />
194                 </csc>
195         </target>
197         <target name="common.set-assembly-attribute-values">
198                 <property overwrite="false" name="assembly.is-cls-compliant" value="true" />
199                 <property overwrite="false" name="assembly.is-com-visible" value="false" />
200                 <property overwrite="false" name="assembly.guid" value="" />
201                 <property overwrite="false" name="assembly.allow-partially-trusted-callers" value="false" />
202                 <property overwrite="false" name="assembly.description" value="" />
203                 <property overwrite="false" name="assembly.product" value="${project::get-name()}" />
204                 <property overwrite="false" name="assembly.company" value="${project.company}" />
205                 <property overwrite="false" name="assembly.title" value="${project::get-name()} for ${framework::get-description(framework::get-target-framework())}" />
206                 <property overwrite="false" name="assembly.version" value="${project.major}.${project.minor}.${project.build}.0" />
207                 <property overwrite="false" name="assembly.version.informational" value="${assembly.major}.${assembly.minor}.${assembly.build}.${svn.revision}" />
208                 <property overwrite="false" name="assembly.copyright" value="Castle Project, original author or authors" />
209                 <property overwrite="false" name="assembly.keyfile" value="${key.file}" />
210                 <property overwrite="false" name="assembly.sign" value="${sign}" />
211         </target>
213         <target name="common.generate-assemblyinfo"
214                 depends="common.init common.set-assembly-attribute-values"
215                 description="Generate AssemblyInfo.cs using assembly.* properties."
216         >
217                 <property name="assemblyinfo.cs" value="${path::combine(src.dir,'AssemblyInfo.cs')}" />
218                 <attrib file="${assemblyinfo.cs}" readonly="false" />
219                 <asminfo output="${assemblyinfo.cs}" language="CSharp">
220                         <imports>
221                                 <import namespace="System" />
222                                 <import namespace="System.Reflection" />
223                                 <import namespace="System.Runtime.CompilerServices" />
224                                 <import namespace="System.Runtime.InteropServices" />
225                                 <import namespace="System.Security" if="${assembly.allow-partially-trusted-callers}" />
226                         </imports>
227                         <attributes>
228                                 <attribute type="CLSCompliantAttribute" value="${assembly.is-cls-compliant}" />
229                                 <attribute type="ComVisibleAttribute" value="${assembly.is-com-visible}" />
230                                 <attribute type="GuidAttribute" value="${assembly.guid}" if="${assembly.guid != ''}" />
231                                 <attribute type="AssemblyTitleAttribute" value="${assembly.title}" />
232                                 <attribute type="AssemblyDescriptionAttribute" value="${assembly.description}" />
233                                 <attribute type="AssemblyCompanyAttribute" value="${assembly.company}" />
234                                 <attribute type="AssemblyProductAttribute" value="${assembly.product}" />
235                                 <attribute type="AssemblyCopyrightAttribute" value="${assembly.copyright}" />
236                                 <attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
237                                 <attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version.informational}" />
238                                 <attribute type="AssemblyFileVersionAttribute" value="${assembly.version.informational}" />
239                                 <attribute type="AssemblyDelaySignAttribute" value="false" />
240                                 
241                                 <!-- For some reason, NAnt doesn't detect that APTCA has a public no-argument constructor -->
242                                 <attribute asis="true" type="AllowPartiallyTrustedCallersAttribute" if="${assembly.allow-partially-trusted-callers}" />
243                         </attributes>
244                 </asminfo>
245                 <if test="${assembly.sign and not (nant.settings.currentframework == 'net-2.0')}" >
246                         <echo append="true" file="${assemblyinfo.cs}">#if MONO</echo>
247                         <echo append="true" file="${assemblyinfo.cs}">[assembly: AssemblyKeyFileAttribute(@"${path::get-full-path(assembly.keyfile)}")]</echo>
248                         <echo append="true" file="${assemblyinfo.cs}">#endif</echo>
249                 </if>
250         </target>
251         
252         <target name="common.assemblyinfo">
254                 <nant target="generate-assemblyinfo">
255                         <buildfiles refid="buildfiles.all" />
256                 </nant>
258         </target>
260         <target name="common.run-tests"
261                 description="Run NUnit tests">
263                 <if test="${common.testrunner.enabled}">
264                         <call target="common.find-nunit" />
266                         <echo message="Running tests in '${project::get-name()}'" />
268                         <exec if="${mbunit.found and string::to-lower(testrunner)=='mbunit'}"
269                                 program="${mbunit-console}" 
270                                 workingdir="${build.dir}"
271                                 commandline="${project::get-name()}.dll /rf:${testresults.dir} /rnf:${project::get-name()}.dll-results /rt:Xml"
272                                 failonerror="${common.testrunner.failonerror}"
273                         />
274                         <!-- Use nunit-console.exe if found, otherwise fall back to nunit2 task -->
275                         <exec if="${nunit.found and string::to-lower(testrunner)=='nunit'}"
276                                 program="${nunit-console}" 
277                                 workingdir="${build.dir}" 
278                                 commandline="${project::get-name()}.dll /xml:${testresults.dir}/${project::get-name()}.dll-results.xml /config:${build.dir}/${project::get-name()}.dll.config /nologo"
279                                 failonerror="${common.testrunner.failonerror}"
280                                  />
282                         <nunit2 unless="${nunit.found}" if="${string::to-lower(testrunner)=='nunit'}" failonerror="${common.testrunner.failonerror}">
283                                 <formatter 
284                                         type="Xml" 
285                                         usefile="true" 
286                                         extension=".xml" 
287                                         outputdir="${testresults.dir}"
288                                 />
289                                 <test
290                                         assemblyname="${build.dir}/${project::get-name()}.dll"
291                                         appconfig="${build.dir}/${project::get-name()}.dll.config" />
292                         </nunit2>
293                 </if>
294                 <if test="${not common.testrunner.enabled}">
295                         <echo message="Tests are disabled for '${project::get-name()}'" />
296                 </if>
298         </target>
300         <target name="common.run-database-tests"
301                 depends="common.put-connection-settings-into-app-config common.run-tests common.remove-connection-settings-from-app-config" />
303         <target name="common.put-connection-settings-into-app-config">
305                 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
307                 <!-- make sure the config file is writable -->
308                 <attrib file="${app.config}" readonly="false" />
310                 <!-- 
311                         Tell nhibernate how to connect to the test database.
312                 -->
313                 <xmlpoke
314                         file="${app.config}"
315                         xpath="/configuration/nhibernate/add[@key='hibernate.dialect']/@value"
316                         value="${nhibernate.dialect}" 
317                 />
318                 <xmlpoke
319                         file="${app.config}"
320                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.driver_class']/@value"
321                         value="${nhibernate.connection.driver_class}" 
322                 />
323                 <xmlpoke
324                         file="${app.config}"
325                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
326                         value="${nhibernate.connection.connection_string}" 
327                 />
328         </target>
330         <target name="common.remove-connection-settings-from-app-config">
331                 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
333                 <xmlpoke
334                         file="${app.config}"
335                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
336                         value="conn string here" 
337                 />
338         </target>
340 </project>