Adding a Block Comment Keybinding to the ANT editor in Eclipse

Friday, December 2, 2011

If you’re like me, you keep your hands off the mouse and know your IDE intimately. You use shortcuts (keybindings) whenever possible, and if you find yourself reaching for the mouse, you stop and you try to find the shortcut.

Turns out, Eclipse’s ANT editor doesn’t seem to have a keybinding for inserting block comments (<!-- -->). Fortunately, if your Eclipse install has a plugin such as the WTP HTML editor  or ColdFusion Builder which includes a “Insert Block Comment” action, then you can easily bind that editor’s action to the ANT editor, thereby getting block comment insertion in ANT build files with a keyboard shortcut. Here’s how:

Binding a Block Comment to a keyboard shortcut

  1. Window – Preferences
  2. Filter on “keys” to get to the keybinding property sheet
  3. In the keybinding sheet, type “html comment” in the filter
  4. If your editor supports it, one or more  rows will appear. Highlight one of them.
  5. Click “Copy Command”
  6. In the copied command, down in the “Binding” field, type a keystroke you want to use. I like ctrl+shift+M
  7. In the “When” dropdown, select “Editing Ant Buildfiles”
  8. Click “OK” and get out of all that.


Now, when editing an ANT file, you can use your shortcut to insert block comments.


MXUnit 2.1 Released

Saturday, November 12, 2011

We’re pleased to announce the release of MXUnit version 2.1, comprising contributions from long-time MXUnit developers and new contributors alike.

This version includes:

Test Decorators

Without doubt the most significant feature in this release is “Test Decorators”, largely contributed by Mark Mandel. Decorators let you change MXUnit’s default behavior by writing a bit of your own code, without having to change MXUnit’s internals. We’ll be bringing you more documentation on this soon, but in the meantime, some problems this will solve are:

  • --Being selective in which tests get run on which platforms
  • --Controlling the sort order of tests
  • --Adding auto-rollback functionality to tests which commit data to databases
  • --Controlling which functions in a TestCase get ignored
  • --Enabling you to use custom attributes on tests, and respond to those attributes in your decorators
  • And so on

The mechanics are thus:

  1. Write a new component which extends mxunit.framework.TestDecorator
  2. Override any of the functions in the base TestDecorator to achieve the functionality you desire
  3. Add that decorator to your testcase, like so: <cfcomponent mxunit:decorators=”My.Custom.Decorator”…>
  4. Optionally, use custom function attributes and respond to them: <cfset var someAttribute = getAnnotation(methodName, "myCoolAttribute")/>

See MXUnit’s built-in decorators for examples and ideas.

Array, Query, and Structure Comparisons

Another significant change is how MXUnit compares arrays, queries, and structs in equality assertions. Up till now, these were done via turning those datatypes into strings and doing string comparisons.

With MXUnit 2.1, you’ll get a full comparison of these datatypes. When mismatches occur, you’ll be able to see the full set of mismatches in both the Eclipse plugin and when running tests via the browser. When running from the plugin, you can either use the Compare Dialog to see the differences, or use MXUnit’s “debug” output to view a structure which explains all the differences. They look thusly:




This is a first stab at deep comparisons, and we expect that as you use them, you’ll identify areas for improvement. We always welcome patches and pull requests. It goes without saying that accompanying tests are required.


Test Ordering

Thanks to Ryan Anklam for contributing a long-overdue feature. Until now, test ordering was unpredictable. Ryan’s contribution will order tests in the order in which ColdFusion’s getMetadata() reports them. While still not deterministic – getMetadata() will not order tests exactly in the order they appear in the TestCase – it’s a welcome improvement over the current behavior.

In addition, with TestDecorators, it’s easy to get alphabetical ordering if you wish, since MXUnit ships with an Alphabetical ordering test decorator. See this example test for how to use it.

Special thanks to Tim and John Farrar for the conversations inspiring the TestDecorator feature, and to all who contributed bug reports, patches, and feature code to this release.



CI with Jenkins, ANT, and MXUnit Presentation Materials from cf.Objective() 2011

Saturday, May 14, 2011

This year, I spoke at cf.Objective() on how to use the Jenkins Continuous Integration server for your ColdFusion projects. Slides and all code are available.

