Archive for June, 2007

Upgrading CruiseControl

I recently upgraded the version of CruiseControl that my team has been using from 2.2 to 2.7. I learned a few things that I haven’t really seen posted anywhere else. Most of these are common sense, but I will list them here mostly so the next time I do an upgrade I won’t forget.

  • Delete everything except for the *.ser files and the logs directory. The *.ser files are what hold the last build number for a particular project. This prevents your build number from going to back to 1 the next time it builds on the new version of CC
  • Don’t change the name of a project in the config.xml file. This will change the name of the corresponding *.ser file and will result in a build number of 1
  • You must have CVS or SVN installed and on the path in order for these commands to work within CruiseControl. This is definitely true for a Windows machine where these are less likely to be installed by default.

As I said, all common sense, but still very important to keep in mind when working with CruiseControl.

Ant – Metatargets and a build script Antipattern

A few days ago I was reading an article on the Object Mentor website entitled How To Misuse Ant. One bit of the article in particular caught my attention because it runs completely counter to the way that I have created targets in the past. The bit was about using Metatargets instead of the depends keyword.

By making lots of small targets that do one thing well, you introduce the possibility of chaining them together to do different operations. These “metatargets” allow people to use the build in ways you never anticipated. What horror! Things must be done the way you define them back when you originally wrote the script. Why would anyone have the arrogance to do it another way?

If you have to decouple into small targets, make sure you chain them all together using the depends keyword. It’s almost as good as the OneBigTarget.

To me this makes a lot of sense. However, I see a danger with this thinking; what happens when people run those small, individual targets without first running targets that they do depend on? I can’t run a test target without first compiling the tests or compiling the code or initializing the build directories, etc.

To solve this do I make all the little targets private and the Metatargets public? This to me seems like the most logical explanation. But then my mind wanders over to how communicative this is. A Test target really does depend on certain targets being run successfully before it can run. Putting in a depends attribute communicates this to people. On the other hand, it tightly couples the Test target to its dependencies and possibly prevents the test target to be run later in the build process.

One build antipattern I have definitely identified so far is, what I call, dependency chaining. By this I mean where you create a target that depends on another target which depends on another target which depends on another target and so on. In order to understand the initial target you have to trace your way through 5 or 10 targets to fully understand what the target does.

Using the idea of Metatargets should solve this problem by more explicitly showing exactly what the target does. This makes it a lot easier for a new developer to understand the intent behind a target.

Tip: How to see all available Ant targets

If you have ever had to do a build where you weren’t sure what the right target was, then this simple little tip will help. Entering the following command:

$ ant -projecthelp

or, for those who like short cuts,

$ ant -p

will display a list of all public ant targets available in the default build.xml file. I find myself using this all the time. It is a lot easier then loading the entire file into a text editor to search for the target I want.

I have to add one small caveat though to the above tip. Ant considers a public target to be one with a description. If the description attribute is missing, you will not see the target listed in the output.

Need help building complex form in Rails

I am trying to put together a somewhat complex form in Rails and am hitting a bit of a wall. Here is the general jist of what I am trying to do. I have the following objects:

[source:ruby]
class ExpenseReport
# :project
# :submitted_date
# :comments
has_many :line_items
end

class LineItem
# :amount
belongs_to :expense_report
belongs_to :expense_category
end

class ExpenseCategory
# :category
has_many :line_items
end
[/source]

What I would like to do is to create a form for the ExpenseReport that contains 5 rows of LineItems and each LineItem row would allow the user to select the ExpenseCategory.

This is what I have for the form:

[source:ruby]
< % form_for :report, :url => { :action => ‘create’} do |form| %>


< %= text_field 'report', :project, :size => 40 %>


< %= datetime_select 'report', 'submit_date' %>

Report Line Item

< % fields_for :line_items do |line_item_form| %>
< % @line_items.each_with_index do |line_item, index| %>

< % fields_for :expense_categories do |expense_category| %>
< %= expense_category.collection_select(:id, @expense_category, :id, :name) %>
< % end %>

< %= text_field :line_item_form, :amount, :index => index %>
< % end %>
< % end %>


< %= text_area 'report', 'comments', :rows => 5, :cols => 60 %>
< %= submit_tag "Create" %>

< % end %>
[/source]

I am getting two errors when I do this, first is when I go to retrieve the line_items from the params, I am getting a ‘nil object’ error and second, I only get one instance of the report_category being returned in the params instead of 5 (I create an array of 5 new LineItems for the @line_items collection.

If anyone has any hints, tricks, suggestions, or comments, please leave them in the comments sections or email via my contact page. Unfortunately, the Agile Web Development with Rails books only has simple examples and nothing that uses two or three model objects.

Installed Parallels 3.0 on Macbook Pro

I just installed the newest version of Parallels on my Macbook Pro and can’t wait to install Quake and see how it runs. I am not sure the graphics card is up to playing it full screen on my new 24″ monitor though.

Update: Quake 3 runs great. I had a few problems with getting the screen size correct, but once that was sorted out, the game ran fine. I ran it at a resolution of 1024×768. I’m not sure I would want to run it any larger then that.