<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ted Naleid</title>
	<atom:link href="http://naleid.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://naleid.com/blog</link>
	<description>Groovy, Grails and OS X tips and tricks</description>
	<lastBuildDate>Wed, 16 Jun 2010 17:38:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Groovy Each Iterator with Peek-ahead at Next Collection Value</title>
		<link>http://naleid.com/blog/2010/06/15/groovy-each-iterator-with-peek-ahead-at-next-collection-value/</link>
		<comments>http://naleid.com/blog/2010/06/15/groovy-each-iterator-with-peek-ahead-at-next-collection-value/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 04:55:10 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[metaprogramming]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=191</guid>
		<description><![CDATA[Groovy closures combined with iterators make it simple to create our own enhanced iterators that let us process a collection how we want to.
I write my own custom iterators all the time and name them something descriptive.  This makes the code much more readable. Rather than trying to decipher what a for loop is [...]]]></description>
			<content:encoded><![CDATA[<p>Groovy closures combined with iterators make it simple to create our own enhanced iterators that let us process a collection how we want to.</p>
<p>I write my own custom iterators all the time and name them something descriptive.  This makes the code much more readable. Rather than trying to decipher what a for loop is trying to do, we wrap up all of that iteration logic into a meaningful name and we cleanly separate that iteration from the processing that we&#8217;re doing with each element.</p>
<p>This kind of design is a core concept in Uncle Bob&#8217;s <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882" onclick="pageTracker._trackPageview('/outgoing/www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882?referer=');">Clean Code</a>, one of my favorite programming books in the last few years.</p>
<p>This example iterates over a collection and calls the passed in closure until we hit a value greater than 5.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> eachUntilGreaterThanFive <span style="color: #669966;">=</span> <span style="color: #669966;">&#123;</span> collection, closure <span style="color: #669966;">-&gt;</span>
    <span style="color: #996600;">for</span> <span style="color: #669966;">&#40;</span> value <span style="color: #996600;">in</span> collection <span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
        <span style="color: #996600;">if</span> <span style="color: #669966;">&#40;</span> value  <span style="color: #669966;">&gt;</span> <span style="color: #cc66cc;">5</span> <span style="color: #669966;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span>
        closure<span style="color: #669966;">&#40;</span>value<span style="color: #669966;">&#41;</span>
    <span style="color: #669966;">&#125;</span>
<span style="color: #669966;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">def</span> a <span style="color: #669966;">=</span> <span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">6</span>, <span style="color: #cc66cc;">7</span><span style="color: #669966;">&#93;</span>
&nbsp;
eachUntilGreaterThanFive<span style="color: #669966;">&#40;</span>a<span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
    <span style="color: #663366;">println</span> it
<span style="color: #669966;">&#125;</span></pre></div></div>

<p>prints:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #cc66cc;">1</span>
<span style="color: #cc66cc;">2</span>
<span style="color: #cc66cc;">3</span>
<span style="color: #cc66cc;">4</span>
<span style="color: #cc66cc;">5</span></pre></div></div>

<p>This code makes it obvious what the iterator is doing (looping till we hit a condition) as well as what will happen with each element iterated over (print it out).</p>
<p>For a real life example, I had a need to iterate over a list of values and where I needed both the current object as well as a peek at the next object in the list.</p>
<p>Doing this is Java is a bit of a pain, but groovy makes it easy to write and (hopefully) to read, we can also add it directly onto the Collection metaClass so that it&#8217;s available for all of our Collection instances:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #aaaadd; font-weight: bold;">Collection</span>.<span style="color: #006600;">metaClass</span>.<span style="color: #006600;">eachWithPeek</span> <span style="color: #669966;">=</span> <span style="color: #669966;">&#123;</span> closure <span style="color: #669966;">-&gt;</span>
    <span style="color: #000000; font-weight: bold;">def</span> last <span style="color: #669966;">=</span> <span style="color: #000000; font-weight: bold;">null</span>
    delegate<span style="color: #669966;">?</span>.<span style="color: #663399;">each</span> <span style="color: #669966;">&#123;</span> current <span style="color: #669966;">-&gt;</span>
        <span style="color: #996600;">if</span> <span style="color: #669966;">&#40;</span>last<span style="color: #669966;">&#41;</span> closure<span style="color: #669966;">&#40;</span>last, current<span style="color: #669966;">&#41;</span>
        last <span style="color: #669966;">=</span> current
    <span style="color: #669966;">&#125;</span>
    <span style="color: #996600;">if</span> <span style="color: #669966;">&#40;</span>last<span style="color: #669966;">&#41;</span> closure<span style="color: #669966;">&#40;</span>last, <span style="color: #000000; font-weight: bold;">null</span><span style="color: #669966;">&#41;</span>
<span style="color: #669966;">&#125;</span></pre></div></div>

<p>These test cases show that as we iterate through the collection, we can see the current item and peek at the next one (if any).  If the collection is empty, we don&#8217;t execute the closure it, and if we&#8217;re at the end of the list there isn&#8217;t anything to peek at:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #669966;">&#91;</span><span style="color: #669966;">&#93;</span>.<span style="color: #006600;">eachWithPeek</span> <span style="color: #669966;">&#123;</span> current, peek <span style="color: #669966;">-&gt;</span>
    <span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #808080; font-style: italic;">// shouldn't get here, nothing to iterate through</span>
<span style="color: #669966;">&#125;</span>
&nbsp;
<span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #669966;">&#93;</span>.<span style="color: #006600;">eachWithPeek</span> <span style="color: #669966;">&#123;</span> current, peek <span style="color: #669966;">-&gt;</span>
    <span style="color: #000000; font-weight: bold;">assert</span> current <span style="color: #669966;">==</span> <span style="color: #cc66cc;">1</span>
    <span style="color: #000000; font-weight: bold;">assert</span> peek <span style="color: #669966;">==</span> <span style="color: #000000; font-weight: bold;">null</span>  <span style="color: #808080; font-style: italic;">// only 1 element, nothing to peek at</span>
<span style="color: #669966;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">def</span> results <span style="color: #669966;">=</span> <span style="color: #669966;">&#91;</span><span style="color: #669966;">&#93;</span>
<span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">5</span><span style="color: #669966;">&#93;</span>.<span style="color: #006600;">eachWithPeek</span> <span style="color: #669966;">&#123;</span> current, peek <span style="color: #669966;">-&gt;</span>
    results <span style="color: #669966;">&lt;&lt;</span> <span style="color: #669966;">&#91;</span>current, peek<span style="color: #669966;">&#93;</span>
<span style="color: #669966;">&#125;</span>
<span style="color: #000000; font-weight: bold;">assert</span> results <span style="color: #669966;">==</span> <span style="color: #669966;">&#91;</span><span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span><span style="color: #669966;">&#93;</span>, <span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span><span style="color: #669966;">&#93;</span>, <span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span><span style="color: #669966;">&#93;</span>, <span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">5</span><span style="color: #669966;">&#93;</span>, <span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">5</span>, <span style="color: #000000; font-weight: bold;">null</span><span style="color: #669966;">&#93;</span><span style="color: #669966;">&#93;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/06/15/groovy-each-iterator-with-peek-ahead-at-next-collection-value/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using a Unique Grails Working Directory for each Mercurial Branch</title>
		<link>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/</link>
		<comments>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/#comments</comments>
		<pubDate>Fri, 07 May 2010 18:07:40 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=184</guid>
		<description><![CDATA[At work, we&#8217;re using mercurial for our source control.  As we&#8217;ve released code to production we&#8217;ve needed to branch our repository to support what&#8217;s in production as well as ongoing development.  
By default, grails uses ~/.grails as the working directory.  If you&#8217;re doing branchy development, you can run into problems with this [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we&#8217;re using <a href="http://mercurial.selenic.com/" onclick="pageTracker._trackPageview('/outgoing/mercurial.selenic.com/?referer=');">mercurial</a> for our source control.  As we&#8217;ve released code to production we&#8217;ve needed to branch our repository to support what&#8217;s in production as well as ongoing development.  </p>
<p>By default, grails uses <code>~/.grails</code> as the working directory.  If you&#8217;re doing branchy development, you can run into problems with this if you&#8217;ve got plugins installed in one branch that aren&#8217;t in the other.  Having a unique directory per branch prevents you from having to run <code>grails clean</code> all the time.</p>
<p>Here&#8217;s a quick shell script that changes the grails working directory to have the branch name as a suffix if your source is contained in a mercurial repository (ex: the default branch would be <code>~/.grails_default</code> and the 1.0 branch would be <code>~/.grails_1.0</code>).  If your application is not in a repo, it just uses the regular <code>~/.grails directory</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">HG_BRANCH</span>=<span style="color: #000000; font-weight: bold;">`</span>hg branch <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">GRAILS_SCRIPT</span>=<span style="color: #007800;">$GRAILS_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>grails
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$HG_BRANCH</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">GRAILS_WORK_DIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> ~<span style="color: #000000; font-weight: bold;">`/</span>.grails_<span style="color: #007800;">$HG_BRANCH</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;** grails working directory: <span style="color: #007800;">$GRAILS_WORK_DIR</span>&quot;</span>
	<span style="color: #007800;">$GRAILS_SCRIPT</span> -Dgrails.work.dir=<span style="color: #007800;">$GRAILS_WORK_DIR</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;** default grails working directory&quot;</span>
	<span style="color: #007800;">$GRAILS_SCRIPT</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Just save this script as &#8220;grails&#8221; and put it in your PATH before the $GRAILS_HOME/bin directory (also make sure that you&#8217;ve defined $GRAILS_HOME).  I have a ~/bin directory that&#8217;s the first thing in my PATH.</p>
<p>If you use the grails-debug command, you can repeat these steps for that, just change <code>GRAILS_SCRIPT</code> to <code>$GRAILS_HOME/bin/grails-debug</code>.</p>
<p>This same technique could easily be modified to be used for other source control systems such as git or subversion.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Grails build-test-data 1.1 released with new buildLazy functionality</title>
		<link>http://naleid.com/blog/2010/04/04/grails-build-test-data-1-1-released-with-new-buildlazy-functionality/</link>
		<comments>http://naleid.com/blog/2010/04/04/grails-build-test-data-1-1-released-with-new-buildlazy-functionality/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 19:13:44 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=178</guid>
		<description><![CDATA[Version 1.1 of the build-test-data plugin has just been released.
It adds a new buildLazy method that will only create a new object graph if it can&#8217;t find an existing object that matches the build criteria specified.
Example:

    def a = new Author&#40;firstName: &#34;Ray&#34;, lastName: &#34;Bradbury&#34;&#41;
    a.save&#40;&#41;
    assert [...]]]></description>
			<content:encoded><![CDATA[<p>Version 1.1 of the <a href="http://bitbucket.org/tednaleid/grails-test-data/wiki/Home" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-test-data/wiki/Home?referer=');">build-test-data plugin</a> has just been released.</p>
<p>It adds a new buildLazy method that will only create a new object graph if it can&#8217;t find an existing object that matches the build criteria specified.</p>
<p>Example:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">def</span> a <span style="color: #669966;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Author<span style="color: #669966;">&#40;</span>firstName: <span style="color: #aa0000;">&quot;Ray&quot;</span>, lastName: <span style="color: #aa0000;">&quot;Bradbury&quot;</span><span style="color: #669966;">&#41;</span>
    a.<span style="color: #006600;">save</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #cc66cc;">1</span> <span style="color: #669966;">==</span> Author.<span style="color: #663399;">count</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">// Author table already has Ray Bradbury in it, finds existing record</span>
    <span style="color: #000000; font-weight: bold;">def</span> bradbury <span style="color: #669966;">=</span> Author.<span style="color: #006600;">buildLazy</span><span style="color: #669966;">&#40;</span>lastName: <span style="color: #aa0000;">&quot;Bradbury&quot;</span><span style="color: #669966;">&#41;</span>  
    <span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #cc66cc;">1</span> <span style="color: #669966;">==</span> Author.<span style="color: #663399;">count</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">assert</span> bradbury.<span style="color: #006600;">firstName</span> <span style="color: #669966;">==</span> <span style="color: #aa0000;">&quot;Ray&quot;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">def</span> newAuthor <span style="color: #669966;">=</span> Author.<span style="color: #006600;">buildLazy</span><span style="color: #669966;">&#40;</span>lastName: <span style="color: #aa0000;">&quot;Moore&quot;</span><span style="color: #669966;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #cc66cc;">2</span> <span style="color: #669966;">==</span> Author.<span style="color: #663399;">count</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span> <span style="color: #808080; font-style: italic;">// creates a new record, no existing &quot;Moore&quot; author previously</span></pre></div></div>

<p>I find this particularly useful for building testing data in the grails console.  It allows me to do some quick setup of new objects and then concentrate on creating the code that I actually want to try out.  Without buildLazy, I was always commenting out my creation code so that multiple executions of the test script didn&#8217;t create multiple copies of the same data (and potentially hit unique constraints issues that I had to screw around with).  </p>
<p>Now, I no longer need to worry about commenting out the creation code after running it the first time.</p>
<p>Example:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> u <span style="color: #669966;">=</span> User.<span style="color: #006600;">buildLazy</span><span style="color: #669966;">&#40;</span>ssn: <span style="color: #aa0000;">&quot;123-456-7890&quot;</span><span style="color: #669966;">&#41;</span> <span style="color: #808080; font-style: italic;">// User.ssn has unique constraint</span>
u.<span style="color: #006600;">foo</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
u.<span style="color: #006600;">bar</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
u.<span style="color: #006600;">baz</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span></pre></div></div>

<p>Before buildLazy I&#8217;d need to comment out the user creation and replace it with a user.findBySsn.  Now buildLazy does the creation and later finding for me.  I can concentrate on making foo/bar/baz do what I want them to (the reason I opened the console in the first place).</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/04/04/grails-build-test-data-1-1-released-with-new-buildlazy-functionality/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Grails build-test-data plugin version 1.0 released</title>
		<link>http://naleid.com/blog/2010/03/17/grails-build-test-data-plugin-version-1-0-released/</link>
		<comments>http://naleid.com/blog/2010/03/17/grails-build-test-data-plugin-version-1-0-released/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 04:48:53 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[metaprogramming]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=171</guid>
		<description><![CDATA[I&#8217;ve finally released version 1.0 of the grails build-test-data plugin.
If you&#8217;re not familiar with build-test-data, the quick summary is that it puts a build() method on all grails domain objects.  Calling that method will automatically construct and save an instance of that domain object that conforms to all of the domain&#8217;s constraints.  It [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally released version 1.0 of the <a href="http://bitbucket.org/tednaleid/grails-test-data/wiki/Home" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-test-data/wiki/Home?referer=');">grails build-test-data plugin</a>.</p>
<p>If you&#8217;re not familiar with build-test-data, the quick summary is that it puts a <code>build()</code> method on all grails domain objects.  Calling that method will automatically construct and save an instance of that domain object that conforms to all of the domain&#8217;s constraints.  It also allows you to override the values that you want to explicitly set.  It makes your tests much cleaner and less fragile as you only need to specify the values that actually matter to a particular test method instead of building a huge graph of objects just to satisfy constraints.</p>
<p>The plugin has been quite stable for the past 6 months or so, and has survived upgrades from grails 1.0.X through grails 1.2.1 with minimal changes.  Because of this, I&#8217;ve decided to move the version from 0.2.3 to 1.0 to indicate that the plugin is stable and ready to be used.  I&#8217;ve also added the <a href="http://bitbucket.org/tednaleid/grails-test-data/src/tip/build-test-data/LICENSE" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-test-data/src/tip/build-test-data/LICENSE?referer=');">LICENSE</a> file releasing the plugin under the Apache 2.0 open source license (the same license as grails).  It was always open source, but I had neglected to add the official license file in the past.</p>
<p>If you&#8217;re not familiar with the build-test-data plugin, the <a href="http://bitbucket.org/tednaleid/grails-test-data/wiki/Home" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-test-data/wiki/Home?referer=');">documentation on the wiki</a> is thorough, I&#8217;ve also given <a href="http://naleid.com/blog/2009/07/14/grails-build-test-data-presentation/">a presentation on build-test-data</a> that explains why it&#8217;s better than other existing data generation technologies. </p>
<p>The biggest changes for this release compared to the last are a number of bugfixes around making sure that both sides of a one-to-many relationship get populated correctly and that there isn&#8217;t a need to <code>refresh()</code> from the database.</p>
<p>Previously, if you had an Author that <code>hasMany</code> Books, and each Book <code>belongsTo</code> an Author, you&#8217;d need to <code>refresh</code> the Author if you tried to build a new book with an existing author:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">Author eap <span style="color: #669966;">=</span> Author.<span style="color: #006600;">findByName</span><span style="color: #669966;">&#40;</span><span style="color: #aa0000;">&quot;Edgar Allan Poe&quot;</span><span style="color: #669966;">&#41;</span>
<span style="color: #aaaadd; font-weight: bold;">Book</span> b <span style="color: #669966;">=</span> <span style="color: #aaaadd; font-weight: bold;">Book</span>.<span style="color: #006600;">build</span><span style="color: #669966;">&#40;</span>author: eap, title: <span style="color: #aa0000;">&quot;The Tell-Tale Heart&quot;</span><span style="color: #669966;">&#41;</span>
&nbsp;
assertEquals eap.<span style="color: #006600;">name</span>, b.<span style="color: #006600;">author</span>.<span style="color: #006600;">name</span>  <span style="color: #808080; font-style: italic;">// works, linked in OK previously</span>
assertEquals <span style="color: #cc66cc;">1</span>, eap.<span style="color: #006600;">books</span>.<span style="color: #663399;">size</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span> <span style="color: #808080; font-style: italic;">// FAILED previously WORKS now, previously the book wasn't added properly to the author side of things</span></pre></div></div>

<p>The previous workaround was to call <code>eap.refresh()</code> to reload the author from the database, or to have the user manually <code>addToBooks(b)</code>.  Both solutions were ugly and kludgy and this issue has now been fixed.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/03/17/grails-build-test-data-plugin-version-1-0-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Updated grails autocomplete script for zsh</title>
		<link>http://naleid.com/blog/2010/03/02/updated-grails-autocomplete-script-for-zsh/</link>
		<comments>http://naleid.com/blog/2010/03/02/updated-grails-autocomplete-script-for-zsh/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 04:22:28 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=166</guid>
		<description><![CDATA[A couple of years ago, I created a grails auto-completion script for bash and zsh.  
Since then, I&#8217;ve completely abandoned bash, in favor of zsh (which I consider to be the superior shell) and I&#8217;d been getting annoyed at a few issues in the last grails autocomplete script.
I finally got motivated to make some [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of years ago, I created a <a href="http://naleid.com/blog/2008/03/25/autocomplete-grails-script-names-in-bashzsh/">grails auto-completion script for bash and zsh</a>.  </p>
<p>Since then, I&#8217;ve completely abandoned bash, <a href="http://naleid.com/blog/2009/05/13/shared-zshrc-file/">in favor of zsh</a> (which I consider to be the superior shell) and I&#8217;d been getting annoyed at a few issues in the last grails autocomplete script.</p>
<p>I finally got motivated <a href="http://bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_grails_compinstall" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_grails_compinstall?referer=');">to make some enhancements to it</a>.  Including support for grails 1.2 plugin scripts (1.2 moved the plugins into the ~/.grails directory), and support for test class name autocompletion (very useful for <code>grails test-app</code>).</p>
<p>To get it working (assuming you&#8217;re using zsh), you can either add the contents of <a href="http://bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_grails_compinstall" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/src/tip/zshrc_grails_compinstall?referer=');">my zshrc_grails_compinstall</a> to your .zshrc file, or you can switch over to using <a href="http://naleid.com/blog/2009/05/13/shared-zshrc-file/">my full zshrc setup</a>, which has a number of nice features that I&#8217;ve collected over the years.  I&#8217;ll also continue to update this as I think of new tricks.</p>
<p>After getting it installed, just type &#8220;grails&#8221; followed by a space and then hit tab.  It will show you a list of all of the potential grails scripts for the application that you&#8217;re in.  It&#8217;s aware of the version of the current app, as well as it&#8217;s application name based on the contents of application.properties, and also will include any scripts for the plugins you have installed in that app in <code>~/.grails/GRAILS_VERSION/projects/APP_NAME/plugins</code>  (in addition to the scripts in <code>./scripts</code>, <code>$GRAILS_HOME/scripts</code> and <code>~/.grails/scripts</code>).</p>
<p>After you choose your script (such as <code>grails test-app</code> hit space again and it will show you all of the test classes, with the full package for the class, under your test directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/03/02/updated-grails-autocomplete-script-for-zsh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using iWork Numbers.app AppleScript to Sum Columns For All Tables on a Sheet</title>
		<link>http://naleid.com/blog/2010/02/07/using-iwork-numbers-applescript-to-sum-columns-for-all-tables-on-a-sheet/</link>
		<comments>http://naleid.com/blog/2010/02/07/using-iwork-numbers-applescript-to-sum-columns-for-all-tables-on-a-sheet/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 04:45:08 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=157</guid>
		<description><![CDATA[Overall, I&#8217;m pretty happy with Numbers.app (part of Apple&#8217;s iWork suite) as a replacement for Excel.  It&#8217;s considerably cheaper and has lots of user interface tweaks to make it more pleasant to work with.
One of these changes is that each sheet can actually have multiple tables on it, and these can be arranged independently [...]]]></description>
			<content:encoded><![CDATA[<p>Overall, I&#8217;m pretty happy with Numbers.app (part of Apple&#8217;s iWork suite) as a replacement for Excel.  It&#8217;s considerably cheaper and has lots of user interface tweaks to make it more pleasant to work with.</p>
<p>One of these changes is that each sheet can actually have multiple tables on it, and these can be arranged independently on the same page.  This prevents the problem that happens in excel where you have multiple sets of data you want to see at the same time, but the cell/row sizing for one set of data affects the data in the other set that happens to be on the same row.</p>
<p>I&#8217;ve been leveraging this for a one-off personal project and I had a need to sum up all of the data in the 2nd column on all of the tables within a particular sheet.</p>
<p>This brought me to <a href="http://developer.apple.com/mac/library/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/mac/library/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html?referer=');">AppleScript</a>, Apple&#8217;s scripting language that&#8217;s used to drive applications.<br />
<span id="more-157"></span><br />
You can write scripts in the AppleScript editor (found in /Applications/Utilities).  In there, you can look up the commands and objects that a particular program makes available by going to File->Open Dictionary and then finding the application that you want to script.</p>
<p>I&#8217;ve done a little work in AppleScript in the past, but always recoil from it when I&#8217;m done.  It&#8217;s so damn wordy in what appears to be an attempt to make it more &#8220;friendly&#8221; when it really just makes it harder to remember the right syntax to get something done.  It probably just has <a href="http://www.youtube.com/watch?v=dCud8H7z7vU" onclick="pageTracker._trackPageview('/outgoing/www.youtube.com/watch?v=dCud8H7z7vU&amp;referer=');">&#8220;too many notes&#8221;.</a></p>
<p>Regardless, here&#8217;s the script that I came up with to sum up all of the values in the 2nd column (Column B) for all of the tables on the currently active sheet and then insert the result onto the 2nd column of a table named &#8220;Totals&#8221; (which must previously exist).</p>

<div class="wp_syntax"><div class="code"><pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;Numbers&quot;</span>
	<span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">document</span> <span style="color: #000000;">1</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> total <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">0</span>
		<span style="color: #ff0033; font-weight: bold;">set</span> totalTable <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">0</span>
		<span style="color: #ff0033; font-weight: bold;">tell</span> sheet <span style="color: #000000;">1</span>
			<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> j <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">count</span> <span style="color: #ff0033; font-weight: bold;">of</span> tables<span style="color: #000000;">&#41;</span>
				<span style="color: #ff0033; font-weight: bold;">try</span>
					<span style="color: #ff0033; font-weight: bold;">tell</span> table j
						<span style="color: #ff0033; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0066ff;">name</span> <span style="color: #ff0033; font-weight: bold;">is</span> <span style="color: #ff0033;">not</span> <span style="color: #ff0033;">equal</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #009900;">&quot;Totals&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #ff0033; font-weight: bold;">then</span>
							<span style="color: #ff0033; font-weight: bold;">repeat</span> <span style="color: #ff0033; font-weight: bold;">with</span> k <span style="color: #ff0033; font-weight: bold;">from</span> <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> <span style="color: #0066ff;">count</span> <span style="color: #ff0033; font-weight: bold;">of</span> rows
								<span style="color: #ff0033; font-weight: bold;">set</span> total <span style="color: #ff0033; font-weight: bold;">to</span> total <span style="color: #000000;">+</span> <span style="color: #000000;">&#40;</span>value <span style="color: #ff0033; font-weight: bold;">of</span> cell <span style="color: #000000;">2</span> <span style="color: #ff0033; font-weight: bold;">of</span> row k<span style="color: #000000;">&#41;</span>
							<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
						<span style="color: #ff0033; font-weight: bold;">else</span>
							<span style="color: #ff0033; font-weight: bold;">set</span> totalTable <span style="color: #ff0033; font-weight: bold;">to</span> j
						<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">if</span>
					<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
				<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">try</span>
			<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">repeat</span>
			<span style="color: #ff0033; font-weight: bold;">tell</span> table totalTable
				<span style="color: #0066ff;">display dialog</span> <span style="color: #009900;">&quot;total = &quot;</span> <span style="color: #000000;">&amp;</span> total <span style="color: #000000;">&amp;</span> <span style="color: #009900;">&quot; total table = &quot;</span> <span style="color: #000000;">&amp;</span> totalTable
				<span style="color: #ff0033; font-weight: bold;">set</span> value <span style="color: #ff0033; font-weight: bold;">of</span> cell <span style="color: #000000;">2</span> <span style="color: #ff0033; font-weight: bold;">of</span> row <span style="color: #000000;">1</span> <span style="color: #ff0033; font-weight: bold;">to</span> total
			<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
		<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
	<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span>
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre></div></div>

<p>I needed this ability as the number of tables on this sheet will change quite frequently depending on what I&#8217;m doing with it, and the values in the 2nd column of each of these tables will also get frequently modified and I need to easily know the sum across all of the tables.</p>
<p>To actually execute the script within Numbers.app, there are a couple of ways to do it.  It doesn&#8217;t appear that Numbers has it&#8217;s own script directory (normally, it would be under ~/Library/Application Support/iWork/Numbers/Scripts), but you can add it to your own User Scripts directory at ~/Library/Scripts.</p>
<p>If you want to access it through your menus, you can enable the global script icon up there by going into the AppleScript Editor preferences.  On the General tab, check the box that says &#8220;Show Script menu in menu bar&#8221;.</p>
<p>If you&#8217;re using LaunchBar or Quicksilver, you can also add this directory to their catalog as a place to search.  Then it&#8217;s as easy as cmd-space and the name of the script to execute it (both apps also allow you to set up keyboard shortcuts too).</p>
<p>In all, it feels hacky, and I&#8217;m sure it could be improved if I actually knew what the hell I was doing in AppleScript, but as I said, it&#8217;s a one-off that I need for a fairly particular problem.</p>
<p>I should probably take a little more time to learn more about AppleScript (or look more closely at a bridge to a language that I find a bit more palatable).  Being able to script the applications that I use can be very useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/02/07/using-iwork-numbers-applescript-to-sum-columns-for-all-tables-on-a-sheet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Interrogating Arbitrary Groovy Closures for Values</title>
		<link>http://naleid.com/blog/2010/01/24/interrogating-arbitrary-groovy-closures-for-values/</link>
		<comments>http://naleid.com/blog/2010/01/24/interrogating-arbitrary-groovy-closures-for-values/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 01:24:25 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[metaprogramming]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=136</guid>
		<description><![CDATA[Inspired by this question on stackoverflow, I decided to create a utility class that allowed me to determine generically what calls a closure makes (without actually letting it make any calls).  This lets me see what it&#8217;s trying to do before letting it actually do it.

It works by overriding the delegate of the closure [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by <a href="http://stackoverflow.com/questions/2128115/access-values-of-static-closure-in-groovy" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/2128115/access-values-of-static-closure-in-groovy?referer=');">this question on stackoverflow</a>, I decided to create a utility class that allowed me to determine generically what calls a closure makes (without actually letting it make any calls).  This lets me see what it&#8217;s trying to do before letting it actually do it.<br />
<span id="more-136"></span><br />
It works by overriding the delegate of the closure (a delegate intercepts all method and property get/set calls that have not already been dealt with).  It assigns it to an instance of the ClosureInterrogator which implements the propertyMissing and methodMissing methods.  Any property or set method that is called gets saved in a map that is returned to the caller.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ClosureInterrogator <span style="color: #669966;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #aaaadd; font-weight: bold;">Map</span> closureValueMap <span style="color: #669966;">=</span> <span style="color: #669966;">&#91;</span>:<span style="color: #669966;">&#93;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #aaaadd; font-weight: bold;">Map</span> extractValuesFromClosure<span style="color: #669966;">&#40;</span>Closure closure<span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">def</span> interrogator <span style="color: #669966;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClosureInterrogator<span style="color: #669966;">&#40;</span>closure<span style="color: #669966;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">return</span> interrogator.<span style="color: #006600;">closureValueMap</span>
    <span style="color: #669966;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> ClosureInterrogator<span style="color: #669966;">&#40;</span>Closure closure<span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">def</span> oldResolveStrategy <span style="color: #669966;">=</span> closure.<span style="color: #006600;">getResolveStrategy</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">def</span> oldDelegate <span style="color: #669966;">=</span> closure.<span style="color: #006600;">getDelegate</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
        closure.<span style="color: #006600;">delegate</span> <span style="color: #669966;">=</span> <span style="color: #000000; font-weight: bold;">this</span>
        closure.<span style="color: #006600;">resolveStrategy</span> <span style="color: #669966;">=</span> Closure.<span style="color: #006600;">DELEGATE_FIRST</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #669966;">&#123;</span>
            closure<span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>
        <span style="color: #669966;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #669966;">&#123;</span>        
            closure.<span style="color: #006600;">setDelegate</span><span style="color: #669966;">&#40;</span>oldDelegate<span style="color: #669966;">&#41;</span>
            closure.<span style="color: #006600;">setResolveStrategy</span><span style="color: #669966;">&#40;</span>oldResolveStrategy<span style="color: #669966;">&#41;</span>
        <span style="color: #669966;">&#125;</span>
    <span style="color: #669966;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">// property getter</span>
    <span style="color: #000000; font-weight: bold;">def</span> propertyMissing<span style="color: #669966;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> name<span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> closureValueMap<span style="color: #669966;">&#91;</span>name<span style="color: #669966;">&#93;</span>
    <span style="color: #669966;">&#125;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">// property setter</span>
    <span style="color: #000000; font-weight: bold;">def</span> propertyMissing<span style="color: #669966;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> name, value<span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
        closureValueMap<span style="color: #669966;">&#91;</span>name<span style="color: #669966;">&#93;</span> <span style="color: #669966;">=</span> value
    <span style="color: #669966;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">def</span> methodMissing<span style="color: #669966;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> name, args<span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
        <span style="color: #996600;">if</span> <span style="color: #669966;">&#40;</span>args.<span style="color: #663399;">size</span><span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span> <span style="color: #669966;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#123;</span>
            closureValueMap<span style="color: #669966;">&#91;</span>name<span style="color: #669966;">&#93;</span> <span style="color: #669966;">=</span> args<span style="color: #669966;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #669966;">&#93;</span>
        <span style="color: #669966;">&#125;</span> <span style="color: #996600;">else</span> <span style="color: #669966;">&#123;</span>
            closureValueMap<span style="color: #669966;">&#91;</span>name<span style="color: #669966;">&#93;</span> <span style="color: #669966;">=</span> args
        <span style="color: #669966;">&#125;</span>
    <span style="color: #669966;">&#125;</span>
<span style="color: #669966;">&#125;</span></pre></div></div>

<p>This technique is the basis for all groovy mocking techniques and libraries, it&#8217;s also the main technique used to create a <acronym title="Domain Specific Language">DSL</acronym> with groovy.</p>
<p>Here is a sample class that has a closure (&#8220;something&#8221;) that we want to extract the values from.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> SomeClass <span style="color: #669966;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">static</span> something <span style="color: #669966;">=</span> <span style="color: #669966;">&#123;</span>
        key1 <span style="color: #aa0000;">&quot;value1&quot;</span>              <span style="color: #808080; font-style: italic;">// calls methodMissing(&quot;key1&quot;, [&quot;value1&quot;])</span>
        key2<span style="color: #669966;">&#40;</span><span style="color: #aa0000;">&quot;value2&quot;</span><span style="color: #669966;">&#41;</span>             <span style="color: #808080; font-style: italic;">// calls methodMissing(&quot;key2&quot;, [&quot;value2&quot;])</span>
        key3 <span style="color: #669966;">=</span> <span style="color: #aa0000;">&quot;value3&quot;</span>            <span style="color: #808080; font-style: italic;">// calls propertyMissing(&quot;key3&quot;, &quot;value3&quot;)</span>
        key4 <span style="color: #aa0000;">&quot;foo&quot;</span>, <span style="color: #aa0000;">&quot;bar&quot;</span>, <span style="color: #aa0000;">&quot;baz&quot;</span>   <span style="color: #808080; font-style: italic;">// calls methodMissing(&quot;key4&quot;, [&quot;foo&quot;,&quot;bar&quot;,&quot;baz&quot;])</span>
    <span style="color: #669966;">&#125;</span>
<span style="color: #669966;">&#125;</span></pre></div></div>

<p>If we call &#8220;extractValuesFromClosure&#8221; on the &#8220;something&#8221; closure, we&#8217;ll get back a map that has all of the values we want in it.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> closureValueMap <span style="color: #669966;">=</span> ClosureInterrogator.<span style="color: #006600;">extractValuesFromClosure</span><span style="color: #669966;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> SomeClass<span style="color: #669966;">&#40;</span><span style="color: #669966;">&#41;</span>.<span style="color: #006600;">something</span><span style="color: #669966;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #aa0000;">&quot;value1&quot;</span> <span style="color: #669966;">==</span> closureValueMap.<span style="color: #aa0000;">&quot;key1&quot;</span>  <span style="color: #808080; font-style: italic;">// calls propertyMissing(&quot;key1&quot;)</span>
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #aa0000;">&quot;value2&quot;</span> <span style="color: #669966;">==</span> closureValueMap.<span style="color: #aa0000;">&quot;key2&quot;</span>  <span style="color: #808080; font-style: italic;">// calls propertyMissing(&quot;key2&quot;)</span>
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #aa0000;">&quot;value3&quot;</span> <span style="color: #669966;">==</span> closureValueMap.<span style="color: #aa0000;">&quot;key3&quot;</span>  <span style="color: #808080; font-style: italic;">// calls propertyMissing(&quot;key3&quot;)</span>
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #669966;">&#91;</span><span style="color: #aa0000;">&quot;foo&quot;</span>, <span style="color: #aa0000;">&quot;bar&quot;</span>, <span style="color: #aa0000;">&quot;baz&quot;</span><span style="color: #669966;">&#93;</span> <span style="color: #669966;">==</span> closureValueMap.<span style="color: #aa0000;">&quot;key4&quot;</span>  <span style="color: #808080; font-style: italic;">// calls propertyMissing(&quot;key4&quot;)</span></pre></div></div>

<p>This class will work with any type of closure, such as this closure used by the <a href="http://www.grails.org/Mail+plugin" onclick="pageTracker._trackPageview('/outgoing/www.grails.org/Mail+plugin?referer=');">grails mail plugin</a> to send mail.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> mailClosure <span style="color: #669966;">=</span> <span style="color: #669966;">&#123;</span>
   to <span style="color: #aa0000;">&quot;fred@g2one.com&quot;</span>,<span style="color: #aa0000;">&quot;ginger@g2one.com&quot;</span>
   from <span style="color: #aa0000;">&quot;john@g2one.com&quot;</span>
   cc <span style="color: #aa0000;">&quot;marge@g2one.com&quot;</span>, <span style="color: #aa0000;">&quot;ed@g2one.com&quot;</span>
   bcc <span style="color: #aa0000;">&quot;joe@g2one.com&quot;</span>
   subject <span style="color: #aa0000;">&quot;Hello John&quot;</span>
   body <span style="color: #aa0000;">'this is some text'</span>
<span style="color: #669966;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">def</span> results <span style="color: #669966;">=</span> ClosureInterrogator.<span style="color: #006600;">extractValuesFromClosure</span><span style="color: #669966;">&#40;</span>mailClosure<span style="color: #669966;">&#41;</span>
<span style="color: #663366;">println</span> results
<span style="color: #808080; font-style: italic;">// prints:</span>
<span style="color: #808080; font-style: italic;">// [to:[fred@g2one.com, ginger@g2one.com], from:john@g2one.com, cc:[marge@g2one.com, ed@g2one.com], bcc:joe@g2one.com, subject:Hello John, body:this is some text]</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">assert</span> results.<span style="color: #006600;">to</span>.<span style="color: #006600;">every</span> <span style="color: #669966;">&#123;</span> it.<span style="color: #006600;">endsWith</span><span style="color: #669966;">&#40;</span><span style="color: #aa0000;">&quot;g2one.com&quot;</span><span style="color: #669966;">&#41;</span> <span style="color: #669966;">&#125;</span></pre></div></div>

<p>If we wanted to assert that within a test environment, we&#8217;re only sending e-mail to a specific domain, this would be one technique to assert it before we actually send the e-mail off.</p>
<p>ClosureInterrogator is generic enough that it could also be used on a number of Grails/GORM domain closures such as &#8220;constraints&#8221; and &#8220;mapping&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/01/24/interrogating-arbitrary-groovy-closures-for-values/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hooking up Hudson to your bitbucket mercurial account</title>
		<link>http://naleid.com/blog/2009/12/21/hooking-up-hudson-to-your-bitbucket-mercurial-account/</link>
		<comments>http://naleid.com/blog/2009/12/21/hooking-up-hudson-to-your-bitbucket-mercurial-account/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 06:29:12 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[hudson]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=113</guid>
		<description><![CDATA[This past weekend, I saw @wakaleo running into some issues getting bitbucket hooked up to hudson.
I responded with a long reply that I thought would be worth cleaning up and posting here.

Mercurial, Bitbucket and Hudson
I&#8217;ve been using Mercurial as my personal revision control system for a while now.
I&#8217;ve more recently been using it at work [...]]]></description>
			<content:encoded><![CDATA[<p>This past weekend, I saw <a href="http://twitter.com/wakaleo" onclick="pageTracker._trackPageview('/outgoing/twitter.com/wakaleo?referer=');">@wakaleo</a> running into <a href="http://twitter.com/wakaleo/status/6789413053" onclick="pageTracker._trackPageview('/outgoing/twitter.com/wakaleo/status/6789413053?referer=');">some issues getting bitbucket hooked up to hudson</a>.</p>
<p>I <a href="http://twitter.com/tednaleid/status/6800126659" onclick="pageTracker._trackPageview('/outgoing/twitter.com/tednaleid/status/6800126659?referer=');">responded</a> with <a href="http://a.longreply.com/248600" onclick="pageTracker._trackPageview('/outgoing/a.longreply.com/248600?referer=');">a long reply</a> that I thought would be worth cleaning up and posting here.<br />
<span id="more-113"></span></p>
<h3>Mercurial, Bitbucket and Hudson</h3>
<p>I&#8217;ve been using <a href="http://mercurial.selenic.com/" onclick="pageTracker._trackPageview('/outgoing/mercurial.selenic.com/?referer=');">Mercurial</a> as my personal revision control system <a href="http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/">for a</a> <a href="http://naleid.com/blog/2009/11/08/mercurial-dvcs-devjam-presentation/">while now</a>.</p>
<p>I&#8217;ve more recently been using it at work with a repository hosted at <a href="http://bitbucket.org/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/?referer=');">BitBucket</a>, a great service that offers free accounts (including one private repo) and very <a href="http://bitbucket.org/plans/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/plans/?referer=');">reasonable upgraded accounts</a>.   (I don&#8217;t have any relationship with bitbucket other than just as a happy and satisfied user.)</p>
<p>Being a good agile shop, we use <a href="http://hudson-ci.org/" onclick="pageTracker._trackPageview('/outgoing/hudson-ci.org/?referer=');">hudson</a> as our <a href="http://martinfowler.com/articles/continuousIntegration.html" onclick="pageTracker._trackPageview('/outgoing/martinfowler.com/articles/continuousIntegration.html?referer=');">continuous integration</a> server (much better than Cruise Control IMO).  It polls the source control repository on a periodic basis, if it sees any code changes, it checks them out and runs all of the tests.</p>
<h3> Quick Mercurial/Hudson Setup</h3>
<h5>Install Mercurial</h5>
<p>There are lots of ways to <a href="http://mercurial.selenic.com/wiki/Download" onclick="pageTracker._trackPageview('/outgoing/mercurial.selenic.com/wiki/Download?referer=');">install mercurial</a>.  On the Ubuntu box, the quickest way to get a recent version for me was to just use python&#8217;s easy_install:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> easy_install mercurial</pre></div></div>

<h5>Install Hudson</h5>
<p>There are better guides out there for getting Hudson going depending on the platform you&#8217;re using, but here&#8217;s the quick instructions for how I got it going on an Ubuntu 9.10 image running on Amazon EC2.</p>
<p>Using Ubuntu&#8217;s apt-get package management, installing hudson is easy.  You need to add the repository that has the hudson source so that apt-get knows where to get it.  Add this to your <code>/etc/apt/sources.list</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">deb http:<span style="color: #000000; font-weight: bold;">//</span>hudson-ci.org<span style="color: #000000; font-weight: bold;">/</span>debian binary<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Then update apt-get and install hudson:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> hudson</pre></div></div>

<p>That creates a hudson install with a new &#8220;hudson&#8221; user on your system.  </p>
<h3>Setting up Hudson to SSH</h3>
<p>We want this user to be able to connect to BitBucket over SSH and check out the repository.  To do this, we&#8217;ll need an ssh public and private key that hudson can use.  Sudo to the hudson user and generate one:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> - hudson
&nbsp;
<span style="color: #666666; font-style: italic;"># cd to the home dir, default in /var/lib/hudson</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ~
&nbsp;
<span style="color: #666666; font-style: italic;"># create the ssh key in the ~/.ssh directory</span>
<span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa
&nbsp;
<span style="color: #666666; font-style: italic;"># that creates the public/private key in the /var/lib/hudson.ssh directory</span>
<span style="color: #c20cb9; font-weight: bold;">cat</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub</pre></div></div>

<p>Copy that key to your clipboard (make sure to get all of it, it&#8217;s all one big line that probably has wrapped in your terminal window a couple of times).  We&#8217;ll be using this as our identification on bitbucket.</p>
<h5>Give the Public Key to BitBucket</h5>
<p>If you&#8217;ve already got a BitBucket account that you want to give Hudson access to go to it now.  Otherwise, create a new account for Hudson to use.  Go to the <a href="http://bitbucket.org/account/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/account/?referer=');">&#8220;account&#8221; page</a> and paste the public key in the &#8220;SSH Keys&#8221; field and hit the &#8220;add key&#8221; button.</p>
<p>If this is the account that owns the repository (or already has access to it), you&#8217;re done on BitBucket.  Otherwise, if it&#8217;s a private repository owned by another user, you&#8217;ll need to add the hudson bitbucket user as a &#8220;read-only&#8221; user to the repository on the repository&#8217;s &#8220;admin&#8221; screen (or ask the repo owner to do that).</p>
<p>Then, go to the repository and get the ssh clone string for the repo you want to clone.  By default, bitbucket shows you the HTTPS clone string, which will NOT work with this authentication method.  To see it, click on the &#8220;SSH&#8221; link and it should show you something like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg clone <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>hg<span style="color: #000000; font-weight: bold;">@</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>tednaleid<span style="color: #000000; font-weight: bold;">/</span>grails-test-data<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>If the protocol in the url is &#8220;ssh&#8221;, you&#8217;ve got the right one.</p>
<h5>Finish Hudson Setup</h5>
<p>Back on the hudson box, you&#8217;ll want to manually clone the repo as the hudson user so that bitbucket is in the <code>~/.ssh/known_hosts</code> file.  Just execute the ssh clone command we found above:</p>
<p>Example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg clone <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>hg<span style="color: #000000; font-weight: bold;">@</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>tednaleid<span style="color: #000000; font-weight: bold;">/</span>grails-test-data<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>ssh will prompt you to add the host to the list of known hosts and then will clone the repo.  If that works, authentication is set up right and we&#8217;re almost done.</p>
<h5>Install the Mercurial plugin in Hudson</h5>
<p>All that&#8217;s left to do now is install the Mercurial plugin in hudson.  In a browser, go to http://INSERT_YOUR_IP_HERE:8080.  Hudson should come up.  </p>
<p>Click on &#8220;Manage Hudson&#8221; and go to &#8220;Manage Plugins&#8221;.  Go to the &#8220;Available&#8221; tab, check &#8220;Hudson Mercurial plugin&#8221; and hit the &#8220;Install&#8221; button.  Hudson will prompt you to restart, and then it&#8217;s installed.</p>
<p>After that, just create a new job and you&#8217;ll have a new &#8220;mercurial&#8221; option in the &#8220;source control management&#8221; section.  Select that and put the ssh URL in the &#8220;Repository URL&#8221; field.  Then put &#8220;default&#8221; in the &#8220;branch&#8221; field and set up the rest of the job to build/test your code (an exercise left to the reader).</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/12/21/hooking-up-hudson-to-your-bitbucket-mercurial-account/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mercurial DVCS DevJam Presentation</title>
		<link>http://naleid.com/blog/2009/11/08/mercurial-dvcs-devjam-presentation/</link>
		<comments>http://naleid.com/blog/2009/11/08/mercurial-dvcs-devjam-presentation/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 02:43:20 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=106</guid>
		<description><![CDATA[This past week, I gave a presentation to the DevJam meeting on the advantages of using Mercurial, a DVCS (Distributed Version Control System) over tools like Subversion, Perforce, and ClearCase.

I&#8217;ve been using a mercurial repository at bitbucket to host the build-test-data grails plugin, as well as a number of other things that I&#8217;ve done.  [...]]]></description>
			<content:encoded><![CDATA[<p>This past week, I gave a presentation to the <a href="http://www.devjam.com/" onclick="pageTracker._trackPageview('/outgoing/www.devjam.com/?referer=');">DevJam</a> meeting on the advantages of using Mercurial, a DVCS (Distributed Version Control System) over tools like Subversion, Perforce, and ClearCase.<br />
<span id="more-106"></span><br />
I&#8217;ve been using a mercurial repository at bitbucket to host the build-test-data grails plugin, as well as a number of other things that I&#8217;ve done.  We&#8217;re also using it at work to hold our grails applications.  I find that the way Mercurial works fits better with my style of development over git, the other popular DVCS.</p>
<p>The turnout at the meeting was great, and a heated discussion followed the presentation (as it always does at that meeting).</p>
<p>I&#8217;ve checked the original keynote files along with a PDF version into <a href="http://bitbucket.org/tednaleid/dvcs-with-mercurial/src/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/dvcs-with-mercurial/src/?referer=');">a mercurial repository</a>.</p>
<p>Here&#8217;s <a href="http://www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116?referer=');">the presentation on SlideShare</a>:</p>
<div style="width:425px;text-align:left" id="__ss_2426116"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116" title="Mercurial DVCS presentation to DevJam 11/4/2009" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116?referer=');">Mercurial DVCS presentation to DevJam 11/4/2009</a><object style="margin:0px" width="600" height="500"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dvcspresentation-091104221655-phpapp01&#038;stripped_title=mercurial-dvcs-presentation-to-devjam-1142009-2426116" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dvcspresentation-091104221655-phpapp01&#038;stripped_title=mercurial-dvcs-presentation-to-devjam-1142009-2426116" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="500"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/?referer=');">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/tednaleid" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid?referer=');">tednaleid</a>.</div>
</div>
<p><script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/11/08/mercurial-dvcs-devjam-presentation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Grails Testing Alias to Rerun Failed Tests</title>
		<link>http://naleid.com/blog/2009/11/03/grails-testing-alias-to-rerun-failed-tests/</link>
		<comments>http://naleid.com/blog/2009/11/03/grails-testing-alias-to-rerun-failed-tests/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 03:29:58 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[zshrc]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=99</guid>
		<description><![CDATA[A while ago I blogged about my grails testing aliases and how much time they save me.
I&#8217;ve made some enhancements to them in the interim that have made them even easier to use.  
The most important alias is gtaf, which is short for &#8220;grails test-app&#8221; for failed tests.
It will search through your test output [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I <a href="http://naleid.com/blog/2009/06/14/grails-testing-command-line-aliases/">blogged about my grails testing aliases</a> and how much time they save me.</p>
<p>I&#8217;ve made some enhancements to them in the interim that have made them even easier to use.  </p>
<p>The most important alias is <code>gtaf</code>, which is short for &#8220;grails test-app&#8221; for failed tests.</p>
<p>It will search through your test output directory and look for any tests that failed.  If it finds any, it will rerun only those tests.  Otherwise, it will rerun all tests.  That makes it easy to just use <code>gtaf</code> all the time.  If any tests fail, it will open them up using Console.app.  </p>
<p>If you&#8217;re not on OSX, or would like to use something else to view the failed test logs, just modify the <code>testlog</code> alias to do something different.<br />
<span id="more-99"></span><br />
There are alternative versions of it to only run failed integration tests (<code>gtaif</code> &#8211; Grails Test App Integration Failed), failed unit tests (<code>gtauf</code> &#8211; Grails Test App Unit Failed) or attach a debugger to the tests as they run (<code>gtadf</code> &#8211; Grails Test App Debug Failed).</p>
<p>These aliases, plus most of the rest of my zsh setup, is <a href="http://bitbucket.org/tednaleid/shared-zshrc/src/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/shared-zshrc/src/?referer=');">available on bitbucket</a>.  If you haven&#8217;t used zsh before and are still using bash, I suggest <a href="http://naleid.com/blog/2009/05/13/shared-zshrc-file/">switching over for the numerous benefits that it gives you</a>.</p>
<p>Here&#8217;s the section of zshrc_general that has the grails testing aliases, just add this to your .zshrc/.bashrc and make sure to uncomment the appropriate GRAILS_TEST_LOG_DIRECTORY export if you&#8217;re not running grails 1.2 yet:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># grails &gt; 1.2</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GRAILS_TEST_LOG_DIRECTORY</span>=target<span style="color: #000000; font-weight: bold;">/</span>test-reports
&nbsp;
<span style="color: #666666; font-style: italic;"># grails &lt; 1.2</span>
<span style="color: #666666; font-style: italic;"># export GRAILS_TEST_LOG_DIRECTORY=test/reports</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># after grails-test if there were ERROR messages, you can open those logs with the Console.app using this</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">testlog</span>=<span style="color: #ff0000;">'for F in `grep -lE &quot;FAILED|Caused\ an\ ERROR&quot; $GRAILS_TEST_LOG_DIRECTORY/plain/*.txt`; do echo &quot;&gt;&gt;&gt; opening&quot; $F; open -a Console $F; done;'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># grails-debug-suspend doesn't exist by default, it's a copy of grails-debug with the suspend flag changed to &quot;y&quot; so that</span>
<span style="color: #666666; font-style: italic;"># we can attach a remote debugger before it proceeds past startup</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># aliases where you can optionally pass in a set of tests to run (or no argument to run all tests in that group)</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gta</span>=grailsTestApp
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtad</span>=grailsTestAppDebug
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtau</span>=grailsTestAppUnit
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaud</span>=grailsTestAppUnitDebug
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtai</span>=grailsTestAppIntegration
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaid</span>=grailsTestAppIntegrationDebug
&nbsp;
<span style="color: #666666; font-style: italic;"># aliases that will rerun any failed tests (or all tests if there aren't any failed tests)</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaf</span>=grailsTestAppFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtadf</span>=grailsTestAppDebugFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtauf</span>=grailsTestAppUnitFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaudf</span>=grailsTestAppUnitDebugFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaif</span>=grailsTestAppIntegrationFailed
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gtaidf</span>=grailsTestAppIntegrationDebugFailed
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestApp<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails <span style="color: #ff0000;">&quot;&quot;</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppDebug<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails-debug-suspend <span style="color: #ff0000;">&quot;&quot;</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppDebugFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails-debug-suspend <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnit<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails <span style="color: #660033;">-unit</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnitFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails <span style="color: #660033;">-unit</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnitDebug<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails-debug-suspend <span style="color: #660033;">-unit</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppUnitDebugFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails-debug-suspend <span style="color: #660033;">-unit</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegration<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails <span style="color: #660033;">-integration</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegrationFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails <span style="color: #660033;">-integration</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegrationDebug<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsTest grails-debug-suspend <span style="color: #660033;">-integration</span> $<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsTestAppIntegrationDebugFailed<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span> grailsFailedTests grails-debug-suspend <span style="color: #660033;">-integration</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsFailedTests<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #007800;">FAILED_TESTS</span>=<span style="color: #ff0000;">''</span>
	<span style="color: #000000; font-weight: bold;">for</span> F <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-lE</span> <span style="color: #ff0000;">&quot;FAILED|Caused\ an\ ERROR&quot;</span> <span style="color: #007800;">$GRAILS_TEST_LOG_DIRECTORY</span><span style="color: #000000; font-weight: bold;">/</span>plain<span style="color: #000000; font-weight: bold;">/*</span>.txt<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #007800;">FAILED_TESTS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$FAILED_TESTS</span> <span style="color: #780078;">`echo $F | sed -E 's/.*TEST-(.*)Tests.txt/\1/g'`</span>&quot;</span>
	<span style="color: #000000; font-weight: bold;">done</span>;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;failed tests: <span style="color: #007800;">$FAILED_TESTS</span>&quot;</span>
	grailsTest $<span style="color: #000000;">1</span> $<span style="color: #000000;">2</span> <span style="color: #007800;">$FAILED_TESTS</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> grailsTest<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Running: $1 test-app $2 $3 || testlog &quot;</span>
    <span style="color: #000000; font-weight: bold;">time</span> $<span style="color: #000000;">1</span> test-app $<span style="color: #000000;">2</span> $<span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">||</span> testlog
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>I believe that they&#8217;ll also work fine as-is in bash, though I haven&#8217;t tested them.</p>
<p><script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/11/03/grails-testing-alias-to-rerun-failed-tests/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