Test and be happy.


ORM Zen Presentation Materials from cf.Objective() 2011

At cf.Objective() 2011 I presented my story, in code, from suffering to (sort-of) ORM enlightenment. Slides, Code, etc are all available.

Thanks to all attendees!


Jenkins / Hudson Continuous Integration documentation now on the MXUnit Wiki

Saturday, April 2, 2011

Quite a while back, I wrote a series of blog posts detailing how to set up Continuous Integration with Hudson, ANT, and MXUnit for your ColdFusion projects. That documentation has now been updated for Jenkins and brought into the MXUnit Wiki.


MXUnit Eclipse Plugin 1.4.1 Released

Wednesday, March 23, 2011

Thanks again to Denny Valliant for the latest updates to the MXUnit Eclipse plugin. This release includes two important features:

  • “Run as MXUnit Test” is now added to the “Run As” menu. This includes keybinding support, so you can now run your tests from keys. The default binding, following the Eclipse pattern, is Alt+Shift+X, M. You can change this to something more finger friendly in preferences.
  • Until now, when a test fails and shows you the list of files in the tag context, those files would only be openable if they existed in projects. No more. The plugin now supports opening the files from the file system if they are not in a project.

As always, the update site is at Enjoy… And please thank Denny when you pass him in the halls!

The Lazarus effect: Raising a ColdFusion server from the dead with 1 simple code change

Tuesday, February 22, 2011

My coworker (and all around good egg) Scott Stroz and I hit an interesting memory problem recently in one of our applications. The fix, and our story, is now documented, with pretty pictures.



Hashing passwords with bcrypt in ColdFusion

Sunday, February 20, 2011

Why bcrypt?

I’ve been thinking more about security lately; specifically, password safety. For a fine explanation of why you want to hash passwords instead of storing them plaintext, read Billy’s post from a while back. He’s got a good list of references as well, including NIST’s approved hashing algorithms. In addition, check out OWASP’s thorough treatment.

Now, then…

This weekend I re-read Coda Hale’s admonition about why MD5, SHA512, etc aren’t the right choice for a hashing algorithm. His point: use bcrypt, which “uses a variant of the Blowfish encryption algorithm’s keying schedule, and introduces a work factor, which allows you to determine how expensive the hash function will be” (Coda Hale’s words).

As of this writing, bcrypt does not ship with ColdFusion. Fortunately, it’s quite easy to use within CF. One thing that quite appeals to me about bcrypt is that the salt is essentially stored with the hash, and so you don’t need to store/use/remember the salt used to hash a password. Think about that.

What does it look like in ColdFusion?

In code, it means you can hash and check a password as easily as this:

//hash it
pw = "happy1.!gIlm0re";
hashed = bcrypt.hashpw(pw, bcrypt.gensalt());
//check it
match = bcrypt.checkpw(pw, hashed);

Compare that with any password hashing code you've written before. I bet it's simpler and at the same time more secure.

What’s the catch? Time… in my tests, with the default “work load”, it takes about 200-300 ms to hash and check a single password. This is also, not ironically, why it’s such an effective technique for hashing passwords, as Coda Hale describes.

How to set it up

Here’s how to do it in ColdFusion:

  1. Go to the jbCrypt homepage. Here you’ll see usage instructions as well as download links.
  2. Download jBcrypt, written by Damien Miller
  3. unzip and drop the folder into your project
  4. compile the .java into a .class file using the JDK
    1. OR download the class file, if you’re not familiar with compiling Java
  5. either put that class file into your CF’s classes directory and restart, or you can use javaloader. The code below uses javaloader

Using javaloader, you’ll do the following. I’m leaving my timers in here so you can easily compare the difference between the default workload and a higher workload of, say, 12.

pw = "happy1.!gIlm0re";

jbClass = expandPath("jBCrypt-0.3");
javaloader = createObject('component','javaloader.javaloader');

bcrypt = javaloader.create("BCrypt");
startts = getTickCount();
hashed = bcrypt.hashpw(pw, bcrypt.gensalt());
writeoutput("created pw " & hashed & " in " & getTickCount()  - startts & " ms <br>");

