Sunday, October 18, 2009

Working with the 1.5 code base : part 5

Away with the dreaded WPF, and back to good old CCNet coding ;-)
This part will cover another updated part of the code : communication. In 1.5 Craig introduced messaging, Changing to Messages. As always Craigs blog is very informative in what and why he changes. I'll try to give a more hands-on example, so others can see more details and some code.
The problem : In CCNet 1.4.3 I exposed the breakers of a build to cctray and the dashboard. Cradiator also uses this information. Now in CCNet 1.5 Craig, yes he again, exposed also the breaking tasks, which is good. But this introduced a problem : the xml feed Cradiator uses, only exposes the last message! So this means that we show the breaker, OR the breaking tasks. (also the dashboard has this problem for the moment)
The solution is simple : expose all messages :-) This is covered in Jira Issue 1718
Anyway, this kind of information is stored in the messages arraylist on the project being integrated. When a build is ok, we clear this list, when a build is bad, we look at the modifications, and extract the user names. The same goes for the tasks that failed. All this information is just a message in this arraylist. This also is a problem on its own. A message is just a text : John Wayne Broke the build. You can not see what kind of information it is, only by parsing the text :-(

Fixing the issue :
Step 1 : add a type for each message
Currently I have these 4 types in an enum
  • NotDefined
  • Breakers
  • Fixer
  • FailingTasks
This is just adding a property with the enum to the message class

/// <summary>
/// The type of message
/// </summary>
[XmlText]
public MessageKind Kind
{
get { return messageKind; }
set { messageKind = value; }
}
Step 2 : adjusting the communication
We need to update the MessageRequest to have this new property also

/// <summary>
/// The kind of message
/// </summary>
[XmlElement("kind")]
public Message.MessageKind Kind
{
get { return kind; }
set { kind = value; }
}
Everywhere where we go from a MessageRequest to a Message we need to pass this new property value. This is in 1 place : CruiseServer.cs in public virtual Response SendMessage(MessageRequest request)
The only thing left to do is specify the value of the type when we add a message to the list. For CCTray this is the option :Volunteer to fix build, in the integration itself, we must add the correct value to the breakers and the failing tasks.

Step 3 : expose the messagelist

This is merely adding a new xml element, which is a list, nothing special.
So in XmlReportAction.cs add this element :
xmlWriter.WriteStartElement("messages");

foreach (Message m in status.Messages)
{
xmlWriter.WriteStartElement("message");
xmlWriter.WriteAttributeString("text", m.Text);
xmlWriter.WriteAttributeString("kind", m.Kind.ToString());
xmlWriter.WriteEndElement();
}

xmlWriter.WriteEndElement();


Not so hard was it ?

Stay tuned for more in the future ...

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete