Archive

Posts Tagged ‘Fun’

CruiseControl.NET and F#

8 April, 2010 1 comment

I’ve been writing some documentation on building plug-ins and recently I expanded it to include some Visual Basic examples. That got me thinking, what other languages can we build plug-ins in? So I thought I’d give it a quick try in one of the new fangled languages that people are raving about – F#.

Here is a basic hello world task written in F#:

namespace CCNet.FSharpDemos.Plugin.Tasks

open Exortech.NetReflector
open ThoughtWorks.CruiseControl.Core
open ThoughtWorks.CruiseControl.Core.Config
open ThoughtWorks.CruiseControl.Core.Util
open ThoughtWorks.CruiseControl.Remote

[<ReflectorType("fsHelloWorld")>]
type HelloWorldTask() = 
    let mutable myName = ""
    let mutable myCount = 1
    [<ReflectorProperty("name")>]
    member x.Name 
        with get() = myName
        and set(value) = myName <- value
    [<ReflectorProperty("count", Required = false)>]
    member x.Count
        with get() = myCount
        and set(value) = myCount <- value
    interface ITask with
        member this.Run(result) =
            result.BuildProgressInformation.SignalStartRunTask("Sending a hello world greeting")
            for i = 1 to myCount do
                let msg = "Hello " + myName + " from " + result.ProjectName + "(build started " + result.StartTime.ToString() + ")"
                result.AddTaskResult msg
            result.Status <- IntegrationStatus.Success
    interface IConfigurationValidation with
        member this.Validate(configuration, parent, errorProcesser) =
            if myCount < 1 then
                errorProcesser.ProcessWarning "count is less than 1!"

This is based on my stumbling around the F# documentation, so I’m not sure if there is a better way, but it does show how easy it is to build plug-ins in other languages than just C#.

Categories: CruiseControl.Net Tags:
Follow

Get every new post delivered to your Inbox.