startts = getTickCount();
match = bcrypt.checkpw(pw, hashed);
writeoutput("checked pw match (#match#) in " & getTickCount()  - startts & " ms <br>");

startts = getTickCount();
hashed = bcrypt.hashpw(pw, bcrypt.gensalt(12));
writeoutput("created pw " & hashed & " in " & getTickCount()  - startts & " ms <br>");

startts = getTickCount();
match = bcrypt.checkpw(pw, hashed);
writeoutput("checked pw match (#match#) in " & getTickCount()  - startts & " ms <br>");

Using the code below, here’s sample output:



The ability to hash and check passwords without having to manage salts, combined with the high degree of difficulty it would require to actually crack a bcrypted password, makes this an appealing solution for me. The fact that it’s so easy to use in ColdFusion is gravy.

ColdFusion ORM: cascade=all-delete-orphan behavior differs depending on relationship type

Thursday, February 10, 2011

Long title, I know. Short post.

Executive Summary

I thought that you needed cascade=”all-delete-orphan” any time you wanted to ensure an element in a one-to-many property was removed from the join table. For example, blog.removeComment( comment ) should remove the row from BlogComments. Turns out, it’s not always required.

I still think you should use it all the time, however.

This is one of those “I learned something new but it doesn’t change anything” type of posts.

all-delete-orphan and LinkTable

When removing elements from a one-to-many collection, you typically specify cascade=”all-delete-orphan” on that property. Then, when you remove the item and re-save the entity, it’ll remove that item from the join table. Here’s an example, using a typical “linktable”, which you use when you have a simple 2-key join table. Given an entity named “Event.cfc”, with a property named “attendees” which maps to an Attendee.cfc:

property name="attendees" fieldtype="one-to-many" cfc="Attendee"

With a relationship like this, if you call event.removeAttendee( someAttendee ), then ORM will remove the link from that linktable for you, thanks to the cascade.

Here’s what I learned… cascade=”all-delete-orphan” doesn’t matter in the case of a simple linktable. If you set it to cascade=”all”, it’ll do exactly what you want.

all-delete-orphan and intermediary entity

BUT: it absolutely matters when you have a property that is not a simple link table but is instead an entity in itself, representing a link in addition to other data.

Consider this… an Event entity mapping to an “EventComment” entity. EventComment comprises more than a simple “eventid,commentid” relationship; instead, it has a comment string, and also an Attendee and a date and who knows what else. These “joins with additional data” are more common than simple joins in my experience, if for no other reason than everyone seems to *need* CreatedBy, CreatedOn, ModifiedBy, and ModifiedOn fields even though you never use them.

That mapping looks like:

property name="eventComments" fieldtype="one-to-many" cfc="EventComment"


