NAnt fails with "Invalid element <checksum>. Unknown task or datatype" - nant

I had to move from nant-0.86 to nant-0.92
This part of the code now fails with: Invalid element <checksum>. Unknown task or datatype.
<target name="make_one_cksum">
<!-- <echo message="ECHO za md5 ${filename}" /> -->
<checksum algorithm="MD5" fileext="MD5_nov">
<fileset>
<include name="${filename}"/>
</fileset>
</checksum>
</target>
Any suggestions to make this work again?

You will need to update your NAnt.Contrib.Task to 0.93.
Requirements
Assembly: NAnt.Contrib.Tasks (0.93.5041.0)
http://nantcontrib.sourceforge.net/nightly/latest/help/tasks/checksum.html

Related

phing dbdeploy with postgres

Hiho,
I want to use Phing an dbdeploy with a postgres DB.
the problem is that I can not connect to the database with the connection string because I can not define a password.
Does any one has an solution for this?
The following is the deply xml:
`
<!-- load the dbdeploy task -->
<taskdef name="dbdeploy" classname="phing.tasks.ext.dbdeploy.DbDeployTask" />
<!-- these two filenames will contain the generated SQL to do the deploy and roll it back -->
<property name="build.dbdeploy.deployfile" value="scripts/deploy-${DSTAMP}${TSTAMP}.sql" />
<property name="build.dbdeploy.undofile" value="scripts/undo-${DSTAMP}${TSTAMP}.sql" />
<!-- generate the deployment scripts -->
<dbdeploy
url="pgsql:host=${db.host};dbname=${db.name}"
userid="${db.username}"
password=""
dir="${phing.dir}/sql"
outputfile="${build.dbdeploy.deployfile}"
undooutputfile="${build.dbdeploy.undofile}" />
<!-- execute the SQL - Use psql command line to avoid trouble with large
files or many statements and PDO -->
<trycatch>
<try>
<exec
command="pqsql -h${db.host} -U${db.username} -p${db.port} -d${db.name} < ${build.dbdeploy.deployfile} -W"
dir="${phing.dir}"
checkreturn="true"
output="${phing.dir}/cache/deploy-${DSTAMP}${TSTAMP}.log"
error="${phing.dir}/cache/deploy-error-${DSTAMP}${TSTAMP}.log"
/>
<echo msg="Datenbank erfolgreich ausgerollt"/>
</try>
<catch>
<echo msg="Fehler beim ausrollen der Datenbank, führe Rollback durch"/>
<exec
command="pgsql -h${db.host} -U${db.username} -p${db.port} -d${db.name} < ${build.dbdeploy.undofile}"
dir="${phing.dir}"
checkreturn="true"
/>
<echo msg="Rollback erfolgreich"/>
</catch>
</trycatch>
</target>
<!-- ============================================ -->
<!-- Target: writeFiles -->
<!-- ============================================ -->
<target name="writeFiles" description="Write all properties in files">
<copy
file="${dir}config/autoload/local.php.dist"
tofile="${dir}config/autoload/local.php"
overwrite="true"
>
<filterchain>
<replacetokens begintoken="#" endtoken="#">
<token key="db.host" value="${db.host}"/>
<token key="db.username" value="${db.username}"/>
<token key="db.password" value="${db.password}"/>
<token key="db.name" value="${db.name}"/>
<token key="db.port" value="${db.port}"/>
</replacetokens>
</filterchain>
</copy>
<echo>local.php geschrieben.</echo>
</target>`
You can create a password file for the system user (the user which will execute the phing script).

How to redirect nant build errors to 'catch' section?

I need to build my application in 'try-catch' section of nant config file, like this:
<trycatch>
<try>
<echo message="Start building MyApplication.."/>
<call target="BuildApp"/>
</try>
<catch>
<echo message="Build MyApp.sln is failed"/>
<fail/>
</catch>
</trycatch>
When build is failed it only shows the message: "Build MyApp.sln is failed", without any detailed information why it failed. How can I redirect build errors to 'catch' section and see the reason of failing?
You need to add the property attribute to the catch tag:
<trycatch>
<try>
<echo message="Start building MyApplication.."/>
<call target="BuildApp"/>
</try>
<catch property="failure.message">
<echo message="Build MyApp.sln is failed"/>
<echo message="Failure message: ${failure.message}"/>
<fail />
</catch>
</trycatch>
You could also forward the failure message via <fail message="${failure.message}" />.

Why is NAnt executing my sql scripts in the wrong order?

