I have implemented a custom script task for NAnt which makes progress 
reporting back to CCNet much easier.  Progress reporting is accomplished 
by inserting XML into a file which is read by CCNet to display progress 
information.  See 
http://confluence.public.thoughtworks.org/display/CCNETCOMM/Viewing+build+progress+with+Nant+and+MSBuild
 
for official details.

I am attaching the script for anyone to use.  What I do is:

1) save the contents of the script below in a file named CCNet-progress.xml
2) include the new file in any NAnt script which will want to utilize it 
like:

    <include buildfile="CCnet-progress.xml"/>

3) call the progress reporter when you want to update the progress of 
your task, like this:

    <CCnet-progress message="Beginning the web site clean-up" 
file="${CCNetListenerFile}"/>

and that's it.  I usually do a little more, like set a true/false 
variable like this:

    <property name="progress.logging" value="false"/>
    <property name="progress.logging" value="true" 
if="${property::exists('CCNetListenerFile')}"/>

and then my actual progress logging calls look like:

    <CCnet-progress message="Beginning the web site clean-up" 
file="${CCNetListenerFile}" if="${progress.logging}"/>

This allows my NAnt scripts to continue working when I am using them 
outside of CCNet.

Here's the file:

======================================================================
<?xml version="1.0" encoding="utf-8"?>
<project name="CCNet-extensions">
    <script language="C#">
        <references>
            <include name="System.Xml.dll"/>
        </references>
        <imports>
            <import namespace="System.Xml"/>
        </imports>
        <code><![CDATA[
   
            [TaskName("CCNet-progress")]
            public class TestTask : Task
            {
                #region Private Instance Fields
                private string _message;
                private string _file;
                #endregion Private Instance Fields
               
                #region Public Instance Properties
                [TaskAttribute("message", Required=true)]
                [StringValidator(AllowEmpty=false)]
                public string Message
                {
                    get { return _message; }
                    set { _message = value; }
                }
                [TaskAttribute("file", Required=true)]
                [StringValidator(AllowEmpty=false)]
                public string FileName
                {
                    get { return _file; }
                    set { _file = value; }
                }
                #endregion Public Instance Properties
               
                #region Override implementation of Task
   
                protected override void ExecuteTask()
                {
                    XmlDocument progressXML = new XmlDocument();
                    if (File.Exists(_file))
                    {
                        progressXML.Load (_file);
                    }
                    else
                    {
                        XmlElement newDE = 
progressXML.CreateElement("data");
                        progressXML.AppendChild (newDE);
                    }
                    XmlElement newNode = progressXML.CreateElement ("Item");
                    newNode.SetAttribute ("Time", DateTime.Now.ToString ());
                    newNode.SetAttribute ("Data", _message);
                    progressXML.DocumentElement.AppendChild (newNode);
                    progressXML.Save (_file);
                }
   
                #endregion Override implementation of Task
            }
   
        ]]></code>
    </script>
</project>
==============================================================

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to