Now check this out. If you call event.removeEventComment( someComment ), it’ll remove it from EventComment’s table as expected. But unlike the earlier example, if you change it to cascade=”all”, it will not behave the same way. In fact, the behavior I observed, using MySQL, is this:

  1. The element is removed from Event’s array of EventComments
  2. refetching the object in the same request (i.e. entityLoadByPK( “Event”, event.getId() ); returns an object without that EventComment… even if you have FlushAtRequestEnd=false, and AutomanageSession=false, and perform the entitySave() in a transaction (suck it, Hibernate Session Object)
  3. The EventComment is not in fact deleted. If you refetch in another request or check it out in the query browser, it’s still there.

Bottom line: no deletion, though it *looks* like it’s deleted. These ORM headfakes’ll drive a dude to drink (More).

This is perhaps completely obvious that it should behave this way. I so rarely work with 2-column join tables, and while futzing about tonight with some examples I stumbled onto this difference in behavior accidentally.

My Takeaway

You don’t need all-delete-orphan when working with simply a linktable. However, I strongly suggest using it, since it doesn’t cause damage and more clearly expresses intent. And in the event that your simple join turns into a multi-column affair requiring an intermediary entity, you save yourself one fewer “now why in the hell isn’t this deleting anymore?” moment.



Editing xml and xml.cfm files in a better Eclipse XML Editor

Friday, February 4, 2011

Lately, the frameworks I’ve been using  have been configured with XML files – ColdSpring, ModelGlue, and ValidateThis. If you’re coding XML, and use either the basic XML editor in Eclipse or the Aptana XML editor in ColdFusion Builder, you’re potentially missing out on some slick code completion offered by another Eclipse plugin… the  WebTools project, which contains my free XML Editor of choice.

To Install:

Use the normal “Help -- Install new software” process in Eclipse, using as the update site.

What’s it get me?

The WTP XML editor has two must-have features:

  1. It “learns” your XML and begins providing code assist after it knows what elements are in your files
  2. If your XML file contains a schema declaration, it’ll provide very rich code assist for both elements and attributes

Check it:


This is me editing a ModelGlue xml config file. Note that the file has this attribute on the modelglue element: xsi:noNamespaceSchemaLocation=""

Yes, that’s a valid URL.

This means that if your framework of choice makes an XSD schema available, then you can add the appropriate URI to your XML file and voila, the editor will start providing code assist.

One other small-but-useful feature is automatic element shorthand. Let me explain:

Imagine you type this: <param name=”regex” value=”(?i)password”></param>

Or, rather, imagine the editor auto-closed that tag. Now, if you put your cursor right after password” and before the closing angle bracket, and enter the backslash, the editor will automatically remove the closing element. Small, but the little things in life matter.

How do I edit XML files with a CFM Extension?

A best practice for the XML files is to suffix them with a .cfm extension, i.e. ModelGlue.xml.cfm if those files are web-accessible. This way, you can put an Application.cfm in that directory, with a CFABORT, and those xml config files are no longer readable (assuming you don’t lock them down with your webserver). The problem here is that once they have a .cfm extension, they don’t play nicely with the XML editor.

Fortunately, this is an easy fix.

  1. Open the Eclipse preferences
  2. Filter on “content type”
  3. Scroll down, expand “text”, then go to “XML“
  4. In the bottom pane, click “Add” and then type “.cfm”. Click OK till finished.

Here’s what that looks like:



That’s step 1. Step 2 is actually opening a .cfm file in the WTP XML Editor.

  1. Right click on your .xml.cfm file
  2. Select “Open With”
  3. If '”XML Editor” is an option, choose it. Otherwise, click the “Other” and scroll down till you see the XML editor. It’ll be at the bottom. Note this is not the “Aptana XML Editor”

That dialog looks like this:


This is  a one time thing! Once you open a particular .xml.cfm file in the XML editor, it’ll always open in that editor until you instruct it otherwise.


How does Eclipse know that your .xml.cfm is an XML content type?

You may have a .xml.cfm file that, when you open with the xml editor via right click – open with, continues to give you the “invalid content type” popup. This is most likely because the file does not have the xml declaration at the top. For example, if you have a Coldspring beans.xml.cfm file and it starts with <beans>, you’ll probably get this error. The fix is to add <?xml version="1.0" encoding="UTF-8"?>  to the top of your file.


If you want code assist on your XML files, both .xml and .xml.cfm, then take 5 minutes to install the WTP XML Editor. Give it a go, and see if it’s right for you.

Immutable Objects in ColdFusion

Tuesday, February 1, 2011

This piece will briefly discuss concepts of immutability--what it is, why you should care, and how you can implement immutability in ColdFusion. Immutability is also an important piece in functional programming, which is very appealing from a testing perspective--I’ll touch on that towards the end.

What are immutable objects?

Simply stated, once an immutable object is created you can’t change it. There are typically no setter methods or public instance members, and the constructors are strictly controlled. The results are immutable objects. A factory method can also be used to generate or build immutable objects.


If this concept seems strange, consider these ideas:
  1. If an object’s state doesn’t change, it makes testing much easier.
    • You test the state of the object only after it’s been created. You’re not as focused on testing methods that alter the state of the object, simply because they don’t exist.
  2. Immutable objects are inherently thread safe. [BLOCH]
    • Since no thread can change it’s state, all threads read the exact same data.
    • They can be shared freely.
  3. Your state-based unit tests may be fewer and more reliable.
    • I’m speculating here, but your state-based tests may need only test those methods that create immutable objects. Perhaps, one set of tests that work on one set of creational methods could also be used to test other creational methods. (This would be a good area to look at further)
There are down sides, of course. The most obvious is the cost associated with object creation and garbage collection. For example, consider java.lang.String, a classic immutable object. Once a String is created, it cannot be changed. Period. With software that does a lot of String manipulation, you can end up with a lot of string objects in need of garbage collecting. To answer this problem, StringBuilder was implemented (StringBuffer is the predecessor). So, you may need to create a mutable version of your object that should be used with specific intent.

What does this look like?

In its simplest form, you (1) control how objects are created, and (2) make sure the object’s state can’t be changed. Though there are a number of ways to do this, I’ll present one method using ColdFusion 9.

This example represents a mathematical expression abstraction. An expression will look something like this: (2*4) + (5^2) * 10. The main thing we do is control the default constructor, init. By requiring a string expression as a parameter, we’ve controlled how instances are created.

component name="ImmutableExpression" {


public ImmutableExpression function init(required String expression) {
   rawExpression = expression;

     evaluatedExpression = evaluate(expression);
   catch(Expression e){
     throw( type="InvalidExpressionException",
            message="This doesn't look like a valid expression: " & expression);
   return this;

The above controls ColdFusion’s default constructor init by requiring a single argument. The ObjectInstantiationException is for clarity, otherwise the operation would fail at rawExpression = expression; and not express our intent. Updated as per Ray's comments.

In our Expression object, we want to maintain the original string representation and the result of evaluating the expression. Once we create an expression, we’re done. Equally as important, any state is maintained by private instance variables. And there are no setters and no direct way to change this object’s state.

A unit test for the constructor could look something like:

component extends=“mxunit.framework.TestCase” {

 function twoExpressionsShouldNotBeTheSame(){
      exp1 = new ImmutableExpression( “3^3” );
      exp2 = new ImmutableExpression( “4*2” );
      assertNotSame( exp1, exp2 );

* @expectedException InvalidExpressionException
 function badExpressionShouldBeKickedOut(){
   exp1 = new ImmutableExpression( “1*b” );


Let’s make this a little more interesting ...

With these expressions, which are somewhat related to polynomials, perhaps we’d like to add them:

exp1 = new ImmutableExpression( “3^3” );
  exp2 = new ImmutableExpression( “4*2” );
  exp3 = exp1.add(exp2) ;

The take-home here is in the 3rd line. The intent is to effectively add exp2 to exp1, returning a new ImmutableExpression. exp3.getExpression() will return (3^3) + (4*2) and exp3.value() will return 35

The implementation is straight forward:

public ImmutableExpression function add (ImmutableExpression exp){
   return new ImmutableExpression( “(” & rawExpression & “) + (” & exp.getExpression() & “)” ); 

Again, the point here is that we choose not to alter the state of an expression once created and so, we create new ImmutableExpression objects when we need to actually have the expression interact with another object, such as add(...). This is in the style if functional programming


  • ColdFusion doesn’t offer the ability to annotate a component as final , so you have to check the type being instantiated at runtime to prevent it from being extended. Why? If a component can be extended its methods can be overridden and possibly break your immutable intention.

 myComponentType = “sandbox.mutability.ImmutableExpression”;
 private void function ensureInstanceType(){
    if ( getMetaData(this).fullName != myComponentType )
     throw ( type=“InheritanceViolationException”,
               message=“This component is not intended to be extended.” );

Wrap up

Creating immutable objects is fairly straightforward and makes writing unit tests more effective, and immutable objects are inherently thread safe. However, care must be taken when creating software that could generate lots of immutable objects, and a mutable version of the object could be added to the API.

Functional Programming

In mathematics, a function f(n) always returns a value and never alters the function arguments. So, if you have an add(1,1) function, it will guarantee to return something, hopefully 2, and it will guarantee not to change either of the parameters (1 or 1). With respect to programming, we’re usually passing in variables that are evaluated at runtime to some value. In a functional style, you do not change the state of the variables being passed in. In some functional languages, this constraint is a feature, but in many languages it is not. So, you need to do this yourself by cloning.

ColdFusion Functional Programming Example:

Full source code:

Josh Bloch, Effective Java

Barbara Liskov, Program Development in Java

♫ Inspiration
Bill Evans

bill shelton