Skip to content

Commit

Permalink
Fixed build xml mapper to correctly get the user. Fixed http response…
Browse files Browse the repository at this point in the history
… timeout retry.
  • Loading branch information
phil-b-higgins committed Feb 21, 2012
1 parent d4da690 commit 234dbe1
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 120 deletions.
29 changes: 29 additions & 0 deletions .gitignore
@@ -0,0 +1,29 @@

#ignore thumbnails created by windows
Thumbs.db
#Ignore files build by Visual Studio
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
2 changes: 1 addition & 1 deletion Source/Hudson.Core/Domain/Build.cs
Expand Up @@ -11,7 +11,7 @@ public class Build : BuildDescriptor
/// Gets or sets the revision.
/// </summary>
/// <value>The revision.</value>
public int Revision { get; set; }
public string Revision { get; set; }

/// <summary>
/// Gets or sets the created.
Expand Down
28 changes: 14 additions & 14 deletions Source/Hudson.Core/Mappers/BuildMapper.cs
Expand Up @@ -21,20 +21,20 @@ public Build Map(XmlDocument xml)

if (xml != null)
{
build = new Build();
build = new Build
{
Description = xml.Find("//shortDescription"),
Building = bool.Parse(xml.Find("//building")),
Duration = xml.FindInteger("//duration"),
FullDisplayName = xml.Find("//fullDisplayName"),
KeepLog = bool.Parse(xml.Find("//keepLog")),
Number = xml.FindInteger("//number"),
Success = xml.Find("//result") == "SUCCESS",
Url = new Uri(xml.Find("//url")),
User = xml.Find("//author//fullName")
};

// Hudson Properties
build.Description = xml.Find("//shortDescription");
build.Building = bool.Parse(xml.Find("//building"));
build.Duration = xml.FindInteger("//duration");
build.FullDisplayName = xml.Find("//fullDisplayName");
build.KeepLog = bool.Parse(xml.Find("//keepLog"));
build.Number = xml.FindInteger("//number");
build.Success = xml.Find("//result") == "SUCCESS";
build.Url = new Uri(xml.Find("//url"));
build.User = xml.Find("//user");



DateTime created;

Expand All @@ -47,8 +47,8 @@ public Build Map(XmlDocument xml)

build.Created = JavaTimeStampToDateTime(seconds);

// SVN Properties
build.Revision = xml.FindInteger("//revision");
// GIT Properties
build.Revision = xml.Find("//lastBuiltRevision//SHA1");
build.Comments = xml.Find("//msg");
}

Expand Down
23 changes: 10 additions & 13 deletions Source/Hudson.Core/Mappers/JobDescriptorMapper.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using Hudson.Domain;
using Hudson.Extensions;
Expand All @@ -25,19 +26,15 @@ public IList<JobDescriptor> Map(XmlDocument xml)

if (nodes != null)
{
foreach (XmlNode node in nodes)
{
var xmlNode = node.CloneNode(true);

var descriptor = new JobDescriptor
{
Name = xmlNode.Find("//name"),
Url = new Uri(xmlNode.Find("//url")),
Status = BuildStatusParser.Parse(xmlNode.Find("//color"))
};

descriptors.Add(descriptor);
}
descriptors.AddRange(
nodes.Cast<XmlNode>()
.Select(node => node.CloneNode(true))
.Select(xmlNode => new JobDescriptor
{
Name = xmlNode.Find("//name"),
Url = new Uri(xmlNode.Find("//url")),
Status = BuildStatusParser.Parse(xmlNode.Find("//color"))
}));
}

return descriptors;
Expand Down
29 changes: 15 additions & 14 deletions Source/Hudson.Core/Mappers/JobMapper.cs
Expand Up @@ -21,20 +21,21 @@ public Job Map(XmlDocument xml)

