Coldbox, ColdSpring, Transfer, Refactoring And Me (part 1)

Today I started (gee, that's such a big and meaningful word) work on cwBlog. Since I'll be experimenting with this application, I thought it would be a great opportunity to try out some new (for me) technologies. I've been using Coldbox for a while, but decided it was time to take the plunge and try out some IoC and ORM frameworks (if you're not subscribed to Adobe Edge (you should be! (3rd-level nested text)), here's a great overview article Mark Mandel wrote on some of the most popular frameworks: Adobe Edge: October 2008). After reading the article and careful deliberation (5-10 minutes), I decided on ColdSpring for IoC, and Transfer-ORM for, well, ORM. Before I go into more detail, I just want to say that if it weren't for my unconventional server layout, this entire process would've probably been alot simpler.

Refactoring (we need to start somewhere)

I was talking about my unconventional server layout. Generally, frameworks like being installed in your server's webroot (or have a mapping point to their installed location). For example, Coldbox references it's internal objects with coldbox.system.someInternalObjects. What happens, however, when you need to have different versions of Coldbox installed on the same server? A standard approach I see more and more is to create a frameworks folder which will contain the different frameworks and their versions (coldbox_2_6_0, coldbox_2_6_1, etc.). The problem we'll quickly run into is that the internal objects still point to coldbox.system, not the new location. This is where refactoring comes into play. We need to change the way the frameworks work to make them point to their new locations. The technique is different for each, so I'll go through them one at a time.

Coldbox (Original location: /coldbox. New location: /frameworks/coldbox_2_6_1)

Luis includes a refactor.xml Ant task with his framework. However when I tried it it seemed to be broken (reported), so I had to refactor the files manually. Luckily, Eclipse's search feature (ctrl-h) scans through all the files in your open projects (other IDE's can also do this). You need to replace two distinct strings:

  • "coldbox.system" becomes frameworks.coldbox_2_6_1.system"
  • "/coldbox/system" becomes /frameworks/coldbox_2_6_1/system"

ColdSpring (Original location: /coldspring. New location: /frameworks/coldspring_1_2)

No Ant task with ColdSpring, but as we've seen with Coldbox there are ways around that. Using the same technique as with Coldbox, here are the two replacements we need to do:

  • "coldspring." becomes "frameworks.coldspring_1_2."
  • "/coldspring/" becomes "frameworks.coldspring_1_2/"

Transfer (Original location: /coldspring. New location: /frameworks/transfer_1_0)

After having so much success (let's admit it) blindly replacing strings in complex objects, I hit a snag with Transfer. When running my tests to make sure everything was working OK, I ended up realizing that some replacements actually broke Transfer! Rather than passing through the 1000+ occurences of "transfer.", I decided it would be best to search for another option. I luckily stumbled upon a post by Luis (yup, him again): Need to Refactor Transfer to meet your server layout? Here you go! In it, he shares an Ant task that automatically refactors the Transfer framework to the location of your choice. The best part? It works! I'll post it here also for posterity's sake:

<?xml version="1.0"?>
<!-- ======================================================================
Mar 19, 2007 12:23:55 PM

transfer.refactoring
This ant task will rebuild Transfer using a prefix of choice:
shared.frameworks.transfer0_63

This is useful, if you are not placing the Transfer library
in your web root.

Example: shared.frameworks.transfer0_63

by Luis Majano
====================================================================== -->

<project name="transfer.refactoring" default="do.refactor" basedir=".">
<description>
This ant task will rebuild colspring using a prefix of choice
</description>

<target name="do.prefix" description="Choose the new transfer prefix">
<input message="What prefix would you like to use? (ex:frameworks.transfer0_63)" addproperty="transfer.newprefix" />
<input message="What is the relative path now? (ex:/frameworks/transfer0_63)" addproperty="transfer.relativepath" />
<echo>The prefix choosen is: ${transfer.newprefix}</echo>
</target>

<target name="do.refactor" depends="do.prefix" description="refactor the code">
<echo>Refactoring: ${basedir}</echo>
<replace dir="${basedir}" value="${transfer.newprefix}.com" summary="yes">
<include name="**/*.cfc" />
<replacetoken>transfer.com</replacetoken>
</replace>
<replace dir="${basedir}" value="${transfer.relativepath}/resources" summary="yes">
<include name="**/
*.cfc"
/>

<replacetoken>/transfer/resources</replacetoken>
</replace>
</target>

</project>

There's one last thing left to change, and oddly enough that's in the Coldbox framework's system folder (in /frameworks/coldbox_2_6_1/system/extras/transfer/). Both cfc files reference the Transfer object, and need to point to the appropriate location. Find the occurences of "transfer." in these files and change them to "frameworks.transfer_1_0.".

In the next article I'll show you how I integrated these frameworks and got them working together.

TweetBacks
There are no TweetBacks for this entry.
Comments
Raul Riera's Gravatar I wanted to dig into frameworks but they all require like 3 other frameworks to work and that sir is a MESS, I am using now cfwheels.com, although is a port from another framework its actually pretty good
# Posted By Raul Riera | 10/15/08 4:54 AM
Sana's Gravatar @Raul: with coldbox you can use builtin IOC (lightwire), just skipping coldspring. Secondly Transfer is much more mature ORM than any other orm (as far as I know). If you got some time then compare features/performance between frameworks, I am sure you will find coldbox much more than a framework.
# Posted By Sana | 10/15/08 6:43 AM
Francois Levesque's Gravatar @Raul,

The three framework levels are actually distinct (MVC (Coldbox) - IoC (ColdSpring) - ORM (Transfer)). You can use one without using any of the others. I've actually been running Coldbox as a standalone for a while now, and it works great!

With this series I want to take it a step further, and integrate all three levels. I agree, however, that it's much easier to learn one layer at a time, so you're not overwhelmed ;).

Using Coldbox has made my life much easier, and I'm hoping the other layers will too (if they don't, what are they good for? :P). It's also the most documented of the popular frameworks out there (that I know of), so I recommend starting there if you're interested.
# Posted By Francois Levesque | 10/15/08 7:10 AM
Raul Riera's Gravatar Yeah, I actually consider ColdBox over ModelGlue, because model glue I needed to use other frameworks as well, so I was really going forwward with ColdBox, but then I saw the requirement for other frameworks in order to make it work, and that took me away. When I found cfwheels, yes its needs features but everything is RIGHT THERE out of the box, you get MVC and ORM.

I will follow your series to see if ColdBox plus ColdSpring and Transfer (since I need those frameworks too) could be a replacement for cfwheels, but currently i dont see how.

Ill keep a watch on this thread.
# Posted By Raul Riera | 10/15/08 8:34 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.3.000. Contact Blog Owner