<?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>Sword Systems &#187; groovy</title>
	<atom:link href="http://swordsystems.com/category/groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://swordsystems.com</link>
	<description>Cutting Commentary</description>
	<lastBuildDate>Tue, 10 Jan 2012 02:02:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Auto-create User Domain Object with Spring Security</title>
		<link>http://swordsystems.com/2011/12/12/auto-create-user-domain-object-with-spring-security/</link>
		<comments>http://swordsystems.com/2011/12/12/auto-create-user-domain-object-with-spring-security/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 16:13:21 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[Single Sign On]]></category>
		<category><![CDATA[SSO]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[spring-security]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=194</guid>
		<description><![CDATA[For those who skip straight to the last page of a book to see how it ends &#8211; See Chap 7. Events of the spring-security-core plugin documentation. For those who like a little more detail&#8230; I just moved our grails app from using the shiro plugin to using the spring-security plugin(s). I like shiro&#8217;s filter-based [...]]]></description>
			<content:encoded><![CDATA[<p>For those who skip straight to the last page of a book to see how it ends &#8211; See <a href="http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/7%20Events.html" target="_blank">Chap 7. Events</a> of the spring-security-core plugin documentation.</p>
<p>For those who like a little more detail&#8230;</p>
<p>I just moved our grails app from using the <a href="http://www.grails.org/plugin/shiro" target="_blank">shiro</a> plugin to using the <a href="http://www.grails.org/plugin/spring-security-core" target="_blank">spring-security</a> plugin(s).  I like shiro&#8217;s filter-based config, but all the pre-built extension modules that <a href="http://burtbeckwith.com/blog/" target="_blank">Burt Beckwith</a> has put together for spring-security (<a href="http://www.grails.org/plugin/spring-security-ldap" title="spring-security-ldap" target="_blank">LDAP</a>, <a href="http://www.grails.org/plugin/spring-security-cas" title="Grails CAS plugin" target="_blank">CAS</a>, etc.) makes it much easier for us to support the range of environments in which we have to deploy.</p>
<p>The one feature which took me a little while to figure out was how to have our app auto-create a user domain object when it is using an external authentication source.  For example, say an instance of our app is configured to authentication against an LDAP server.  The app has a <code>MyUser</code> class that holds local settings for users like preferences, documents, etc.  When a user signs in for the first time and makes it past the authentication step, we need to automatically create a <code>MyUser</code> instance and associate it with the LDAP username.  With the shiro-based authentication, we did this in the controller method which handled the authentication itself.  Spring security works a little differently and there isn&#8217;t a central, post-authentication landing point.  </p>
<p>If your app is always deployed with the same type of authentication (e.g. always with LDAP), you could put the persistence code into a custom <code>UserDetailsService</code>.  There are several posts on the web that discuss creating a custom <code>UserDetails</code> object and a corresponding service for it, so this was the first approach I looked at.  <a href="http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/11%20Custom%20UserDetailsService.html" target="_blank">Chapter 11</a> of the spring-security-core plugin&#8217;s user guide has info on it as well.  The primary shortcoming is that you can&#8217;t chain together <code>UserDetailsService</code>s.  You have to implement one for each form of authentication with which you want to work. </p>
<p>If your app must work with a variety of authentication methods, it is easier to register a listener with Spring Security.  <a href="http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/7%20Events.html" target="_blank">Chapter 7</a> of the plugin guide discusses the two ways to do this.  I found that handling the <code>AuthenticationSuccessEvent</code> was all I needed.  Since we already had a Grail&#8217;s service that handles various user-related tasks, the listener object was dirt simple:</p>
<pre class="brush: groovy; title: ; notranslate">
import org.springframework.beans.factory.InitializingBean
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.context.ApplicationListener
import org.springframework.security.authentication.event.AuthenticationSuccessEvent

class MyAuthenticationEventListener implements ApplicationListener&lt;AuthenticationSuccessEvent&gt;, InitializingBean, ApplicationContextAware {
    ApplicationContext applicationContext
    def userService

    void afterPropertiesSet() {
        userService = applicationContext.getBean('userService')
    }

    void onApplicationEvent(AuthenticationSuccessEvent e) {
        //the principal field of the source object is a UserDetails object of some form.
        //The spring-security API contract guarantees that at least the username field will be populated.
        userService.createUser(e.source.principal)
    }
}
</pre>
<p>Since the whole class really just has one line of &#8220;functional&#8221; code, I could have used the closure-based approach described in section 7.3 of the user guide.  I just prefer to keep true code out of the <code>Config.groovy</code> file.</p>
<p>Then, within the <code>UserService.createUser</code> method, the key lines look something like this:</p>
<pre class="brush: groovy; title: ; notranslate">
    def user = MyUser.findByUsername(userDetails.username)
    if (!user)
    {
        MyUser.withTransaction {status -&gt;
            user = new MyUser(username:userDetails.username /*, set any other props you want to store locally*/)
            user.save(flush: true, failOnError:true)
        }
    }
    return user
</pre>
<p>One note of interest &#8211; without the <code>withTransaction</code> statement, you may get an exception stating that no hibernate session exists and one cannot be opened.  The <code>withTransaction</code> closure wraps this up nicely for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2011/12/12/auto-create-user-domain-object-with-spring-security/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GPars Quick Hits</title>
		<link>http://swordsystems.com/2011/09/28/gpars-quick-hits/</link>
		<comments>http://swordsystems.com/2011/09/28/gpars-quick-hits/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 02:30:07 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[gpars]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=165</guid>
		<description><![CDATA[Just finished my presentation to the DC Groovy Users Group on GPars collection and closure enhancements. Slides are on slide share for anyone who wants to take a peek. I&#8217;ll post up some of the coding examples when I get a chance.]]></description>
			<content:encoded><![CDATA[<p>Just finished my presentation to the DC Groovy Users Group on GPars collection and closure enhancements.  Slides are on <a href="http://www.slideshare.net/ericsword/gpars-quick-hits" title="slide share">slide share</a> for anyone who wants to take a peek.  I&#8217;ll post up some of the coding examples when I get a chance.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2011/09/28/gpars-quick-hits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GPars performance test</title>
		<link>http://swordsystems.com/2011/08/29/gpars-performance-test/</link>
		<comments>http://swordsystems.com/2011/08/29/gpars-performance-test/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 11:46:28 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[gpars]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=164</guid>
		<description><![CDATA[We just added a REST interface for replicating data between servers. Parts of the service require us to GET a collection of URLs all at once and to POST an object to a collection of remote servers all at once. I thought this would be a great time to try out GPars. After all, you [...]]]></description>
			<content:encoded><![CDATA[<p>We just added a REST interface for replicating data between servers.  Parts of the service require us to GET a collection of URLs all at once and to POST an object to a collection of remote servers all at once.  I thought this would be a great time to try out GPars.  After all, you can&#8217;t get much easier pooling/multi-threaded support than:</p>
<pre class="brush: java; title: ; notranslate">
    GParsPool.withPool {
        urlList.eachParallel {
            ...get/post with Jersey client...
        }
    }
</pre>
<p>Some of my co-workers expressed concern that this would involve creating and destroying the pool data structures (specifically, Java threads) for every url or server collection we submitted.  They thought this would take too much overhead.  So I decided to put together a few tests to see what GPars could get us using its simplest form of concurrency.  First, an interesting tidbit from the reference guide:</p>
<blockquote><p>
While the GParsPool class relies on the jsr-166y Fork/Join framework and so offers greater functionality and better performance, the GParsExecutorsPool uses good old Java executors and so is easier to set up in a managed or restricted environment.  It needs to be stated, however, that GParsPool performs typically much better than GParsExecutorsPool does.  (<a href="http://www.gpars.org/guide/guide/3.%20Data%20Parallelism.html">Section 3 intro</a>).
</p></blockquote>
<p>and, from Groovy in Action v2:</p>
<blockquote><p>
GParsPool does not create threads. Instead, it takes them from a fork/join thread pool of the jsr166y library, which is a candidate for inclusion in future Java versions. GPars uses this library extensively, especially its support for parallel arrays that are the basis for all parallel collection processing in GPars.&#8221; (Section 17.2)
</p></blockquote>
<p>If these statements were correct, then hopefully we didn&#8217;t have to worry about maintaining an existing pool and setting up a countdown latch of some form.</p>
<h2>Tests</h2>
<p>I threw together some quick-and-dirty tests:</p>
<ul>
<li>A series of mathematical operations (i.e. pure cpu)</li>
<li>Open and read in the text of 120 files, each about 1-4Kb</li>
<li>Get the contents of a small web page (9kb) hosted on a machine on the local network</li>
</ul>
<p>Obviously, these were not meant to be a definitive test of all of GPars capabilities.  I just wanted to see if we could use the simplest form of GPars notation or if we had to do something more complicated.</p>
<p>I ran each test in a loop various numbers of times (100 up to 10000), just to see if there was significant difference over time.  The results I list below are for the test that ran the loop 5000 times.  The core bit of code I timed was something like this:</p>
<pre class="brush: java; title: ; notranslate">
    int ms = 0
    5000.times {
        StopWatch timer = new StopWatch().go()
        GParsExecutorsPool.withPool {
            List result = data.collectParallel {
                //(1..100).sum {i -&gt; i^it}
                //or
                //it.text.size()
            }
        }
        ms += timer.stop
    }
    def message = DebugUtils.logTimePerItem(&quot;GParsPool&quot;, numLoops, ms)
    println message
</pre>
<p>where &#8220;it&#8221; was a File or URL (or a number for test #1).</p>
<p>I ran the test using regular sequential code (i.e. commenting out the <code>withPool</code> block and changing <code>collectParallel</code> to the normal <code>collect</code>), and then using GParsPool.withPool and GParsExecutorsPool.withPool.  I also tried using the GPars <code>ParallelEnhancer</code> class and the <code>makeConcurrent</code>, both of which let me just use the normal <code>collect</code> call rather than having to write <code>collectParallel</code>.  For some reason, these conventions slowed down the collection processing by a noticeable amount.  I did not dive into why that happens, but I suspect it has to do with the additional overhead of the custom <code>MetaClass</code> handling.</p>
<h1>Results</h1>
<p>These are the results on my Dell Precision M6400 running 32-bit Fedora 14.  The JVM had 1.5G of RAM.</p>
<h3>Test: Mathematical Operation</h3>
<p>Normal: 5000 in 14594 (343/s)<br />
GParsPool: 5000 in 12480 (401/s)<br />
GParsExecutorsPool: 5000 in 15685 (319/s)</p>
<p>I reran this test with the timer inside the withPool call to see what the overhead of creating the pool was, i.e.:</p>
<pre class="brush: java; title: ; notranslate">
        GParsExecutorsPool.withPool {
            MemStopWatch timer = new MemStopWatch().go()
            List result = data.collectParallel {
                (1..100).sum {i -&gt; i^it}
            }
            ms += timer.stop
        }
</pre>
<p>with these results:<br />
GParsPool: 5000 in 11253 (444/s)<br />
GParsExecutorsPool: 5000 in 13308 (376/s)</p>
<p>So setting up the pool each time definitely has some overhead cost, but even doing that, the GParsPool is still faster than normal, single-threaded sequential execution, even on my little ol&#8217; dual core machine.</p>
<h3>Test: Open and Read Files</h3>
<p>Normal: 5000 in 31726 (157/s)<br />
GParsPool: 5000 in 24050 (207/s)<br />
GParsExecutorsPool: 5000 in 25351 (197/s)</p>
<p>Very similar scale of results as with the straight mathematical operation.</p>
<h3>Test: Get small web page over local network</h3>
<p>All tests resulted in the same numbers &#8211; network latency was the deciding factor.  Sorry for not having the exact metrics on this one.</p>
<h1>Conclusion</h1>
<p>So what does all this mean?  I think it means that just using the simple <code>GParsPool.withPool</code> structure to iterate over a collection is perfectly fine for our needs.  We could optimize a bit with different structures and a pre-existing pool, but it honestly won&#8217;t make a bit of difference in real performance given that network latency is the deciding factor for us.  Your mileage may vary, especially if you are running an open server that has higher load requirements. </p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2011/08/29/gpars-performance-test/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Representing an XML qualified name as a string</title>
		<link>http://swordsystems.com/2011/05/31/representing-an-xml-qualified-name-as-a-string/</link>
		<comments>http://swordsystems.com/2011/05/31/representing-an-xml-qualified-name-as-a-string/#comments</comments>
		<pubDate>Tue, 31 May 2011 10:30:59 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[OGC]]></category>
		<category><![CDATA[semantic web]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=140</guid>
		<description><![CDATA[I am working on a project where we need to store qualified XML names (QNames i.e. namespace and local name) as strings outside of an XML document. This includes QNames from any third party namespace that a user of our package wants to include. So I set out to find the standard way of doing [...]]]></description>
			<content:encoded><![CDATA[<p>I am working on a project where we need to store qualified XML names (QNames i.e. namespace and local name) as strings outside of an XML document.  This includes QNames from any third party namespace that a user of our package wants to include.  So I set out to find the standard way of doing this in a way that would give other apps the best chance of being able to properly parse the string back into a QName, especially for QNames which already had a somewhat widely used string representation.  We are storing meta-data about &#8220;things&#8221; (documents, sensor recordings, you name it), so I paid particular attention to popular schemas in the semantic web space.  Should we use <code>ns:name, ns/name, ns#name</code>, or something else?  After spending way too much time on this, here is what I found:</p>
<ul>
<li>There is no official standard.  A qualified name is officially defined as two strings &#8211; the namespace and the local name.  Oh, great.</li>
<li>One of the first <a href="http://jclark.com/xml/xmlns.htm">papers</a> on this by James Clark says <code>{namespace}local</code> is proper.  This is what <a href="http://download.oracle.com/javase/6/docs/api/javax/xml/namespace/QName.html#toString%28%29">javax.xml.namespace.QName.toString</a> produces, and the <a href="http://download.oracle.com/javase/6/docs/api/javax/xml/namespace/QName.html#valueOf%28java.lang.String%29">QName.valueOf</a> method will parse that format.  This form is also what the groovy QName class uses, but, interestingly, the <a href=" http://groovy.codehaus.org/api/groovy/xml/QName.html#equals%28java.lang.Object%29">equals</a> for that class will accept a string that uses a colon delimiter.</li>
<li><a href="http://docstore.mik.ua/orelly/xml/xmlnut/ch04_02.htm">http://docstore.mik.ua/orelly/xml/xmlnut/ch04_02.htm</a> talks of both <code>{namespace}local</code> and <code>namespace#local</code></li>
<li><a href="http://www.rpbourret.com/xml/NamespacesFAQ.htm#names_15">http://www.rpbourret.com/xml/NamespacesFAQ.htm#names_15</a> has great detail on namespaces overall.  It talks of <code>{namespace}local</code> and another form, <code>namespace^local</code>, which is what SAX filter uses, according to the page.  I found no other examples or mention of this &#8220;caret&#8221; format.</li>
<li><a href="http://download.oracle.com/javaee/5/api/javax/xml/soap/Name.html">javax.xml.soap.Name</a> uses <code>namespace:local</code>.  Apache axis does the same thing, which is not surprising considering I believe one came from the other.</li>
<li><a href="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMAScript for XML</a> (and, thus, Adobe ActionScript) uses 2 colons &#8211; <code>namespace::local</code>.  This is partly because it uses the two colons as an operator of sorts, and needed to separate it from other uses of a colon in the ECMAScript syntax.</li>
<li><a href="http://dublincore.org/documents/dcmi-terms/">Dublin Core (DC)</a> explicitly defines the URIs of the terms in its schema.  It uses &#8220;the path divider &#8216;/&#8217; as the delimiter between namespace and local name.  Of note, if you try to put one of those URIs into a web browser as a URL, it will redirect to a page which uses &#8216;#&#8217; to note the fragment in an RDF schema.  For example, <code>http://purl.org/dc/terms/</code> will resolve to <code>http://dublincore.org/2010/10/11/dcterms.rdf#name</code>.  I didn&#8217;t find any other schema/taxonomy that explicitly defines the URI for each element. </li>
<li>Regardless of the above behaviour, the <a href="http://dublincore.org/schemas/xmls/qdc/2008/02/11/dcterms.xsd">Dublin Core XSD</a> defines the namespace to include the ending &#8216;/&#8217;.</li>
<li>The <a href="http://www.w3.org/TR/rdf-schema/#ch_appendix_rdfs">namespaces of the RDF and OWL specifications</a> include an ending &#8216;#&#8217;.</li>
<li>All namespaces included in the output from <a href="http://pingthesemanticweb.com/stats/namespaces.php">pingthesemanticweb</a>, which lists the most popular semantic schemas, end in &#8216;/&#8217; or &#8216;#&#8217;. Even the few that use urn format end in &#8216;#&#8217; (e.g. <code>urn:x-inspire:specification:gmlas:HydroPhysicalWaters:3.0#</code>).</li>
<li>The <a href="http://metadata.dod.mil/mdr/ns/DDMS/current/">Department of Defense Discovery Metadata Specification (DDMS)</a> namespace, based heavily on Dublin Core, includes the ending &#8216;/&#8217; just as DC does.</li>
<li>I could not find any namespaces that end in &#8216;}&#8217;, &#8216;^&#8217;, or &#8216;:&#8217; (the first two of which are illegal, I think)</li>
<p><nbr/><br />
So, you might be thinking that we could just concatenate the namespace and local name together to form the string.  To parse it, we could then split the string at the last occurrence of the delimiter character, keeping the delimiter as part of the namespace if it is a &#8216;/&#8217; or a &#8216;#&#8217;.  But wait!  There&#8217;s more&#8230;</p>
<li>Many non-semantic-web schemas, like the <a href="http://www.w3.org/2001/XMLSchema.xsd">XML Schema itself</a>, <a href="http://www.w3.org/TR/xlink-naming/">xlink</a>, and the <a href="http://www.opengeospatial.org/">OGC</a> standards like <a href="http://schemas.opengis.net/gml/3.2.1/gml.xsd">gml</a>, do not include the ending delimiter in their namespaces.</li>
<li><a href="http://www.niem.gov/niem/niem-core/2.0/niem-core.xsd">National Information Exchange Model (NIEM)</a> namespaces, arguably somewhat-semantic, also do not include a trailing delimiter.</li>
<li>Neither does the <a href="http://www.niem.gov/IC-ISM-v2.xsd">Intelligence Community Metadata Standard for<br />
Information Security Marking (IC-ISM)</a> namespace (which is in <code>urn</code> format).</li>
<li>Nor does the <a href="http://metadata.dod.mil/mdr/ns/dodmwg/0.75c/owl/coreTaxonomy">DOD core metadata OWL schema</a>, at least as far as I can tell.  Sorry, I couldn&#8217;t find an exact reference to that one.</li>
</ul>
<h2>Resolution Rules</h2>
<p>So if you want to represent a particular qualified name as a string and do it in a way that others are most likely to recognize as the &#8220;accepted&#8221; way to represent that particular QName <strong>and</strong> you want it to be reversible, at least within your own app, the best rules I could come up with are:</p>
<h3>Creating the String</h3>
<p>Call the path divider &#8216;/&#8217; and fragment &#8216;#&#8217; symbols <em>sticky</em> delimiters because they may be a part of (i.e. stick to) a namespace.  Call the other possibilities (&#8216;:&#8217;, &#8216;::&#8217;, &#8216;}&#8217;, &#8216;^&#8217;) <em>formal</em> delimiters because you know they only serve the purpose of being a delimiter.</li>
<ol>
<li>If the namespace ends in a delimiter of any form, simple append the local name directly to it.</li>
<li>Else, use &#8216;:&#8217;, &#8216;^&#8217; or, to be totally safe, surround the namespace string with &#8216;{}&#8217; and then append the local name.  I chose &#8216;:&#8217; because I at least saw some uses of that form on various pages while I never saw any uses of the caret &#8216;^&#8217; or the surrounding &#8216;{}&#8217;.  If you have total control of your input and output, use the surrounding braces format since it is totally unambiguous.</li>
</ol>
<h3>Parsing the String</h3>
<ol>
<li>If there is a &#8216;{}&#8217; pair, can assume form is <code>{namespace}local</code></li>
<li>Else, find the last possible delimiter in the string.  If it is a &#8220;formal&#8221; delimiter, then drop the delimiter and make the namespace the chars before it and local name the chars after it.</li>
<li>Else, if the last delimiter is &#8220;sticky&#8221;, you have to guess whether to keep it in the namespace.  I put some basic logic in my code to recognize well known namespaces (like those above) that do not end in a delimiter, but then otherwise assume that a sticky delimiter should be included in the namespace.</li>
</ol>
<p>It&#8217;s not a perfect solution, but that&#8217;s what you get when there is no standard.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2011/05/31/representing-an-xml-qualified-name-as-a-string/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Running latest Groovy from Maven</title>
		<link>http://swordsystems.com/2011/04/05/running-latest-groovy-from-maven/</link>
		<comments>http://swordsystems.com/2011/04/05/running-latest-groovy-from-maven/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 15:10:15 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[groovy plugin]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=126</guid>
		<description><![CDATA[Say you have a groovy-project that you build with maven.  You use the org.codehaus.gmaven:gmaven-plugin to compile your groovy code and run groovy tests without a problem.  Then you add some features or tests that need groovy 1.7.  You add the proper dependency and version to the &#60;dependencies&#62; section of your pom, run your test&#8230; and [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have a groovy-project that you build with maven.  You use the org.codehaus.gmaven:gmaven-plugin to compile your groovy code and run groovy tests without a problem.  Then you add some features or tests that need groovy 1.7.  You add the proper dependency and version to the &lt;dependencies&gt; section of your pom, run your test&#8230; and watch it blow up because the gmaven-plugin defaults to using groovy 1.6.  So you dig around on the web and find references for how to use the &lt;providerSelection&gt; tag of the gmaven-plugin to get your code compiled with 1.7 and to use 1.7 when running tests.  Things seem good.  Until&#8230;</p>
<p>You add a feature that requires some version of groovy greater than 1.7.4 (the version included with the latest gmaven-plugin, 1.3).  In my case, I used the @Delegate annotation with some inheritance in a test configuration and hit a bug that was fixed in groovy 1.7.6.  No matter what version I used in my dependencies section, my tests were executed under groovy 1.7.4.  I finally came up with the configuration below which let me run with a different groovy.  Note that it made no difference what I included in the dependencies section.  The gmaven-plugin configuration appears to be completely independent of that.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.gmaven&lt;/groupId&gt;
    &lt;artifactId&gt;gmaven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.3&lt;/version&gt;
    &lt;configuration&gt;
        &lt;providerSelection&gt;1.7&lt;/providerSelection&gt;
        &lt;!-- This is only used if you want to run a groovy script from the command line using maven --&gt;
        &lt;source&gt;${groovy.script}&lt;/source&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;goals&gt;
                &lt;goal&gt;compile&lt;/goal&gt;
                &lt;goal&gt;testCompile&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;!-- This block is required in order to make the gmaven plugins use a groovy other than 1.7.4.
     This is independent of the groovy entry in the dependencies section.  This does not affect the class path.

     What is interesting is that there must be both the gmaven.runtime entry with the explicit excludes
     and the additional dependency on whatever version we do want to use.  If you exclude the former,
     it will throw an exception. --&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.codehaus.gmaven.runtime&lt;/groupId&gt;
            &lt;artifactId&gt;gmaven-runtime-1.7&lt;/artifactId&gt;
            &lt;version&gt;1.3&lt;/version&gt;
            &lt;exclusions&gt;
                 &lt;exclusion&gt;
                     &lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
                     &lt;artifactId&gt;groovy-all&lt;/artifactId&gt;
                 &lt;/exclusion&gt;
            &lt;/exclusions&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
            &lt;artifactId&gt;groovy-all&lt;/artifactId&gt;
            &lt;version&gt;1.7.6&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/plugin&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2011/04/05/running-latest-groovy-from-maven/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cruising on other people&#8217;s work</title>
		<link>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/</link>
		<comments>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 14:48:26 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=23</guid>
		<description><![CDATA[I love it when other people do my work for me.  For example, I needed to store a few random settings in a Grails app, such as the last time a service polled an external resource.  So I went to the main Grails Plugin site and, sure enough, someone else has already written a Grails [...]]]></description>
			<content:encoded><![CDATA[<p>I love it when other people do my work for me.  For example, I needed to store a few random settings in a Grails app, such as the last time a service polled an external resource.  So I went to the main <a href="http://grails.org/plugin/category/all" target="_blank">Grails Plugin</a> site and, sure enough, someone else has already written a <a href="http://grails.org/plugin/settings" target="_blank">Grails Settings</a> plugin.  It needs a few enhancements to do what I want, but it&#8217;s better than starting from scratch.  While I was perusing the plugin list, I found a few others that can replace features I had started to sketch out (like <a href="http://grails.org/plugin/taggable" target="_blank">Taggable</a>) and was inspired by yet others that would let me easily add features that I hadn&#8217;t thought of before (like <a href="http://grails.org/plugin/commentable" target="_blank">Commentable </a>and <a href="http://grails.org/plugin/sparkline" target="_blank">Sparkline</a>).</p>
<p>Another example is yet another good <a href=" http://agileice.blogspot.com/2009/09/grails-integration-testing.html" target="_blank">post</a> by my friend and coworker Jeff Erikson detailing his research into problems with Grails config options getting wiped during integration tests.  I had been meaning to write up a note about how the GrailsUnitTestCase class hides the true config settings, so you don&#8217;t want to accidentally use it in integration tests.  Jeff took my little tip a lot farther with his post.  Thanks, Jeff!</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/09/11/cruising-on-other-peoples-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse, Maven, and Groovy, oh my!</title>
		<link>http://swordsystems.com/2009/06/03/eclipse-maven-and-groovy-oh-my/</link>
		<comments>http://swordsystems.com/2009/06/03/eclipse-maven-and-groovy-oh-my/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 11:00:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[m2eclipse]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=10</guid>
		<description><![CDATA[The groovy support in Eclipse leaves a bit to be desired. &#8220;Tell me something new&#8221; you say. How about &#8211; The groovy support in maven projects within eclipse leaves a lot to be desired, but it does at least exist, so long as you are willing to work at it a bit. Rather than posting [...]]]></description>
			<content:encoded><![CDATA[<p>The groovy support in Eclipse leaves a bit to be desired.  &#8220;Tell me something new&#8221; you say.  How about &#8211; The groovy support in maven projects within eclipse leaves a lot to be desired, but it does at least exist, so long as you are willing to work at it a bit.</p>
<p>Rather than posting the details off in the wilderness of my own blog, I responded to a post on the <a href="http://m2eclipse.sonatype.org/">m2eclipse</a> (the maven-eclipse <span class="blsp-spelling-error" id="SPELLING_ERROR_0">plugin</span>) mail list from last Fall where someone was asking how to add groovy support to maven projects.  The author of the m2eclipse <span class="blsp-spelling-error" id="SPELLING_ERROR_1">plugin</span> stated that the groovy <span class="blsp-spelling-error" id="SPELLING_ERROR_2">plugin</span> needed to support some hooks into m2eclipse.  While that may be true to get fully automated setup and synchronization, you can get the two <span class="blsp-spelling-error" id="SPELLING_ERROR_3">plugins</span> working together.  See this thread for the info:<br /><a href="http://www.nabble.com/Using-M2Eclipse-together-with-Groovy-td19261256.html">http://www.nabble.com/Using-M2Eclipse-together-with-Groovy-td19261256.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/06/03/eclipse-maven-and-groovy-oh-my/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipe Groovy Plugin &#8211; decent for scripts, PITA for classes</title>
		<link>http://swordsystems.com/2009/05/03/eclipe-groovy-plugin-decent-for-scripts-pita-for-classes/</link>
		<comments>http://swordsystems.com/2009/05/03/eclipe-groovy-plugin-decent-for-scripts-pita-for-classes/#comments</comments>
		<pubDate>Sun, 03 May 2009 20:14:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[groovy plugin]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=5</guid>
		<description><![CDATA[I have been using the Groovy plugin for Eclipse for about 18 months now. First let me say thanks to the team who has put it together. I can&#8217;t really complain about any problems since it is a volunteer effort and I haven&#8217;t volunteered. And over the time I have used the plugin it has [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using the <a href="http://groovy.codehaus.org/Eclipse+Plugin">Groovy plugin for Eclipse</a> for about 18 months now.  First let me say thanks to the team who has put it together.  I can&#8217;t really complain about any problems since it is a volunteer effort and I haven&#8217;t volunteered.  And over the time I have used the plugin it has gotten some pretty nice improvements, especially for code refactoring and auto-completion.  It&#8217;s debugging capability has always been good (with a few quirks).  The fact that I can debug scripts as well as regular classes kept me from switching to NetBeans when the major upgrade of that product came out in November without that feature (hmmm&#8230; I see there are some upgrades for NB.  Yet another thing to add to my to-do list to check out).  Overall I find the plugin perfectly capable when writing scripts, especially in small projects.  For writing classes however, especially in a large project or when mixed with Java classes, it&#8217;s a PITA.  </p>
<p>For those that cannot or do not want to move from Eclipse to IDEA or NetBeans, here are a few tips for getting by with the plugin for now:</p>
<p>1) The largest issue is a memory leak.  I posted to the <a href=" http://archive.castor.codehaus.org/lists/org.codehaus.groovy.user/msg/47F67363.9010304@saic.com">groovy user list</a> about it over a year ago.  (My explanation of the problem in that post was slightly incorrect.  The problem will occur in any project with a lot of classes on the class path, not just one that includes another project.)  I think the issue has gotten better in some circumstances, but it still makes it impossible for me to easily integrate groovy classes into my major projects.<br /><span style="font-weight:bold;">Work Around:</span> I have a small &#8220;GroovySandbox&#8221; project that has the class directory and key required libraries from my main project on its classpath.  (Do not include the main project as a dependent project because you will have the exact same memory problem.) I write new scripts and classes in this project and then when they are ready, I copy them into the main project.  The memory issue still has an affect, but I can work a full day on groovy files without having to restart eclipse rather than having to restart every 20-30 minutes.</p>
<p>2) Whenever I modify the class path of a project that includes groovy classes (thus triggering a clean build by Eclipse), the groovy class files are wiped with everything else and are not regenerated.  I have to go in and touch each groovy class to get it to compile.<br /><span style="font-weight:bold;">Work Around:</span> I now have enough groovy classes that this isn&#8217;t feasible, so I created an ant target that compiles only the groovy classes and I trigger it from within Eclipse when necessary.  Eclipse detects the newly generated class files and the remaining java classes I have that are dependent on the groovy classes finish compiling.  (Why do I have to mix groovy and java so much?  See #1, above and #3, below.  Unless I want to take advantage of groovy syntax features a lot, I stick with Java.) </p>
<p>3. When I open a groovy class in the editor, it often doesn&#8217;t populate the Outline view.  Makes it hard to navigate the file.<br /><span style="font-weight:bold;">Work Around:</span> Touch the file, or add-and-delete a space.  This was a pain when using CVS for our SCM since the files were  tagged as modified, but since switching to Subversion there hasn&#8217;t been a problem.  I guess Subversion uses something beyond file dates to track mods.</p>
<p>4. When debugging, if I try to step into a class (java or groovy) that is included from another project (which I do frequently since nearly all classes are in the main project due to #1, above), I get an error window saying that the class is part of the Groovy Libraries plugin path and that the path is not modifiable.  The screen doesn&#8217;t give you a button to modify the source lookup path for the directory/jar. (This one is relatively new.  It started happening in some update around the beginning of the year.)<br /><span style="font-weight:bold;">Work Around:</span> Go into the project properties->Java Build Path->Libraries and manually set the &#8220;Source Attachment&#8221; property for the offending directory/jar.  The next time you start the debugger, it will let you step in without a problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/05/03/eclipe-groovy-plugin-decent-for-scripts-pita-for-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Groovy Categories vs ExpandoMetaClass</title>
		<link>http://swordsystems.com/2009/04/29/groovy-categories-vs-expandometaclass/</link>
		<comments>http://swordsystems.com/2009/04/29/groovy-categories-vs-expandometaclass/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 19:23:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[category]]></category>
		<category><![CDATA[ExpandoMetaClass]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[unit test]]></category>

		<guid isPermaLink="false">http://swordsystems.com/?p=4</guid>
		<description><![CDATA[I first saw Groovy in Nov 2007 and promptly decided to dive in over my head and write a DSL in it. One thing that I never quite got was why one would want to use a Category versus ExpandoMetaClass. Having to create a class with a bunch of static methods and then surround other [...]]]></description>
			<content:encoded><![CDATA[<p>I first saw Groovy in Nov 2007 and promptly decided to dive in over my head and write a DSL in it.  One thing that I never quite got was why one would want to use a Category versus ExpandoMetaClass.  Having to create a class with a bunch of static methods and then surround other classes in it didn&#8217;t seem very elegant.  Directly adding behavior to a class with an ExpandoMetaClass is much more straightforward.  I thought that the Category approach must be a hold over from Groovy releases prior to 1.5 when ExpandoMetaClass was added.  The only use case I could come up with for them was if you wanted to add the same functionality to a set of classes &#8211; sort of an AOP view of things.</p>
<p>But then Groovy 1.6 came out and I saw that the team had added some very cool annotations to make categories even more powerful and easier to use.  (See <a href="http://www.infoq.com/articles/groovy-1-6 ">InfoQ </a>for a great write up of the 1.6 features.)  Okay &#8211; you don&#8217;t improve a dead feature, so what was I missing?</p>
<p>This past weekend I got a chance to ask the person from whom I first learned about Groovy, Scott Davis.  His Blue Pill and Red Pill talks at NFJS were what first got my mind churning about the possibilities that Groovy opened up.  Before sitting in on another of his talks at the most recent NFJS conference this past weekend, I asked him why one would use categories in a DSL rather than modifying meta classes? His answer told me that I was asking the wrong question.  The strength of categories is in scoping &#8211; modifying behavior for a limited period of time.  The primary example he gave was for unit tests.  A category can short circuit certain behavior (like retrieving info from a DB or from a file) to make it easier to test certain behavior in isolation.  This makes a lot of sense.  Mocks/stubs have their place;  they are useful when you need to work with an object in a very limited sense &#8211; just a few calls.  Then there are times when you want a real object doing 95% of what it is supposed to do, but you want to take over in just a few situations to be able to insert custom behavior.  e.g. in a unit test when you want to short circuit network or file-based activity or you want to purposefully force an error condition.</p>
<p>It so happens that I really need to improve the unit tests for some network-based components in the ETL system that I work with.  The primary one is called GetHttpContent, so you can imagine that unit testing it can be a pain.  I&#8217;ll give Categories a closer look to see if they can help me out.  Unfortunately, I have to wait until we finish shifting to a our new project structure because right now there are so many dependencies in the primary project that if I work on a groovy file in that project in Eclipse I lose ~20M of memory every time I edit it.  But the limitations (and benefits) of the Eclipse groovy plugin can wait for another post.</p>
]]></content:encoded>
			<wfw:commentRss>http://swordsystems.com/2009/04/29/groovy-categories-vs-expandometaclass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