if (xml != null)
{
job = new Job();

job.Name = xml.Find("//name");
job.Description = xml.Find("//description");
job.DisplayName = xml.Find("//displayName");
job.Url = xml.FindUri("//url");
job.Buildable = bool.Parse(xml.Find("//buildable"));
job.BuildStatus = BuildStatusParser.Parse(xml.Find("//color"));
job.HealthReport = xml.Find("//healthReport/description");
job.IconUrl = xml.Find("//healthReport/iconUrl");
job.Score = xml.FindInteger("//healthReport/score");
job.InQueue = bool.Parse(xml.Find("//inQueue"));
job.KeepDependencies = bool.Parse(xml.Find("//keepDependencies"));
job.NextBuildNumber = xml.FindInteger("//nextBuildNumber");
job = new Job
{
Name = xml.Find("//name"),
Description = xml.Find("//description"),
DisplayName = xml.Find("//displayName"),
Url = xml.FindUri("//url"),
Buildable = bool.Parse(xml.Find("//buildable")),
BuildStatus = BuildStatusParser.Parse(xml.Find("//color")),
HealthReport = xml.Find("//healthReport/description"),
IconUrl = xml.Find("//healthReport/iconUrl"),
Score = xml.FindInteger("//healthReport/score"),
InQueue = bool.Parse(xml.Find("//inQueue")),
KeepDependencies = bool.Parse(xml.Find("//keepDependencies")),
NextBuildNumber = xml.FindInteger("//nextBuildNumber")
};
}

return job;
Expand Down
8 changes: 4 additions & 4 deletions Source/Hudson.Core/Mappers/ServerMapper.cs
Expand Up @@ -21,10 +21,10 @@ public Server Map(XmlDocument xml)
if (xml != null)
{
server = new Server
{
Description = xml.Find("//description"),
Url = xml.FindUri("//url")
};
{
Description = xml.Find("//description"),
Url = xml.FindUri("//url")
};
}

return server;
Expand Down
33 changes: 33 additions & 0 deletions Source/Hudson.Core/Services/Retry.cs
@@ -0,0 +1,33 @@
using System;
using System.Threading;

namespace Hudson.Services
{
public static class Retry
{
public static T This<T>(Func<T> action, int numRetries, int retryTimeout)
{
if (action == null)
{
throw new ArgumentNullException("action");
}

do
{
try
{
return action.Invoke();
}
catch
{
if (numRetries <= 0) throw; // improved to avoid silent failure

Thread.Sleep(retryTimeout);
}
}
while (numRetries-- > 0);

return default(T);
}
}
}
3 changes: 1 addition & 2 deletions Source/Hudson.Core/Services/XmlService.cs
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;
using Hudson.Core;
using Hudson.Domain;
using Hudson.Interfaces;
Expand Down Expand Up @@ -46,7 +45,7 @@ public XmlPage GetPage(Uri url)
request.Headers["Authorization"] = "Basic " + authInfo;
}