Here is my Script:
<?xml version="1.0"?>
<project name="createAndPopulateDB" default="deploy">
<property name="sql.connstring" value="Provider=SQLOLEDB;Server=G-PC\sqlexpress;Integrated Security=SSPI" />
<property name="createDB" value="BuildTestDatabase.sql" />
<property name="populateDB" value="CreateTables.sql"/>
<target name="deploy">
<echo message="* Connecting to ${sql.connstring}"/>
<foreach item="File" property="sql.script">
<in>
<items>
<include name="${createDB}" />
<include name="${populateDB}" />
</items>
</in>
<do>
<echo message="* Executing ${path::get-file-name(sql.script)}"/>
<sql connstring="${sql.connstring}" delimiter="go" delimstyle="Line" batch="false" source="${sql.script}"/>
</do>
</foreach>
</target>
</project>
The NAnt script is supposed to call two tsql programs. The first tsql is designed to drop a database if it is present, and if it isn't, create it. The second checks to see if a table is present, and if so, delete it. Similarly if it isn't, it populates the created database with a simple table.
My question is why does it run the populateDB script first?
I found that the best way to determine the order in which the tsql programs are run is through a depends attribute attached to separate targets. This will run them in a predetermined order and is extremely easy to follow logically if the NAnt script is a part of a repository.

Using xmlpeek in Nant script gives odd error

As part of a CI process I am trying to create a buildlabel which consists of the content of an xml element within an xml structure. For this purpose I am using nant and xmlpeek. My problem is that I get an odd error stating:
"Nodeindex '0' is out of range"
This is only the case if the xml file I am xmlpeeking contains a namespace definition in the root node.
Removing the namespace from the xml file gives me the output I expect.
The nant target that generates the error can be boild down to:
<target name="TDSLabel">
<property name="element" value=""/>
<echo message="Getting element" />
<xmlpeek file="C:\xxx\test1.xml" xpath="//Project/PropertyGroup/ProductVersion" property="element"/>
<echo message="The found element value was: ${element}" />
</target>
and the test1.xml file looks like this:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProductVersion>9.0.21022</ProductVersion>
</PropertyGroup>
</Project>
You already gave the right hint yourself. It's about the namespace. This should fix it:
<target name="TDSLabel">
<property name="element" value=""/>
<echo message="Getting element" />
<xmlpeek
file="C:\xxx\test1.xml"
xpath="//x:Project/x:PropertyGroup/x:ProductVersion"
property="element"
verbose="true">
<namespaces>
<namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
</namespaces>
</xmlpeek>
<echo message="The found element value was: ${element}" />
</target>
Found a similar problem and the anwser to my problem here: XmlPoke and unique nodes. The problem was that I did not include the namespace definition within the xmlpeek element and afterwards omitted the necessary reference to the namespace in my xpath statement:
<xmlpeek file="C:\xxx\test1.xml" xpath="//x:Project/x:PropertyGroup/x:ProductVersion" property="element">
<namespaces>
<namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" />
</namespaces>
</xmlpeek>

Nant: Find file by pattern

What I am trying to do, is to find a file with NAnt. This file could by anywhere in a directory structure of a given folder.
I tried to this with the NAnt-foreach task (this works) but I am not quite convinced of that:
<target name="find-file">
<fail message="Property param.dir must be set" unless="${property::exists('param.dir')}" />
<fail message="Property param.pattern must be set" unless="${property::exists('param.pattern')}" />
<property name="return.file" value="" />
<foreach item="File" property="iterator.file">
<in>
<items>
<include name="${param.dir}\**\${param.pattern}" />
</items>
</in>
<do>
<property name="return.file" value="${iterator.file}" if="${string::get-length(return.file) == 0}" />
</do>
</foreach>
</target>
Is there anybody aware of a better approach? If not how can I accomplish to exit the foreach-loop after the first element is found?
This nantcontrib function will put the matching filenames into a delimited string..
If you know that only one matching file will exist then it may get you what you want. If there are several then you could use the nant substring function to just get the first match by taking the substring up to the first delimiter.
The following nant script:
<?xml version="1.0" encoding="utf-8"?>
<project default="find-file2">
<property name="NantContrib.dir" value="C:\Program Files\nantcontrib-0.85\" readonly="true" />
<target name="LoadNantContrib">
<loadtasks assembly="${NantContrib.dir}bin\NAnt.Contrib.Tasks.dll" />
</target>
<target name="find-file2" depends="LoadNantContrib">
<fileset id="find.set">
<include name="${param.dir}\**\${param.pattern}" />
</fileset>
<property name="return.file" value="${fileset::to-string('find.set', ' | ')}" />
<echo message="return.file=${return.file}"/>
<echo message="Found ${fileset::get-file-count('find.set')} files"/>
</target>
</project>
...and the following folder structure:
\---folderroot
+---folder1
| dontfindme.txt
| findme.txt
|
+---folder2
| dontfindme.txt
|
\---folderempty
...works as expected. Searching for findme.txt finds one file. Searching for dontfindme.txt finds two files. Searching for *.txt finds three files.
Example call:
nant -D:param.dir=folderroot -D:param.pattern=findme.txt
Example output:
find-file2:
[echo] return.file=C:\Documents and Settings\rbaker\My Documents\nantfindfile\folderroot\folder1\findme.txt
[echo] Found 1 files
BUILD SUCCEEDED