Applied (modified) patch from Ernst Naezer, fixing FACILITIES-66.
[castle.git] / common-project.xml
blob149881f875aa6714c702a08752f1c15d55b5ca53
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                 <csc 
62                         target="library"
63                         define="${current.build.defines}"
64                         debug="${build.debug}"
65                         warnaserror="${build.warnaserrors}"
66                         output="${build.dir}/${project::get-name()}.dll"
67                         rebuild="${build.rebuild}"
68                 >
69                         <sources refid="project.sources" />
70                         <references refid="project.references" />
71                         <resources refid="project.resources" />
72                         <arg line="${csc.keyfile}" if="${assembly.sign}" />
73                         <arg line="${csc.args}" />
74                 </csc>
76                 <!-- Check if there is a framework specific config file and use that -->
77                 <property name="app.config.src" value="${src.dir}/App-${framework::get-target-framework()}.config" />
78                 <if test="${file::exists(app.config.src)}">
79                         <copy 
80                                 file="${app.config.src}"
81                                 tofile="${build.dir}/${project::get-name()}.dll.config"
82                         />
84                         <call target="common.configure-tests" />
85                         <property name="app.config.src.found" value="true" />
86                 </if>
87                 <!-- In case there was no framework specific config check if there is a framework neutral file and use that. -->
88                 <property name="app.config.src" value="${src.dir}/App.config" />
89                 <if test="${file::exists(app.config.src)}" unless="${property::exists('app.config.src.found')}">
90                         <copy 
91                                 file="${app.config.src}"
92                                 tofile="${build.dir}/${project::get-name()}.dll.config"
93                         />
95                         <call target="common.configure-tests" />
96                 </if>
98         </target>
100         <target name="common.configure-tests"
101                 description="Configure tests for running NUnit tests.">
103                 <property name="app.config" value="${build.dir}\${project::get-name()}.dll.config" />
105                 <!-- make sure the config file is writable -->
106                 <attrib file="${app.config}" readonly="false" />
107                 
108                 <xmlpoke
109                         file="${app.config}"
110                         xpath="/configuration/appSettings/add[@key='tests.src']/@value"
111                         value="${src.dir}"
112                         failonerror="false"
113                 />
114         </target>
116         <target name="common.compile-dll"
117                 description="Compile sources into a DLL">
119                 <csc
120                         target="library" 
121                         define="${current.build.defines}" 
122                         debug="${build.debug}" 
123                         optimize="${build.optimize}"
124                         warnaserror="${build.warnaserrors}"
125                         output="${build.dir}\${project::get-name()}.dll" 
126                         doc="${build.dir}\${project::get-name()}.xml"
127                         rebuild="${build.rebuild}"
128                 >
129                         <nowarn>
130                                 <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
131                         </nowarn>
132                         <sources refid="project.sources" />
133                         <references refid="project.references" />
134                         <resources refid="project.resources" />
135                         <arg line="${csc.keyfile}" if="${assembly.sign}" />
136                         <arg line="${csc.args}" />
137                 </csc>
138         </target>
140         <target name="common.compile-website">
141                 <property name="bin.dir" value="${src.dir}/bin" />
142                 <mkdir dir="${bin.dir}" />
143                 <delete file="${bin.dir}/${project::get-name()}.pdb" failonerror="false" /> <!-- To prevent 1.1 compiler from crashing when switching from a 2.0 build -->
144                 <property name="build.dir" value="${bin.dir}" />
146                 <call target="common.compile-dll" />
147                 <call target="common.copy-references" />
148         </target>
150         <target name="common.copy-references">
151                 <foreach item="File" property="reference">
152                         <in>
153                                 <items refid="project.references" />
154                         </in>
155                         <do>
156                                 <copy file="${reference}" todir="${bin.dir}" overwrite="${build.rebuild}" />
157                         </do>
158                 </foreach>
159         </target>
161         <target name="common.compile-exe"
162                 description="Compile sources into a console executable">
164                 <csc
165                         target="exe"
166                         define="${current.build.defines}" 
167                         debug="${build.debug}"
168                         optimize="${build.optimize}"
169                         warnaserror="${build.warnaserrors}"
170                         output="${build.dir}\${project::get-name()}.exe" 
171                 >
172                         <nowarn>
173                                 <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
174                         </nowarn>
175                         <sources refid="project.sources" />
176                         <references refid="project.references" />
177                         <resources refid="project.resources" />
178                         <arg line="${csc.keyfile}" if="${assembly.sign}" />
179                         <arg line="${csc.args}" />
180                 </csc>
181         </target>
183         <target name="common.set-assembly-attribute-values">
184                 <property overwrite="false" name="assembly.is-cls-compliant" value="true" />
185                 <property overwrite="false" name="assembly.is-com-visible" value="false" />
186                 <property overwrite="false" name="assembly.guid" value="" />
187                 <property overwrite="false" name="assembly.allow-partially-trusted-callers" value="false" />
188                 <property overwrite="false" name="assembly.description" value="" />
189                 <property overwrite="false" name="assembly.product" value="${project::get-name()}" />
190                 <property overwrite="false" name="assembly.company" value="${project.company}" />
191                 <property overwrite="false" name="assembly.title" value="${project::get-name()} for ${framework::get-description(framework::get-target-framework())}" />
192                 <property overwrite="false" name="assembly.version" value="${project.major}.${project.minor}.${project.build}.0" />
193                 <property overwrite="false" name="assembly.version.informational" value="${assembly.major}.${assembly.minor}.${assembly.build}.${svn.revision}" />
194                 <property overwrite="false" name="assembly.copyright" value="Castle Project, original author or authors" />
195                 <property overwrite="false" name="assembly.keyfile" value="${key.file}" />
196                 <property overwrite="false" name="assembly.sign" value="${sign}" />
197         </target>
199         <target name="common.generate-assemblyinfo"
200                 depends="common.init common.set-assembly-attribute-values"
201                 description="Generate AssemblyInfo.cs using assembly.* properties."
202         >
203                 <property name="assemblyinfo.cs" value="${path::combine(src.dir,'AssemblyInfo.cs')}" />
204                 <attrib file="${assemblyinfo.cs}" readonly="false" />
205                 <asminfo output="${assemblyinfo.cs}" language="CSharp">
206                         <imports>
207                                 <import namespace="System" />
208                                 <import namespace="System.Reflection" />
209                                 <import namespace="System.Runtime.CompilerServices" />
210                                 <import namespace="System.Runtime.InteropServices" />
211                                 <import namespace="System.Security" if="${assembly.allow-partially-trusted-callers}" />
212                         </imports>
213                         <attributes>
214                                 <attribute type="CLSCompliantAttribute" value="${assembly.is-cls-compliant}" />
215                                 <attribute type="ComVisibleAttribute" value="${assembly.is-com-visible}" />
216                                 <attribute type="GuidAttribute" value="${assembly.guid}" if="${assembly.guid != ''}" />
217                                 <attribute type="AssemblyTitleAttribute" value="${assembly.title}" />
218                                 <attribute type="AssemblyDescriptionAttribute" value="${assembly.description}" />
219                                 <attribute type="AssemblyCompanyAttribute" value="${assembly.company}" />
220                                 <attribute type="AssemblyProductAttribute" value="${assembly.product}" />
221                                 <attribute type="AssemblyCopyrightAttribute" value="${assembly.copyright}" />
222                                 <attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
223                                 <attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version.informational}" />
224                                 <attribute type="AssemblyFileVersionAttribute" value="${assembly.version}" />
225                                 <attribute type="AssemblyDelaySignAttribute" value="false" />
226                                 
227                                 <!-- For some reason, NAnt doesn't detect that APTCA has a public no-argument constructor -->
228                                 <attribute asis="true" type="AllowPartiallyTrustedCallersAttribute" if="${assembly.allow-partially-trusted-callers}" />
229                         </attributes>
230                 </asminfo>
231                 <if test="${assembly.sign}" >
232                         <echo append="true" file="${assemblyinfo.cs}">#if !DOTNET2</echo>
233                         <echo append="true" file="${assemblyinfo.cs}">[assembly: AssemblyKeyFileAttribute(@"${path::get-full-path(assembly.keyfile)}")]</echo>
234                         <echo append="true" file="${assemblyinfo.cs}">#endif</echo>
235                 </if>
236         </target>
237         
238         <target name="common.assemblyinfo">
240                 <nant target="generate-assemblyinfo">
241                         <buildfiles refid="buildfiles.all" />
242                 </nant>
244         </target>
246         <target name="common.run-tests"
247                 description="Run NUnit tests">
249                 <if test="${common.run-tests}">
250                         <call target="common.find-nunit" />
252                         <echo message="Running tests in '${project::get-name()}'" />
254                         <!-- Use nunit-console.exe if found, otherwise fall back to nunit2 task -->
255                         <exec if="${nunit.found}"
256                                 program="${nunit-console}" 
257                                 workingdir="${build.dir}" 
258                                 commandline="${build.dir}\${project::get-name()}.dll /xml:${testresults.dir}/${project::get-name()}.dll-results.xml /config=${build.dir}\${project::get-name()}.dll.config /nologo"
259                                  />
261                         <nunit2 unless="${nunit.found}">
262                                 <formatter 
263                                         type="Xml" 
264                                         usefile="true" 
265                                         extension=".xml" 
266                                         outputdir="${testresults.dir}"
267                                 />
268                                 <test
269                                         assemblyname="${build.dir}\${project::get-name()}.dll"
270                                         appconfig="${build.dir}\${project::get-name()}.dll.config" />
271                         </nunit2>
272                 </if>
273                 <if test="${not common.run-tests}">
274                         <echo message="Tests are disabled for '${project::get-name()}'" />
275                 </if>
277         </target>
279         <target name="common.run-database-tests"
280                 depends="common.put-connection-settings-into-app-config common.run-tests common.remove-connection-settings-from-app-config" />
282         <target name="common.put-connection-settings-into-app-config">
284                 <property name="app.config" value="${build.dir}\${project::get-name()}.dll.config" />
286                 <!-- make sure the config file is writable -->
287                 <attrib file="${app.config}" readonly="false" />
289                 <!-- 
290                         Tell nhibernate how to connect to the test database.
291                 -->
292                 <xmlpoke
293                         file="${app.config}"
294                         xpath="/configuration/nhibernate/add[@key='hibernate.dialect']/@value"
295                         value="${nhibernate.dialect}" 
296                 />
297                 <xmlpoke
298                         file="${app.config}"
299                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.driver_class']/@value"
300                         value="${nhibernate.connection.driver_class}" 
301                 />
302                 <xmlpoke
303                         file="${app.config}"
304                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
305                         value="${nhibernate.connection.connection_string}" 
306                 />
307         </target>
309         <target name="common.remove-connection-settings-from-app-config">
310                 <property name="app.config" value="${build.dir}\${project::get-name()}.dll.config" />
312                 <xmlpoke
313                         file="${app.config}"
314                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
315                         value="conn string here" 
316                 />
317         </target>
319 </project>