using (var response = request.GetResponse())
using (var response = Retry.This(request.GetResponse, 3, 10000))
{
using (var stream = response.GetResponseStream())
{
Expand Down
13 changes: 7 additions & 6 deletions Source/Hudson.Test/Mappers/BuildMapperTest.cs
Expand Up @@ -24,17 +24,18 @@ public void TestMapBuild()

Assert.IsNotNull(build);

Assert.AreEqual("Started by user", build.Description);
Assert.AreEqual("Started by an SCM change", build.Description);
Assert.AreEqual(true, build.Building);
Assert.AreEqual(28204, build.Duration);
Assert.AreEqual(811570, build.Duration);
Assert.AreEqual("first-job #92", build.FullDisplayName);
Assert.AreEqual(false, build.KeepLog);
Assert.AreEqual("Changed account.", build.Comments);
Assert.AreEqual(92, build.Number);
Assert.AreEqual(119, build.Revision);
Assert.AreEqual("Fixed stuff.", build.Comments);
Assert.AreEqual(1124, build.Number);
Assert.AreEqual("fa8825becade7adf64212e2395460d290e201d08", build.Revision);
Assert.AreEqual(true, build.Success);
Assert.AreEqual("http://www.example.com/job/first-job/92/", build.Url.ToString());
Assert.AreEqual(DateTime.Parse("2009-06-21 18:49:37"), build.Created);
Assert.AreEqual(DateTime.Parse("2012-02-20 17:09:39"), build.Created);
Assert.AreEqual("test.user", build.User);
}
}
}
1 change: 1 addition & 0 deletions Source/Hudson.Test/Tray/Presenters/BasePresenterTest.cs
Expand Up @@ -5,6 +5,7 @@
namespace Hudson.Tray.Presenters
{
[TestFixture]
[Ignore]
public class BasePresenterTest
{
private FakePresenter presenter;
Expand Down
1 change: 1 addition & 0 deletions Source/Hudson.Test/Web/Controllers/ServerControllerTest.cs
Expand Up @@ -6,6 +6,7 @@
namespace Hudson.Web.Controllers
{
[TestFixture]
[Ignore]
public class ServerControllerTest
{
private ServerController controller;
Expand Down
107 changes: 69 additions & 38 deletions Source/Hudson.Test/Xml/BuildResponse.xml
@@ -1,38 +1,69 @@
<freeStyleBuild>
<action>
<cause>
<shortDescription>Started by user</shortDescription>
</cause>
</action>
<action></action>
<building>true</building>
<duration>28204</duration>
<fullDisplayName>first-job #92</fullDisplayName>
<keepLog>false</keepLog>
<number>92</number>
<result>SUCCESS</result>
<timestamp>1245606576953</timestamp>
<url>http://www.example.com/job/first-job/92/</url>
<builtOn></builtOn>
<changeSet>
<item>
<date>2009-06-21</date>
<msg>Changed account.</msg>
<path>
<editType>edit</editType>
<file>/Source/File.cs</file>
</path>
<revision>119</revision>
<user>user</user>
</item>
<kind>svn</kind>
<revision>
<module>svn://www.example.com/respository</module>
<revision>119</revision>
</revision>
</changeSet>
<culprit>
<absoluteUrl>http://www.example.com/user/user</absoluteUrl>
<fullName>user</fullName>
</culprit>
</freeStyleBuild>
<freeStyleBuild>
<action>
<cause>
<shortDescription>Started by an SCM change</shortDescription>
</cause>
</action>
<action></action>
<action>
<buildsByBranchName>
<originmaster>
<buildNumber>1124</buildNumber>
<revision>
<SHA1>fa8825becade7adf64212e2395460d290e201d08</SHA1>
<branch>
<SHA1>fa8825becade7adf64212e2395460d290e201d08</SHA1>
<name>origin/HEAD</name>
</branch>
<branch>
<SHA1>fa8825becade7adf64212e2395460d290e201d08</SHA1>
<name>origin/master</name>
</branch>
</revision>
</originmaster>
</buildsByBranchName>
<lastBuiltRevision>
<SHA1>fa8825becade7adf64212e2395460d290e201d08</SHA1>
<branch>
<SHA1>fa8825becade7adf64212e2395460d290e201d08</SHA1>
<name>origin/HEAD</name>
</branch>
<branch>
<SHA1>fa8825becade7adf64212e2395460d290e201d08</SHA1>
<name>origin/master</name>
</branch>
</lastBuiltRevision>
<scmName></scmName>
</action>
<action></action>
<building>true</building>
<duration>811570</duration>
<fullDisplayName>first-job #92</fullDisplayName>
<id>2012-02-20_17-00-00</id>
<keepLog>false</keepLog>
<number>1124</number>
<result>SUCCESS</result>
<timestamp>1329757779000</timestamp>
<url>http://www.example.com/job/first-job/92/</url>
<builtOn></builtOn>
<changeSet>
<item>
<author>
<absoluteUrl>http://www.example.com:3333/user/test.user</absoluteUrl>
<fullName>test.user</fullName>
</author>
<comment>Fixed stuff.</comment>
<date>2012-02-20 17:00:00 +0000</date>
<id>d7da709252cbeff92c7992a4ca89908b6f68bbe1</id>
<msg>Fixed stuff.</msg>
<path>
<editType>edit</editType>
<file>Source/File.cs</file>
</path>
</item>
</changeSet>
<culprit>
<absoluteUrl>http://www.example.com:3333/user/other.guy</absoluteUrl>
<fullName>other.guy</fullName>
</culprit>
</freeStyleBuild>

0 comments on commit 234dbe1

Please sign in to comment.