Monday, June 16, 2008

How to call Rake from CruiseControl.Net

CruiseControl.Net is a great Continuous Integration tool. It is easier to setup than CruiseControl (java). Plus it makes more sense to use CC.Net if you work at a .Net shop.

To script the Continuous Integration process, I first investigated using MSBuild. At this time, I found MSBuild to work well for building Visual Studio projects. But MSBuild wasn't mature enough to accomplish much else. NAnt is a more mature alternative to MSBuild, which I've used on some projects. NAnt is fairly powerful (even better in my opinion than the original Ant). However, there is one problem with both these tools: XML is not a programming language.

Rake is a programming language. Rake is actually Ruby, with some additional stuff to give it the powers of Make. Rake also makes sense in a .Net shop because 1) Ruby can call .Net objects using the Ruby/.Net Bridge. 2) John Lam is currently porting Ruby to run directly on the .Net DLR.

So how do you get CruiseControl.Net to call Rake? The best solution would be to create a CC.Net plugin to call Rake. But if your like me, time is limited. So an easy kludge will suffice. The kludge is this: 1) CC.Net calls either MSBuild or NAnt, which is already built in. 2) MSBuild or NAnt executes Rake via an Exec task.

(You may be wondering why not use CC.Net exec task. The short answer, I couldn't get CC.Net exec task to call Rake. I'm not sure why. It just didn't work well.)

First - CC.Net calls MSBuild or NAnt. This is very simple. In the CC.Net config file you add a task...

   <tasks>
<nant buildFile="nant.xml" />
</tasks>



or

   <tasks>
<msbuild projectFile="msbuild.xml" />
</tasks>


Then you have NAnt or MSBuild call Rake. Here are the nant.xml and msbuild.xml files:

<?xml version="1.0"?>
<project name="Rake Runner" default="RakeBuild" basedir=".">
<target name="RakeBuild">
<exec program="c:\ruby\bin\rake.bat" />
</target>
</project>



<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="RakeBuild">
<Target Name="RakeBuild">
<Exec Command="rake" />
</Target>
</Project>



Notice that each just calls the RakeBuild target, which is the default target.

Rake will then run the default target (you could specify a Rake task in the scripts above). Here is an example Rake script which displays all the environment variables:


task :default => [:test]

task :test do
ENV.each {|k,v| puts "#{k}=#{v}" }
end



CC.Net captures the output a little different for MSBuild vs NAnt. MSBuild's output is append to the end of the build log. Which results in a long build log. NAnt's output is captured to a different page "NAnt Output". However, NAnt prepends each line with "[exec]".

Sunday, May 11, 2008

Twitter fun

Last Friday I attend the IPSA meeting on Social Media. That got me interested in two products: Twitter and ooVoo.

I've now got a Twitter account using the nickname neversleep360. For which I got curious about the reach of Twitter. So I wrote a quick ruby script to search out Friends and Friends of Friends, then score everything they were following based on the number of Friends/FriendsX2 following. This should point out nicks of common interest. Also, I found several interesting nicks sitting out in the wings.

I've posted everything on my wiki at Twitter Friends of Friends. One interesting result is the number of links to BarackObama. Personally I'm not a fan of BarackObama; but it is interesting to see him score highly among this circle of friends on Twitter.

Tuesday, February 19, 2008

Unexpected Hash Behavior With String Keys

I was looking for a way to create a case-insensitive Hash class. One suggestion was to use NormalizedHash (http://pastie.caboo.se/154304), and override methods on the String keys. This doesn't work as expected.

I found that Hash makes a duplicate of the String key. This unfortunately removes any methods added in the singleton class. (surprise!)

Here is the code to demonstrate this behavior: http://pastie.caboo.se/154595

----

Shortly after writing the above post, I came across a little footnote in Hash#[]= which says... "(a String passed as a key will be duplicated and frozen)"

I learn something new every day. (I wish this information was given in the class description instead of the method description where it is easly missed.)

Monday, September 17, 2007

My SQL Server 2005 is Slow

Testing code that queries SQL Server 2005, I kept observing long delays. Sometimes my tests would execute in less than one second, which was expected. Frequently, they would take 30 to 120 seconds!

A little digging into the SQL Server, I found the two top waits were SQLTRACE_BUFFER_FLUSH and RESOURCE_SEMAPHORE, both of which would grow in correlation to delays I observed when running my unit tests.

A little reading found: this forum topic and this kb article. The former being the most useful. It turns out SQL 2005 will run a trace by default; to assist in fixing problems later. (read "default trace enabled" in SQL Books Online) Unfortunately on my development box, it appears the trace is the source of my delays. So my solution is to turn off the default trace using:

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'default trace enabled',0
reconfigure


After this, my tests always ran in less than one second!