<?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>Xebia Blog &#187; Tools</title>
	<atom:link href="http://blog.xebia.com/category/tools/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com</link>
	<description>Software development done right!</description>
	<lastBuildDate>Wed, 01 Feb 2012 00:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Why Application Release Automation needs a Release and an Operations view</title>
		<link>http://blog.xebia.com/2012/02/01/why-application-release-automation-needs-a-release-and-an-operations-view/</link>
		<comments>http://blog.xebia.com/2012/02/01/why-application-release-automation-needs-a-release-and-an-operations-view/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 00:30:00 +0000</pubDate>
		<dc:creator>Andrew Phillips</dc:creator>
				<category><![CDATA[Continuous Delivery]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Methodology]]></category>
		<category><![CDATA[Middleware]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Xebia Labs]]></category>
		<category><![CDATA[application release automation]]></category>
		<category><![CDATA[continuous delivery]]></category>
		<category><![CDATA[devops]]></category>

	<!-- AutoMeta Start -->
	<category>myapplication</category>
	<category>myapplication</category>
	<category>perspectives</category>
	<category>prod</category>
	<category>devops</category>
	<category>delivery</category>
	<category>owned</category>
	<category>pipeline</category>
	<category>myapplication</category>
	<category>myapplication</category>
	<category>perspectives</category>
	<category>prod</category>
	<category>devops</category>
	<category>delivery</category>
	<category>owned</category>
	<category>pipeline</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=8559</guid>
		<description><![CDATA[As the interface between Development and Operations, Application Release Management1 handles information that is highly relevant to your Release and Operations teams. Selecting an Application Release Automation solution that provides insight and analytics from both perspectives is thus a key component of an effective DevOps strategy. Here, we explain how Deployit&#8216;s Infrastructure and new Release [...]]]></description>
			<content:encoded><![CDATA[<p>As the interface between Development and Operations, Application Release Management<sup>1</sup> handles information that is highly relevant to your Release and Operations teams. Selecting an Application Release Automation solution that provides insight and analytics from <em>both</em> perspectives is thus a key component of an effective DevOps strategy.</p>
<p>Here, we explain how <a href="http://www.xebialabs.com/tour" target="_new">Deployit</a>&#8216;s Infrastructure and new Release Overview features help you achieve this goal.<br />
<span id="more-8559"></span></p>
<h3>Continuous Delivery &#038; the Release Perspective</h3>
<p>In today&#8217;s highly competitive economic environment, the need to bring new features to market quickly, flexibly and reliably is paramount &#8211; a goal that is ultimately the aim of the main IT trends Cloud, Agile and DevOps.</p>
<p>Continuous Delivery &#8211; extending <a href="/2010/10/12/deployment-automation-vs-build-automation/" target="_new">Continuous Integration</a> to  automatically transition applications down the <em>Dev-Test-Acc-Prod</em> delivery pipeline &#8211; is a key component of this strategy. In order to be able to effectively implement this, your ARA solution needs to allow your developers &#8211; or, in larger organisations, release or DevOps teams, to quickly and efficiently answer questions such as:</p>
<ul>
<li><strong>How far is <em>MyApplication</em> down the road to Production?</strong></li>
<li><strong>When will <em>MyApplication</em> take the next step down the road?</strong></li>
<li><strong>What do I still need to do before that next step can be taken<sup>2</sup>?</strong></li>
</ul>
<p><img src="http://blog.xebialabs.com/wp-content/uploads/2012/01/two-perspectives-release1.png" alt="" title="two-perspectives-release" class="aligncenter size-full wp-image-8347" /></p>
<p>Ideally, this dashboard would also allow you to plan <em>MyApplication</em>&#8216;s next step and calculate the estimated go-live data, perhaps even based on an analysis of previews versions of <em>MyApplication</em>.</p>
<h3>(Virtual) Environment Management &#038; the Operations Perspective</h3>
<p>From an Operations point of view, an individual application is only a small part of the picture. Across your <em>Dev-Test-Acc-Prod</em> landscape, you will need to track <em>all</em> applications vying for these environments, to manage potentially conflicting resource requests, plan environment maintenance activities and the like.</p>
<p>Since these environments are often owned and managed by different teams and certainly have varying service levels, you will also want to limit your view to one or a subset of these environments at a time.</p>
<p>Your Operations or DevOps teams need to know:</p>
<ul>
<li><strong>Which application versions are currently deployed to my environment(s), or were deployed at a certain point in time?</strong></li>
<li><strong>Which components do these applications consist of? On which middleware and infrastructure systems are these components deployed?</strong></li>
<li><strong>What are the current values of any properties or settings for these components? Which environment-specific customizations have been applied?</strong></li>
</ul>
<p><img src="http://blog.xebialabs.com/wp-content/uploads/2012/01/two-perspectives-ops1.png" alt="" title="two-perspectives-release" class="aligncenter" /></p>
<p>Cloud and the on-demand environments it enables will eventually replace the rigid <em>Dev-Test-Acc-Prod</em> distinction<sup>3</sup>. Nevertheless, the ability to present an environment-centric view will still be required, since virtual environments will still be owned by different groups or teams. Indeed, such a perspective will be even <em>more</em> important if you want to effectively combat &#8220;virtual sprawl&#8221;.</p>
<p>While the coming generations of &#8220;true&#8221; cloud architectures will hopefully reduce the shared resource conflicts that greatly complicate much of today&#8217;s <em>Dev-Test-Acc-Prod</em> management, databases, legacy systems and external payment providers are not likely to disappear anytime soon.</p>
<p>In fact, Facebook, Twitter and other social elements of your future business services may even <em>increase</em> the number of shared resources you need to manage!</p>
<h3>Incorporating ARA Data in the Service Delivery Picture</h3>
<p>Whilst your ARA solution should be your &#8220;go-to&#8221; platform for answers about how your applications and environments relate, it is equally important to consider when this data might be more effectively embedded in a broader service delivery picture. </p>
<p>For example, your ARA platform is not a good candidate for providing a release calendar, since it is not aware of much of the information that is relevant in this context, such as CAB<sup>4</sup> meeting schedules, business sign-off dates or operational maintenance windows.</p>
<p>It is thus important to ensure that your ARA solution can make its data accessible via APIs such as RSS feeds, iCal calendars and other APIs, to enable effective integrations with the rest of your service delivery tooling.</p>
<h3>Conclusion</h3>
<p>The right Application Release Automation platform gives your Delivery and Operations teams fast, accurate insight into your application environments and delivery pipeline. </p>
<p>Choosing a solution like <a href="http://www.xebialabs.com/tour" target="_new">Deployit</a> with focused Operations and Delivery overviews as well as open APIs for easy integration into your overall Service Delivery dashboards and reports greatly enhances the accessibility and effectiveness of your application release management.</p>
<div style="background-color: #efeeea; border: 1px solid #AAAAAA; margin: 0.8em; padding: 0.4em; font-size: 85%;"><strong>Footnotes</strong></p>
<ol>
<li>a.k.a. <em>Deployment Automation</em> &#8211; choose your favourite <img src='http://blog.xebia.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
<li>For instance, certain blocking release conditions, such as test sign-off, may still need to be met.</li>
<li>and have long done so in many forward-looking organisations</li>
<li><a href="http://en.wikipedia.org/wiki/Change_Advisory_Board" target="_new"><strong>C</strong>hange <strong>A</strong>dvisory <strong>B</strong>oard</a></li>
</ol>
</div>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2012/02/01/why-application-release-automation-needs-a-release-and-an-operations-view/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2012%2F02%2F01%2Fwhy-application-release-automation-needs-a-release-and-an-operations-view%2F&amp;title=Why%20Application%20Release%20Automation%20needs%20a%20Release%20%3Cem%3Eand%3C%2Fem%3E%20an%20Operations%20view" id="wpa2a_2"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2012/02/01/why-application-release-automation-needs-a-release-and-an-operations-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Taking Application Release Automation to the Next Level</title>
		<link>http://blog.xebia.com/2011/11/29/taking-application-release-automation-to-the-next-level/</link>
		<comments>http://blog.xebia.com/2011/11/29/taking-application-release-automation-to-the-next-level/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 18:54:29 +0000</pubDate>
		<dc:creator>Andrew Phillips</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Middleware]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Xebia Labs]]></category>
		<category><![CDATA[application release automation]]></category>
		<category><![CDATA[continuous deployment]]></category>
		<category><![CDATA[deployment automation]]></category>

	<!-- AutoMeta Start -->
	<category>standardisation</category>
	<category>outs</category>
	<category>intelligence</category>
	<category>adopters</category>
	<category>generation</category>
	<category>standardisation</category>
	<category>outs</category>
	<category>intelligence</category>
	<category>adopters</category>
	<category>generation</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=8147</guid>
		<description><![CDATA[Whether the driver is Agile, Cloud or DevOps1, or a &#8220;plain old&#8221; efficiency drive or process improvement initiative, forward-thinking organisations are currently looking for ways to improve their application release processes through automation. In an area where manual activities are still all too common, it&#8217;s unsurprising that the initial focus has been on automating the [...]]]></description>
			<content:encoded><![CDATA[<p>Whether the driver is Agile, Cloud or DevOps<sup>1</sup>, or a &#8220;plain old&#8221; efficiency drive or process improvement initiative, forward-thinking organisations are currently looking for ways to improve their application release processes through automation. In an area where manual activities are still all too common, it&#8217;s unsurprising that the initial focus has been on automating the deployment <em>execution</em> &#8211; moving all the bits to the right places.</p>
<p>What early adopters have learnt is that, at the enterprise scale, automating release execution quickly introduces a new bottleneck in today&#8217;s dynamic IT environments: continuous management of the deployment plan definition. A new generation of application release automation (ARA) tooling avoids this pitfall by leveraging intelligence to automate deployment <em>planning</em> as well as execution.<br />
<span id="more-8147"></span></p>
<h3>The State of ARA</h3>
<div style="padding: 5px; float: right;">
<img src="http://blog.xebialabs.com/wp-content/uploads/2011/11/ara_next_level-11.jpg" alt="" title="ara_next_level-1" width="200" height="159" class="alignnone size-full wp-image-6003" />
</div>
<p>Given how strongly our IT industry is dedicated to the automation of processes, it is nothing short of amazing how much of the deployment of <em>our own solutions</em> depends on manual actions coordinated more or less effectively between large groups of people.<br />
Indeed, a recent analyst report noted that the majority of large enterprises were still relying on manual application release processes or on in-house scripting understood by only a small number of specialists, operated as a black box that &#8211; hopefully &#8211; will do its job and will most likely necessitate a painful troubleshooting session if it doesn&#8217;t.</p>
<p>With key IT trends such as Agile, Cloud and DevOps dramatically ramping up the frequency of application releases in order to increase responsiveness to business needs and provide more and better services to customers, it&#8217;s clear that this situation cannot continue. </p>
<p>Thinking of today&#8217;s common release processes, it is also hardly surprising that the initial drive has been to automate the actual <a href="http://blog.xebialabs.com/2010/12/20/deployment-automation-vs-server-provisioning/" target="_new">rollout of the application</a> itself: copying the files to the target machines, restarting the servers, running the SQL against the DB etc. Using a defined workflow to organise these activities makes lots of sense: fewer failures, no more missing steps or steps executed in the wrong order, no more typos, better visualization etc.</p>
<h3>Lessons from the First Generation</h3>
<div style="padding: 5px; float: right;">
<img src="http://blog.xebialabs.com/wp-content/uploads/2011/11/ara_next_level-2.png" alt="" title="ara_next_level-2" width="200" height="143" class="alignnone size-full wp-image-6001" />
</div>
<p>Ironically, using one of these first generation ARA tools at an enterprise scale quickly made it obvious to early adopters how much effort is required to maintain the substantial number of workflow definitions that quickly accumulate to support full deployments, partial upgrades, rollbacks, environment scale-outs etc. across an enterprise application portfolio.</p>
<p>Of course, this is not a new challenge: ask anyone who has had to update 100 build job definitions in a continuous integration tool to change a compilation parameter, or 100 test plans in an automated testing setup to accommodate a different target browser, just how time-consuming and error-prone this type of maintenance is.</p>
<p>It&#8217;s not as though these modifications are <em>unique per process</em>. They tend to be <u>systematic</u> changes that reflect changes to the overall deployment strategy and/or context. The issue is that these first-generation tools, where all the deployment <em>intelligence</em> is stored in the power user&#8217;s brain, simply do not have enough internal <em>knowledge</em> of the structure of deployment to assist effectively.</p>
<h3>The Next Level of Application Release Automation</h3>
<div style="padding: 5px; float: right;">
<img src="http://blog.xebialabs.com/wp-content/uploads/2011/11/ara_next_level-3.jpg" alt="" title="ara_next_level-3" width="200" height="189" class="alignnone size-full wp-image-6004" />
</div>
<p>A new generation of Application Release Automation includes this intelligence. These advanced tools<sup>2</sup> no longer require hand-holding by your power users every step of the way, and encode knowledge of deployment best practices and strategies to automate the planning <em>and</em> execution of deployments.<sup>3</sup></p>
<p>No pre-provided strategy can be a 100% fit in an enterprise environment, so the strategies must be configurable, of course. Once your power users have fine-tuned them, however, all the individual deployment plans &#8211; initial installations, full and partial upgrades, downgrades, undeployments, scale-outs etc&#8230;easily hundreds across an application portfolio &#8211; are automatically tailored to your scenario.</p>
<p>This becomes even more efficient the fewer deployment strategies are in play, so these tools also motivate and reward increased standardisation of deployment procedures, in itself a valuable business goal. In fact, with a suitable interface and integrations into the development pipeline you essentially have an enterprise <a href="http://en.wikipedia.org/wiki/Cloud_computing#Platform" target="_new">Platform as a Service</a>, potentially on a private or hybrid cloud.</p>
<h3>Conclusions</h3>
<p>With adoption of Application Release Automation rapidly on the increase, a new generation of solutions are appearing that automate deployment planning as well as execution.<br />
Based on the challenges experienced in scaling the first generation of ARA tools to enterprise levels, these next generation solutions are designed to eliminate &#8220;continuous expert hand-holding&#8221;, promote standardisation and allow organisations to create a &#8220;software factory&#8221; that continuously delivers business value.</p>
<div style="background-color: #efeeea; border: 1px solid #AAAAAA; margin: 0.8em; padding: 0.4em; font-size: 85%;"><strong>Footnotes</strong></p>
<ol>
<li>My spelling preference is <u>still</u> for &#8220;Devops&#8221; since the whole point is, after all, that Dev and Ops are <em>no longer</em> regarded as separate, but hey&#8230; <img src='http://blog.xebia.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
<li>like XebiaLabs&#8217; <a href="http://www.xebialabs.com/tour" target="_new">Deployit</a></li>
<li><a href="http://blog.xebialabs.com/2011/05/03/deployment-is-the-new-build-part-1/" target="_new">This advance</a> closely mirrors the development of build frameworks from tools like <a href="https://ant.apache.org/" target="_new">Ant</a> to today&#8217;s industry standards like <a href="https://maven.apache.org/" target="_new">Maven</a> and on to the next generation of <a href="http://www.gradle.org/" target="_new">Gradle</a>, <a href="https://github.com/harrah/xsbt/wiki/" target="_new">SBT</a> and others.</li>
</ol>
</div>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/11/29/taking-application-release-automation-to-the-next-level/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F11%2F29%2Ftaking-application-release-automation-to-the-next-level%2F&amp;title=Taking%20Application%20Release%20Automation%20to%20the%20Next%20Level" id="wpa2a_4"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/11/29/taking-application-release-automation-to-the-next-level/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integration testing CloudBees&#8217; RUN@cloud</title>
		<link>http://blog.xebia.com/2011/08/03/integration-testing-cloudbees-runcloud/</link>
		<comments>http://blog.xebia.com/2011/08/03/integration-testing-cloudbees-runcloud/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 05:30:50 +0000</pubDate>
		<dc:creator>Andrew Phillips</dc:creator>
				<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Google AppEngine]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Middleware]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[jclouds]]></category>

	<!-- AutoMeta Start -->
	<category>tweetstore</category>
	<category>cloudbees</category>
	<category>cloudbees</category>
	<category>jclouds</category>
	<category>idletimer</category>
	<category>staxsdkappserver</category>
	<category>googledevserver</category>
	<category>timer</category>
	<category>tweetstore</category>
	<category>cloudbees</category>
	<category>cloudbees</category>
	<category>jclouds</category>
	<category>idletimer</category>
	<category>staxsdkappserver</category>
	<category>googledevserver</category>
	<category>timer</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=7040</guid>
		<description><![CDATA[As part of the preparations for the recent 1.0.0 release of jclouds, I was tidying up the existing Tweetstore demo application as well as porting it to CloudBees&#8217; Tomcat-based RUN@cloud platform. A key part of the test harness for the original versions of Tweetstore that run on the Google App Engine is the neat GoogleDevServer [...]]]></description>
			<content:encoded><![CDATA[<p>As part of the preparations for the recent <a href="http://anyweight.blogspot.com/2011/06/jclouds-100-is-out.html" target="_new">1.0.0 release</a> of <a href="http://www.jclouds.org/" target="_new">jclouds</a>, I was tidying up the existing <a href="http://anyweight.blogspot.com/2009/10/save-your-tweets-forever-with-jclouds.html" target="_new">Tweetstore</a> demo application as well as <a href="http://tweetstore.jclouds.cloudbees.net" target="_new">porting it</a> to CloudBees&#8217; Tomcat-based <a href="http://www.cloudbees.com/run.cb" target="_new">RUN@cloud</a> platform.</p>
<p>A key part of the test harness for the <a href="https://jclouds-tweetstore.appspot.com/" target="_new">original</a> <a href="https://jclouds-tweetstore-spring.appspot.com/" target="_new">versions</a> of Tweetstore that run on the <a href="https://code.google.com/appengine/docs/whatisgoogleappengine.html" target="_new">Google App Engine</a> is the neat <a href="https://github.com/jclouds/jclouds/blob/master/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java" target="_new">GoogleDevServer</a> class. Basically, it&#8217;s a clever wrapper around the <tt>KickStart</tt> class used under the covers by the <a href="https://code.google.com/appengine/downloads.html#Google_App_Engine_SDK_for_Java" target="_new">GAE SDK tools</a> that allows you to specify the SDK location, address, port and WAR file (or expanded WAR directory) to run.<br />
Better still, it can programmatically be shut down cleanly, making it ideal for integration test runs<sup>1</sup>.</p>
<p>For CloudBees, I was thus looking to put together a similar <a href="https://github.com/jclouds/jclouds/blob/master/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RunAtCloudServer.java" target="_new">RunAtCloudServer</a>. It proved more challenging than expected&#8230;<sup>2</sup><br />
<span id="more-7040"></span></p>
<h3>Just spawn a container already?</h3>
<p>Both the <a href="http://www.kindleit.net/maven_gae_plugin/" target="_new">maven-gae-plugin</a> and the <a href="https://cloudbees.zendesk.com/entries/421064-maven-guide" target="_new">bees-maven-plugin</a> allow you to spawn a local GAE or RUN@cloud server simulation, of course. These can easily be integrated into your Maven build, for instance as part of your <tt>pre-integration-test</tt> setup. So why not just stick with that?</p>
<p>Well, for some scenarios that can be perfectly sufficient. For Tweetstore, having an inline server that cleanly shuts down allows us to:</p>
<ul>
<li>run integration tests alongside unit tests from an IDE without having to remember to start an external process</li>
<li>debug the application running in the server on demand, without having to mess with remote debuggers or figure out a way to <em>sometimes</em> get the Maven plugins to start in debug mode</li>
<li>work some conditional magic with the server arguments</li>
</ul>
<p>If your project&#8217;s requirements are similar, an inline server might be a good option. And luckily, the code&#8217;s already been written!</p>
<h3>Hangin&#8217; around</h3>
<div style="padding: 5px; float: right;"><img src="http://blog.xebia.com/wp-content/uploads/2011/06/zombies.png" alt="" title="zombies" width="266" height="173" class="alignnone size-full wp-image-7044" /></div>
<p>The <a href="https://cloudbees.zendesk.com/entries/414109-cloudbees-sdk" target="_new">RUN@cloud SDK&#8217;s</a> version of <tt>KickStart</tt> is the <tt>StaxSdkAppServer</tt><sup>3</sup>. Figuring out the correct arguments for the <tt>launchServer</tt> factory method wasn&#8217;t too hard, so I hooked up a <tt>StaxSdkAppServer</tt> and kicked off the test. </p>
<p>Started like a charm! Then the test finished and&#8230;just hung on in there. Over in the trusty debugger<sup>4</sup>, I could see not one, but <em>two</em> zombie threads still running. The design was based on a &#8220;shutdown-by-JVM-kill&#8221; scenario, I guess.</p>
<h3>Assassins and other Ninja Tricks</h3>
<p>The first of the two threads is a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Timer.html" target="_new">Timer</a> that something called the <tt>WebAppEngine</tt> uses to do&#8230;well, who knows? In any case, we can get a reference to it with a decent handful of reflection and <a href="http://download.oracle.com/javase/6/docs/api/java/util/Timer.html#cancel()" target="_new">cancel</a> it. Easy enough.</p>
<p>Our remaining zombie is a bit more elusive, unfortunately. It&#8217;s a thread spawned by an instance of the <tt>RequestMonitorValve</tt> class in a manner analogous to</p>
<pre class="brush: java; title: ; notranslate">
new Thread(idleTimer, &quot;requestMonitor&quot;).start();
</pre>
<p>So no reference, and no way of interrupting it. However, the <tt>idleTimer</tt> <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Runnable.html" target="_new">Runnable</a> <em>is</em> referenced <em><u>and</u></em> repeatedly calls a handler as part of its execution. How about injecting a handler that throws an exception to end the thread?</p>
<p>Nice idea, but it turns out the thread really doesn&#8217;t want to die that way:</p>
<pre class="brush: java; title: ; notranslate">
while(true) {
    try {
        // do stuff
        if(callbackClient != null)
            callbackClient.updateStatus(state);
    } catch(Exception e) {
        // increment some error counters
    }

    try {
        Thread.sleep(statusIntervalSecs * 1000);
    } catch(InterruptedException interruptedexception) { }
}
</pre>
<p>So I&#8217;ve had to go one better and throw a <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ThreadDeath.html" target="_new">ThreadDeath</a> <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Error.html" target="_new">error</a> instead. Urgh.</p>
<h3>Now you see it, now you don&#8217;t?</h3>
<p>The remaining gotcha involves injecting the catchily-named <tt>KillerCallback</tt> into the <tt>idleTimer</tt>. Even using reflection, this is a elementary concurrency failure because without a <a href="http://java.sun.com/docs/books/jls/third_edition/html/memory.html#64058" target="_new">synchronized-with relationship</a><sup>5</sup> between injecting the new handler and invocation of the handler by <tt>idleTimer</tt>, there is no guarantee the new handler will actually be visible to the thread we&#8217;re trying to stop.</p>
<p>Such a relationship <em>could</em> be established if the &#8220;assassin&#8221; was injected <em>before</em> the thread that runs <tt>idleTimer</tt> starts. Unless we want to override library classes, that would mean setting it after creating but before starting the <tt>StaxSdkAppServer</tt><sup>6</sup>&#8230;which unfortunately doesn&#8217;t work either because the instances referencing <tt>idleTimer</tt> are only created when the server starts.</p>
<h3>So?</h3>
<p>So, for now the potential concurrency issue is documented and we hope for the best <img src='http://blog.xebia.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  No problems observered so far&#8230;</p>
<div style="background-color: #EFEEEA; border: 1px solid #AAAAAA; margin: 0.8em; padding: 0.4em; font-size: 85%;">
<strong>Footnotes</strong></p>
<ol>
<li>The <a href="http://www.kindleit.net/maven_gae_plugin/" target="_new">maven-gae-plugin</a> is another nice option for <em>starting</em> the SDK&#8217;s local GAE simulation. The advantage of <tt>GoogleDevServer</tt> is that it also <em>stops</em> cleanly, can be run from your IDE and also allows you to add additional files to the WAR before starting. Tweetstore uses that to include login credentials to various cloud storage providers &#8211; not the kind of thing you&#8217;re likely to want to store in Github <img src='http://blog.xebia.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
<li>but see <a href="http://www.youtube.com/watch?v=cKO0RrM7LvI" target="_new"><strong>here</strong></a></li>
<li>CloudBees <a href="http://www.cloudbees.com/acquisitions/stax/" target="_new">acquired Stax</a> in December 2010</li>
<li><em>This</em> is when being able to run from an IDE really comes into its own!</li>
<li>as provided e.g. by <strong><tt>volatile</tt></strong></li>
<li>Actually, the code uses an almost exact clone called <a href="https://github.com/jclouds/jclouds/blob/master/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/StaxSdkAppServer2.java" target="_new">StaxSdkAppServer2</a> that simply splits creating the server instance from starting it.</li>
</ol>
</div>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/08/03/integration-testing-cloudbees-runcloud/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F08%2F03%2Fintegration-testing-cloudbees-runcloud%2F&amp;title=Integration%20testing%20CloudBees%26%238217%3B%20RUN%40cloud" id="wpa2a_6"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/08/03/integration-testing-cloudbees-runcloud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get your webtests in FitNesse with Xebium</title>
		<link>http://blog.xebia.com/2011/06/01/get-your-webtests-in-fitnesse-with-xebium/</link>
		<comments>http://blog.xebia.com/2011/06/01/get-your-webtests-in-fitnesse-with-xebium/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 05:37:09 +0000</pubDate>
		<dc:creator>Arjan Molenaar</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Xebium]]></category>
		<category><![CDATA[Acceptance Testing]]></category>
		<category><![CDATA[Agile Testing]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Webtesting]]></category>

	<!-- AutoMeta Start -->
	<category>xebium</category>
	<category>selenium</category>
	<category>fitnesse</category>
	<category>fixture</category>
	<category>verifytext</category>
	<category>login</category>
	<category>password</category>
	<category>john</category>
	<category>xebium</category>
	<category>selenium</category>
	<category>fitnesse</category>
	<category>fixture</category>
	<category>verifytext</category>
	<category>login</category>
	<category>password</category>
	<category>john</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6904</guid>
		<description><![CDATA[In the first installment on Xebium, Cirilo explained the ideas behind this FitNesse fixture: Xebium creates a simple way to use Selenium IDE (low learning curve) and FitNesse (ease of maintenance) to it&#8217;s fullest when it comes to maintaining a web application test suites. Xebium is using the same keywords as Selenium IDE. This has [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="/2011/05/introduction-to-xebium/">first installment on Xebium</a>, Cirilo explained the ideas behind this <a href="http://fitnesse.org">FitNesse</a> fixture:</p>
<blockquote><p><i><br />
<a href="http://xebia.github.com/Xebium">Xebium</a> creates a simple way to use Selenium IDE (low learning curve) and FitNesse (ease of maintenance) to it&#8217;s fullest when it comes to maintaining a web application test suites.<br />
</i></p></blockquote>
<p>Xebium is using the same keywords as Selenium IDE. This has the huge advantage that no person should learn another DSL. Since tests are stated this way, they can be copied between Selenium IDE and FitNesse without a hassle (the FitNesse formatter for Selenium IDE is rather trivial). And to be honest: as long as there are XPath and Regular Expressions in the code, it makes no sense to come up with a substitute for <quote>verifyText</quote>.</p>
<p><span id="more-6904"></span></p>
<p><img src="http://blog.xebia.com/wp-content/uploads/2011/05/ide-to-fitnesse.png" alt="Copy test output directly in SeIDE" /></p>
<p>So now it is possible to move our Selenium IDE test case in a FitNesse page. Nice. It&#8217;s easier to set up tests, since FitNesse is quite flexible in that. On the other hand, just playing back you recorded tests is not the most flexible way to work. There can be a huge maintenance burden on this.  It would be a shame not to use the full power of FitNesse in this case. <a href="http://fitnesse.org/FitNesse.UserGuide.SliM.ScenarioTable">Scenario tables</a> for example can make a nice abstraction where some common action, like logging in, only have to be defined (and maintained) in one place. By moving the login code out of the test and into a scenario, we add another level of indirection. The tests themselves become more readable, as they only state the business requirement and the low level details are directly editable by the tester. This is a lot more flexible than creating Selenium fixtures for every scenario.</p>
<blockquote><pre>| log in user | <i>user</i> | with password | <i>password</i> |
| open | http://example.com/login |
| type | name-field | <i>@user</i> |
| type | password-field | <i>@password</i> |
| click | login |
</pre>
</blockquote>
<p>and in your tests, instead of repeating the above, just mention:</p>
<blockquote><pre>| script |
| log in user | <i>john</i> | with password | <i>secret</i> |
| ensure | do | verifyText | on | #userid | with | John |</pre>
</blockquote>
<p>Sure, we&#8217;re back at creating our own DSL, but we do it 100% in FitNesse. Selenium commands can be added where needed (e.g. assertions). No Java (fixture) code, no developers required to change one line because the templates have changed and, foremost, detailed feedback.</p>
<p>But FitNesse can help out even more. Consider data driven testing. Selenium has (by default) no option for that. Using the same scenario table fixture it&#8217;s easy to test logins for a bunch of users.</p>
<p>But we claimed you can copy stuff from FitNesse to Selenium IDE as well and that&#8217;s getting harder when you move everything inro scenarios. To overcome this issue the formatter in Selenium IDE can parse tab separated data as well. So after a test has run, the output as provided by FitNesse can be copied back. This is a useful aid for analyzing failed tests.</p>
<p><img src="http://blog.xebia.com/wp-content/uploads/2011/05/fitnesse-to-ide.png" alt="Copy tests from SeIDE to FitNesse" /></p>
<p>I tend to make my Xebium commands easely available. First of all the fixture needs to be imported. After that the fixture can be assigned as library:</p>
<blockquote><pre>| import |
| com.xebia.incubator.xebium |

| library |
| selenium driver fixture |</pre>
</blockquote>
<p>A note for Windows users, though. When performing a lot of tests, Windows tends to run out of sockets. There is a way to <a href="http://twit88.com/blog/2008/07/28/jmeter-exception-javanetbindexception-address-already-in-use-connect/">configure your machine</a> to work around those silly limitations (at your own risk!).</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/06/01/get-your-webtests-in-fitnesse-with-xebium/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F06%2F01%2Fget-your-webtests-in-fitnesse-with-xebium%2F&amp;title=Get%20your%20webtests%20in%20FitNesse%20with%20Xebium" id="wpa2a_8"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/06/01/get-your-webtests-in-fitnesse-with-xebium/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction to Xebium</title>
		<link>http://blog.xebia.com/2011/05/04/introduction-to-xebium/</link>
		<comments>http://blog.xebia.com/2011/05/04/introduction-to-xebium/#comments</comments>
		<pubDate>Wed, 04 May 2011 15:28:42 +0000</pubDate>
		<dc:creator>Cirilo Wortel</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Xebium]]></category>
		<category><![CDATA[Acceptance Testing]]></category>
		<category><![CDATA[Agile Testing]]></category>
		<category><![CDATA[fitnesse]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Webtesting]]></category>

	<!-- AutoMeta Start -->
	<category>xebium</category>
	<category>selenium</category>
	<category>selenesse</category>
	<category>fitnium</category>
	<category>fitnesse</category>
	<category>substitution</category>
	<category>dsl’s</category>
	<category>playback</category>
	<category>xebium</category>
	<category>selenium</category>
	<category>selenesse</category>
	<category>fitnium</category>
	<category>fitnesse</category>
	<category>substitution</category>
	<category>dsl’s</category>
	<category>playback</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6806</guid>
		<description><![CDATA[Introduction When testing web interfaces, it’s convenient to use an intuitive tool like Selenium IDE, it’s easy to use and can be used by non-technical people, but it is solely meant for record and playback of test-scripts. One of its limitations is that it misses sufficient options for documenting and managing tests. Furthermore it misses [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<p>When testing web interfaces, it’s convenient to use an intuitive tool like <a title="Selenium IDE" href="http://seleniumhq.org/projects/ide/">Selenium IDE</a>,  it’s easy to use and can be used by non-technical people, but it is  solely meant for record and playback of test-scripts. One of its  limitations is that it misses sufficient options for documenting and  managing tests. Furthermore it misses an interface with the backend of  the system under test (SUT), to setup preconditions for a test or for  instance to manipulate or read from a database.<br />
<a title="FitNesse" href="http://fitnesse.org/">Fitnesse</a> is a great tool to do just that, it has the Wiki to manage tests and it  by default has a setup and teardown mechanism, it’s easy to add non  invasive testfixtures to interface directly with your SUT. The downside  is that it is incapable of doing webtests.</p>
<p>We now have the glue that combines the two, it&#8217;s called <a title="Xebium" href="http://xebia.github.com/Xebium/">Xebium</a>!</p>
<p><span id="more-6806"></span></p>
<p><img title="More..." src="http://blog.xebia.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" alt="" />On  several projects I’ve tried to find a way to combine the two, because  both tools are free of use and both have their individual charm, but it  seems combined they would master practically any situation. As a tester I  miss the development skills to come up with a satisfying solution and I  never convinced my team members to help me out in a satisfactory  manner.</p>
<p>At our company we recently started <a title="app-incubator" href="http://app-incubator.xebia.com/">app-incubator</a>,  a new form of knowledge exchange, in the form of mini projects, anyone  can pitch a project idea and when enough colleagues sponsor the project,  we can spend up to three days collaborating on it.  My pitch caught  fire and with about five people we brainstormed on the solution. For me a  prerequisite was that it should be possible to use the test scripts two  directional, so record them with Selenium IDE, run and edit them in  Fitnesse and playback from Selenium IDE again. During this first project  session we came up with additional requirements, it should support  data-driven testing and variable substitution. We wanted to keep it as  simple as possible, no new DSL’s should be introduced and it should not  require conversions between the two products. We explored some existing  solutions such as <a title="Fitnium" href="http://sourceforge.net/projects/fitnium/">Fitnium</a> and <a title="Selenesse" href="https://github.com/cdombroski/selenesse">Selenesse</a> but came to the conclusion these (at the time) were fully based on their own DSL’s and did not support exchanging  files between Selenium IDE and Fitnesse. So we decided to created  something far more simple.</p>
<p><strong>The Result</strong></p>
<p>After several attempts we discovered that Webdriver (Selenium 2.0) would  be the best engine for running our tests. It seems more future proof,  turned out to be a lot more stable than Selenium Testrunner and its  commands are more compatible with Selenium IDE than Selenium RC.<br />
We introduced a Selenium IDE formatter which output can be directly  copied into the Wiki. We created a Fitnesse fixture that is capable of  running the pre-formatted scripts without additional interpretations of  the Selenium commands.</p>
<p>The additional features we had in mind, the data-driven testing and  variable substitution turned out to be standard Fitnesse features. What  we did not realize when we started was that Fitnesse would introduce a  mechanism which, in my opinion, added mind-blowing power to project:  Scenario tables, which now enables us to create abstractions on top of  our testscripts.</p>
<p><strong>Conclusion</strong><a title="Xebium" href="http://xebia.github.com/Xebium/"></a></p>
<p><a title="Xebium" href="http://xebia.github.com/Xebium/">Xebium</a> enables us to use both Selenium IDE (low learning curve) and  FitNesse (ease of maintenance) to it&#8217;s fullest and provides a complete  solution when it comes to automated web testing.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/05/04/introduction-to-xebium/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F05%2F04%2Fintroduction-to-xebium%2F&amp;title=Introduction%20to%20Xebium" id="wpa2a_10"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/05/04/introduction-to-xebium/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bundling a Python application on Mac OS X with VirtualEnv</title>
		<link>http://blog.xebia.com/2011/03/31/bundling-a-python-application-on-mac-os-x-with-virtualenv/</link>
		<comments>http://blog.xebia.com/2011/03/31/bundling-a-python-application-on-mac-os-x-with-virtualenv/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 07:27:40 +0000</pubDate>
		<dc:creator>Arjan Molenaar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[osx]]></category>

	<!-- AutoMeta Start -->
	<category>gaphor</category>
	<category>pypi</category>
	<category>virtualenv</category>
	<category>pygtk</category>
	<category>homebrew</category>
	<category>python</category>
	<category>installdir</category>
	<category>eggs</category>
	<category>gaphor</category>
	<category>pypi</category>
	<category>virtualenv</category>
	<category>pygtk</category>
	<category>homebrew</category>
	<category>python</category>
	<category>installdir</category>
	<category>eggs</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6540</guid>
		<description><![CDATA[When it comes to distributing Python packages, Python has its own mechanism. The tooling (either easy_install or pip) allows you to install a Python package and its dependencies. Typically, those packages are installed as Python Eggs (Java has Jars, Ruby has Gems and Python has Eggs). However, one can not expect Mac users to use [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to distributing Python packages, Python has its own mechanism.  The tooling (either <tt>easy_install</tt> or <tt>pip</tt>) allows you to install a Python package and its dependencies. Typically, those packages are installed as Python Eggs (Java has Jars, Ruby has Gems and Python has Eggs). However, one can not expect Mac users to use these command line tools to download and install Python applications, especially GUI applications.</p>
<p><span id="more-6540"></span></p>
<p>How can you package an application, including library dependencies nicely on a Mac? That&#8217;s the task at hand when I  wanted to make <a href="http://gaphor.sourceforge.net">Gaphor</a> available on the Mac platform.</p>
<p>The idea has been there for quite some time, and it became a lot more concrete once I started to compile and install my open source software using <a href="http://github.com/mxcl/homebrew">Homebrew</a>.</p>
<p>In this post I&#8217;ll outline the way Gaphor is packaged for this platform. I started Gaphor quite some years ago on Linux. It&#8217;s written in Python using the <a href="http://gtk.org">GTK+</a> gui library. After I switched to OS X as my main OS, I still work on this project. The X11 server on OS X works pretty well, so nothing holds me back. Except that it&#8217;s hard to share this app with my fellow Mac users.</p>
<p>Gaphor and most of the dependent modules are available as Python eggs from the <a href="http://pypi.python.org">Python Package Index</a>, hence installing it is a simple task.  GTK+ is not available on Mac OS by default and <a href="http://pygtk.org">PyGTK</a> (GTK+&#8217;s Python bindings) is not available as egg, so those have to be installed from source.  I started off with compiling the dependencies (GTK+ and friends) using Homebrew. Homebrew has a big advantage over MacPorts and Fink in that it does not try to do everything itself (build everything from scratch). Instead it tries to use functionality available on the system already (like X11, Python and some basic libs). With <a href="http://github.com/amolenaar/homebrew/tree/pygtk">a fork</a> of Stein Magnus Jodal&#8217;s <a href="http://github.com/jodal/homebrew">Homebrew branch</a> I was able to get GTK+ and PyGTK compiled and installed.</p>
<p>Next step is to get this stuff packages in an application bundle in order to make it available to a broad audience. The de-facto packaging tool, <a href="http://pypi.python.org/pypi/py2app">py2app</a>, is not able to handle eggs. Since Gaphor depends on eggs (the services for running the application are defined in the egg meta data), I had to figure out some other way to package the application, while retaining the egg structure.</p>
<p>I started of creating a simple application structure: a <tt>Gaphor.app</tt> folder, a <tt>Info.plist</tt> file and some additional directories. Next thing is to make this environment Pythonized. The way to to this is to use <a href="http://pypi.python.org/pypi/virtualenv">VirtualEnv</a>. VirtualEnv is a Python tool that helps you set up isolated environments. This can be very handy for example for developing and testing software. A simple </p>
<pre class="brush: bash; title: ; notranslate">
PYVER=2.6
APP=Gaphor.app
INSTALLDIR=$APP/Contents
virtualenv --python=python$PYVER --no-site-packages $INSTALLDIR
</pre>
<p>did the trick.</p>
<p>I needed to install all PyGTK related libraries in the application folder.</p>
<pre class="brush: bash; title: ; notranslate">
LOCALDIR=/usr/local
SITEPACKAGES=$INSTALLDIR/lib/python$PYVER/site-packages
PYTHON_BREWS=&quot;pycairo pygobject pygtk pyrsvg&quot;

for brew in $PYTHON_BREWS; do
  cp -r $LOCALDIR/Cellar/$brew/*/lib/python$PYVER/site-packages/* $SITEPACKAGES
done
</pre>
<p>Where <tt>$SITEPACKAGES</tt> is a directory in the folder that the `virtualenv-ed&#8217; python installation will use to install the site-packages (non-default python modules).</p>
<p>Of course PyGTK won&#8217;t do a thing without the backing of GTK+ itself, so those libraries also had to be packages. To solve this a listing of dependencies for the freshly installed libraries will do. <tt>otool</tt> is able to list all dependencies. Those dependencies can be copied and the paths can be changed to relative paths. Relative paths on OS X, funny enough, relate to the location of the binary that was initially started. In this case Python (which is installed in <tt>Gaphor.app/Contents/bin</tt>).</p>
<pre class="brush: bash; title: ; notranslate">
function resolve_deps() {
  local lib=$1
  local dep
  otool -L $lib | grep -e &quot;^.$LOCALDIR/&quot; |\
      while read dep _; do
    echo $dep
  done
}

function fix_paths() {
  local lib=$1
  log Fixing $lib
  for dep in `resolve_deps $lib`; do
    #log Fixing `basename $lib`
    log &quot;|  $dep&quot;
    install_name_tool -change $dep @executable_path/../lib/`basename $dep` $lib
  done
}

binlibs=`find $INSTALLDIR -type f -name '*.so'`

for lib in $binlibs; do
  log Resolving $lib
  resolve_deps $lib
  fix_paths $lib
done | sort -u | while read lib; do
  log Copying $lib
  cp $lib $LIBDIR
  chmod u+w $LIBDIR/`basename $lib`
  fix_paths $LIBDIR/`basename $lib`
done
</pre>
<p>Some extra resource files had to be installed and that was it for GTK+. The launch script takes care of setting the environment so the application will work. Now the application itself:</p>
<pre class="brush: bash; title: ; notranslate">
$INSTALLDIR/bin/easy_install gaphor
</pre>
<p>That was easy! The latest version will be downloaded from the PyPI and <a href="http://pypi.python.org/pypi/setuptools"><tt>easy_install</tt></a> is installing it. One of the benefits of using virtualenv is that <tt>easy_install</tt> as well as <tt>pip</tt> are installed by default. This makes it very, very easy to install python applications.</p>
<p>You can find the <a href="http://github.com/amolenaar/gaphor-osx-bundle/blob/master/package.sh">full script</a> on GitHub.</p>
<p>It took a while to figure out all the details, but creating an installable app, Mac style, is rather trivial. Next is a Windows installer and something tells me it won&#8217;t be this easy <img src='http://blog.xebia.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/03/31/bundling-a-python-application-on-mac-os-x-with-virtualenv/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F03%2F31%2Fbundling-a-python-application-on-mac-os-x-with-virtualenv%2F&amp;title=Bundling%20a%20Python%20application%20on%20Mac%20OS%20X%20with%20VirtualEnv" id="wpa2a_12"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/03/31/bundling-a-python-application-on-mac-os-x-with-virtualenv/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iOS + XCode 4 + GHUnit = Mobile TDD+Continuous testing part 2 of n</title>
		<link>http://blog.xebia.com/2011/03/23/ios-xcode-4-ghunit-mobile-tddcontinuous-testing-part-2-of-n/</link>
		<comments>http://blog.xebia.com/2011/03/23/ios-xcode-4-ghunit-mobile-tddcontinuous-testing-part-2-of-n/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 10:51:07 +0000</pubDate>
		<dc:creator>Robert van Loghem</dc:creator>
				<category><![CDATA[ios]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools]]></category>

	<!-- AutoMeta Start -->
	<category>ghunit</category>
	<category>xcode</category>
	<category>ghunitios</category>
	<category>simulator</category>
	<category>iphone</category>
	<category>ocunit</category>
	<category>gabriel</category>
	<category>nsstring</category>
	<category>ghunit</category>
	<category>xcode</category>
	<category>ghunitios</category>
	<category>simulator</category>
	<category>iphone</category>
	<category>ocunit</category>
	<category>gabriel</category>
	<category>nsstring</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6482</guid>
		<description><![CDATA[Last time I explained why I think doing TDD for mobile is imperative, and why I do it. But now it&#8217;s time to get technical, and explain to you how to set up, GHUnit in XCode 4 and run unit tests, not only in the iPhone and iPad simulator but also on your own physical [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.xebia.com/2011/03/09/why-tddcontinous-testing-is-imperative-for-mobile-apps-part-1-of-n/">Last time</a> I explained why I think doing TDD for mobile is imperative, and why I do it. But now it&#8217;s time to get technical, and explain to you how to set up, <a href="http://gabriel.github.com/gh-unit/">GHUnit</a> in XCode 4 and run unit tests, not only in the iPhone and iPad simulator but also on your own physical device!, it&#8217;s in text and images but also in <a href='http://www.youtube.com/watch?v=zk2PXso_WHQ'>video form on YouTube</a>.</p>
<p><a href="http://www.youtube.com/watch?v=zk2PXso_WHQ"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/youtubeScreenshot-300x183.png" alt="" title="Video on how to setup GHUnit in XCode 4 on YouTube" width="300" height="183" class="aligncenter size-medium wp-image-6533" /></a></p>
<p><em>Note, if you want to know why i chose GHUnit over OCUnit, just scroll down to the end of the post.</em></p>
<p><span id="more-6482"></span></p>
<p><strong>But wait….</strong></p>
<p>Before I begin, I want to make one thing very clear, the difference between <em>code</em> unit testing and <em>UI</em> testing. Unfortunately, UI development can be hard to do in a TDD fashion. Especially when you want to test UI components. e.g. When I send a TouchEvent will the View respond and trigger my method in my controller.<br />
My advice; don&#8217;t do UI testing with a Unit testing framework (OCUnit, JUnit, GHUnit), do it with for example the <a href="http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40004652">iOS automation API</a>, which has been created specifically to test those UI components. I&#8217;ll also get back to you in a later post on how to do UI testing on Android.</p>
<p>What do you test with Unit testing frameworks? Well you test just the code, nothing more. Model and Controller code, not the View! You might need the help of a mocking framework to make it testable, because the view is missing and needs to be wired up for the controller and model to work properly, or it might need other controllers etc..</p>
<p><strong>Let&#8217;s begin setting up!</strong></p>
<p>With that in mind, let&#8217;s set up our own iPhone XCode 4 project! add GHunit, create a test and run it in the simulator or your own iOS device, iPhone, iPod Touch or iPad.</p>
<p><em>1.</em> First of all download the GHUnitIOS version (0.4.28 at this time) at <a href="https://github.com/gabriel/gh-unit/archives/master">https://github.com/gabriel/gh-unit/archives/master</a><br />
<em>2.</em> Unpack the downloaded zip file somewhere in your home directory, you should get the GHUnitIOS.framework directory</p>
<blockquote><p>NOTE; I first placed it in /Developer/Library/Frameworks but XCode 4 didn&#8217;t like it and when compiling it could not find the header files, therefore I placed them somewhere in my home directory (e.g. /Users/rvanloghem/Development/Frameworks/GHUnitIOS.framework)</p></blockquote>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/ghunitFrameworkDir.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/ghunitFrameworkDir-150x150.png" alt="" title="Place where my GHUnitIOS.framework dir is located" width="150" height="150" class="aligncenter size-thumbnail wp-image-6498" /></a></p>
<p><strong>Right, you are now ready to set up your GHUnit ready XCode 4 project.</strong></p>
<p><em>3.</em> For example purposes, I&#8217;m choosing a normal, navigation-based application but you might have an existing project.<br />
- NOTE; Don&#8217;t check the Include Unit Tests, because we are going to supply our own unit testing framework and not rely on OCUnit, which is supplied by default in XCode</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/selectNewProjectTemplate.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/selectNewProjectTemplate-150x150.png" alt="" title="Select XCode 4 project template" width="150" height="150" class="aligncenter size-thumbnail wp-image-6491" /></a></p>
<p><em>4.</em> In your XCode project settings (blue root icon in the tree browser) add a Target which you can call Tests, i usually base the project on a simple View-based Application (a Target named Tests will be added + a folder named Tests with all the Tests target files in them)</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/addTestsTarget.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/addTestsTarget-150x150.png" alt="" title="Click to add a new target named Tests" width="150" height="150" class="aligncenter size-thumbnail wp-image-6514" /></a></p>
<p><em>5.</em> Next go back to the Tests target (click on the Tests Target) and add the GHUnitIOS.framework which you downloaded and unpacked in step 1 and 2. (click on the Build Phases tab, open up the Link Binary with Libraries, hit the + button, click Add Other and navigate+select the GHUnitIOS.framework directory on your filesystem)<br />
<em>6.</em> Optional, but nice, move the GHUnitIOS.framework in your Tree to the Frameworks folder, to tidy things up</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/addFrameworkToTestsTarget.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/addFrameworkToTestsTarget-150x150.png" alt="" title="Adding the GHUnitIOS framework to the Tests target" width="150" height="150" class="aligncenter size-thumbnail wp-image-6516" /></a></p>
<p>7. Set the -ObjC and -all_load in the other linker flags on the Tests Target (Select the Tests Target, select the Build Settings, search for other linker flags, and add the 2 flags)</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/setOtherLinkerFlags.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/setOtherLinkerFlags-150x150.png" alt="" title="Setting -ObjC and -all_load on the other linker flags in the Tests target" width="150" height="150" class="aligncenter size-thumbnail wp-image-6518" /></a></p>
<p>8. Now you can delete some files which are not necessary, all the files in the Tests folder. (Note, Not! the Supporting Files folder as well, just the files!)<br />
9. Delete the main.m file in the Supporting Files folder</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/deleteTestsFiles.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/deleteTestsFiles-150x150.png" alt="" title="Delete unneeded files from your Tests target" width="150" height="150" class="aligncenter size-thumbnail wp-image-6520" /></a></p>
<p>10. In the Tests-Info.plist file (again, in the Supporting Files folder), clear out the Main nib file base name value</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/clearMainNibName.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/clearMainNibName-150x150.png" alt="" title="Clear value of man nib file base name in the ?-Info.plist file" width="150" height="150" class="aligncenter size-thumbnail wp-image-6519" /></a></p>
<p><strong>Time to create the GHUnit test runner, which will scan for our Unit Test Cases and run them.</strong></p>
<p>11. Create an Objective-C class in the Tests folder named GHUnitIOSTestMain and make sure it is only! added to the Tests target</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/createTestRunner.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/createTestRunner-150x150.png" alt="" title="Create the GHUnitTestRunner main which will run your test cases" width="150" height="150" class="aligncenter size-thumbnail wp-image-6521" /></a></p>
<p>12. You can delete the GHUnitIOSTestMain.h file<br />
13. Copy and paste source code from (http://github.com/gabriel/gh-unit/blob/master/Project-IPhone/GHUnitIOSTestMain.m) in your GHUnitIOSTestMain.m file</p>
<p><strong>And now it&#8217;s time to create our own test case which will fail <img src='http://blog.xebia.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </strong></p>
<p>14. Again create an Objective-C class in the Tests folder and as this is an example, name it ExampleTest, also make sure it is added to the Tests Target only!<br />
15. You can delete the ExampleTest.h file<br />
15. Copy and paste the next piece of code which is 99% copy/pasted from the example code from GHUnit (http://gabriel.github.com/gh-unit/_examples.html)</p>
<pre class="brush: cpp; title: ; notranslate">// For iOS
#import &lt;GHUnitIOS/GHUnit.h&gt;
// For Mac OS X
//#import &lt;GHUnit/GHUnit.h&gt;

@interface ExampleTest : GHTestCase { }
@end

@implementation ExampleTest

- (BOOL)shouldRunOnMainThread {
    // By default NO, but if you have a UI test or test dependent on running on the main thread return YES
    return NO;
}

- (void)setUpClass {
    // Run at start of all tests in the class
}

- (void)tearDownClass {
    // Run at end of all tests in the class
}

- (void)setUp {
    // Run before each test method
}

- (void)tearDown {
    // Run after each test method
}  

- (void)testFoo {
    NSString *a = @&quot;foo&quot;;
    GHTestLog(@&quot;I can log to the GHUnit test console: %@&quot;, a);

    // Assert a is not NULL, with no custom error description
    GHAssertNotNULL(a, nil);

    // Assert equal objects, add custom error description
    NSString *b = @&quot;bar&quot;;
    GHAssertEqualObjects(a, b, @&quot;A custom error message. a should be equal to: %@.&quot;, b);
}

- (void)testBar {
    GHAssertTrue(TRUE, @&quot;Yes it worked&quot;);
}

@end
</pre>
<p><strong>Right, ready to run!</strong></p>
<p>16. Launch your Tests target (iTunes-like play button arrow) and run it against the simulator-scheme and your Unit test app should start</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/readyToRunGHUnit.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/readyToRunGHUnit-150x150.png" alt="" title="Selecting the scheme to run your unit test case and hitting run in XCode 4" width="150" height="150" class="aligncenter size-thumbnail wp-image-6528" /></a></p>
<p>17. Now in the app in the simulator hit the blue run button and your tests will execute. (and testFoo will fail!, you can click on it to see why it failed)</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/runningTheTest.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/runningTheTest-150x150.png" alt="" title="Running the GHUnit test in the iOS iPhone simulator" width="150" height="150" class="aligncenter size-thumbnail wp-image-6529" /></a></p>
<p><strong>And now it&#8217;s time to fix it&#8230;</strong></p>
<p>18. Change the <code>NSString *b = @"bar";</code> in the testFoo method to <code>NSString *b = @"foo";</code><br />
19. Run the Test app again and re-run the test and they should be green or in this case black, which means your tests are ok</p>
<p><strong>Showing the power of GHUnit</strong></p>
<p>20. Run the app against your own iOS device-scheme. (Select iOS-device-scheme and click the iTunes like run button)</p>
<p><a href="http://blog.xebia.com/wp-content/uploads/2011/03/testsRunningActuallyOnThePhone.png"><img src="http://blog.xebia.com/wp-content/uploads/2011/03/testsRunningActuallyOnThePhone-150x150.png" alt="" title="GHUnit running on an actual iPhone 4" width="150" height="150" class="aligncenter size-thumbnail wp-image-6530" /></a></p>
<p><strong>Why i chose GHUnit over OCUnit</strong></p>
<p>IMHO, this shows the real power of the GHUnit testing framework, not only does it run in the simulator but it also runs on your own iPhone, iPad, etc. Whereas OCUnit can only run as part of your build on your own machine, not on your phone and not in the simulator, this for me, is a big dealbreaker.<br />
The closer you can get your unit tests running against a real-world environment the better it will be. Why? Because you are making use of the real devices processor (not the intel x86), real memory management, or lack there-of, the real API&#8217;s etc. If my Unit tests run on my phone, i&#8217;m 99.999% certain that the code under test will actually run on, yes, you guessed it, my phone.</p>
<p>There is of-course a downside to GHUnit, OCUnit (bundled with XCode) can be run automatically prior to you compiling your own app, this makes getting feedback about regression a lot faster, GHUnit is something which you have to run manually, in this case. But to solve that problem, or at least make it a whole lot better, we can use continuous integration aka build server to do the auto-running-of-unit-tests for us. There is a very <a href="http://paulsolt.com/2010/11/iphone-unit-testing-explained-part-1/">nice blog post</a> which compares various iOS unit testing frameworks.</p>
<p>So what is next? Well, the topic for my next blog and video in this series is hooking up a XCode project + GHUnit to Jenkins (or Hudson for the Oracle minded people out there).</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/03/23/ios-xcode-4-ghunit-mobile-tddcontinuous-testing-part-2-of-n/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F03%2F23%2Fios-xcode-4-ghunit-mobile-tddcontinuous-testing-part-2-of-n%2F&amp;title=iOS%20%2B%20XCode%204%20%2B%20GHUnit%20%3D%20Mobile%20TDD%2BContinuous%20testing%20part%202%20of%20n" id="wpa2a_14"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/03/23/ios-xcode-4-ghunit-mobile-tddcontinuous-testing-part-2-of-n/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>JAXB, XML Data Binding</title>
		<link>http://blog.xebia.com/2011/03/17/jaxb-xml-data-binding/</link>
		<comments>http://blog.xebia.com/2011/03/17/jaxb-xml-data-binding/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 06:00:26 +0000</pubDate>
		<dc:creator>yamsellem</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[JAX-RS]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[xpath]]></category>
		<category><![CDATA[XSD]]></category>

	<!-- AutoMeta Start -->
	<category>recipe</category>
	<category>recipe</category>
	<category>cooking</category>
	<category>cooking</category>
	<category>recipe</category>
	<category>recipe</category>
	<category>cooking</category>
	<category>cooking</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6316</guid>
		<description><![CDATA[As an ubiquitous exchange format, XML is well implemented in java. But those implementations hide how they perform the data binding from a XML structure to an object graph. It leaves us helpless in front of an application giving XML as a plain old string. Because low level API (DOM, XPath) — focused on document [...]]]></description>
			<content:encoded><![CDATA[<p>As an ubiquitous exchange format, XML is well implemented in java. But those implementations hide how they perform the data binding from a XML structure to an object graph. It leaves us helpless in front of an application giving XML as a plain old string. Because low level API (DOM, XPath) — focused on document structure — are tedious, major JAX-RS implementation (Jersey, CXF) have chosen the same high level API — focused on data —: <strong>JAXB</strong>. Let&#8217;s do the same.</p>
<p><span id="more-6316"></span></p>
<style><!--
.syntaxhighlighter { padding: 1px !important; }
--></style>
<h3><a name="Describe"></a>Describe an exchange format</h3>
<p>When the output XML producer does not have any mechanism to describe its node structure, its consumers have to choose a way to operate at its best. This can be done with an object graph equivalent to this XML output. Let&#8217;s see this with a delicious dessert example.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;recipe name=&quot;Pear compote&quot; type=&quot;desert&quot;&gt;
    &lt;cooking duration=&quot;15&quot;&gt;
    	&lt;step optional=&quot;true&quot;&gt;Leave aside a vanilla pod&lt;/step&gt;
        &lt;step&gt;Peel and core pears&lt;/step&gt;
        &lt;step&gt;Cut pears into slices&lt;/step&gt;
        &lt;step&gt;Pour those slices in a casserole with water&lt;/step&gt;
    &lt;/cooking&gt;
    &lt;menu&gt;17-02-2011&lt;/menu&gt;
    &lt;menu&gt;17-03-2011&lt;/menu&gt;
&lt;/recipe&gt;
</pre>
<p>JAXB identifies every node as an <em>element</em> with <em>attributes</em>. An element is a complex type with an element sequence (always first) and an attribute list. An element can have a simple text value if it has no sub-node. An attribute has only a text value. Every XML node is represented by an element and, with XJC, an object of the same name generated from the schema (XJC generation is explained in appendix).</p>
<p>Here is the XSD description of the previous XML:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
    &lt;xsd:element name=&quot;recipe&quot;&gt;
        &lt;xsd:complexType&gt;
            &lt;xsd:sequence&gt;
                &lt;xsd:element name=&quot;menu&quot; type=&quot;xsd:string&quot; maxOccurs=&quot;unbounded&quot; /&gt;
                &lt;xsd:element name=&quot;cooking&quot; type=&quot;cooking&quot; /&gt;
            &lt;/xsd:sequence&gt;
            &lt;xsd:attribute name=&quot;name&quot; type=&quot;xsd:string&quot; /&gt;
            &lt;xsd:attribute name=&quot;type&quot; type=&quot;xsd:string&quot; /&gt;
        &lt;/xsd:complexType&gt;
    &lt;/xsd:element&gt;

    &lt;xsd:complexType name=&quot;cooking&quot;&gt;
        &lt;xsd:sequence&gt;
            &lt;xsd:element name=&quot;step&quot; type=&quot;step&quot; maxOccurs=&quot;unbounded&quot; /&gt;
        &lt;/xsd:sequence&gt;
        &lt;xsd:attribute name=&quot;duration&quot; type=&quot;xsd:int&quot; /&gt;
    &lt;/xsd:complexType&gt;

    &lt;xsd:complexType name=&quot;step&quot; mixed=&quot;true&quot;&gt;
        &lt;xsd:attribute name=&quot;optional&quot; type=&quot;xsd:boolean&quot; /&gt;
    &lt;/xsd:complexType&gt;
&lt;/xsd:schema&gt;
</pre>
<p>These schema nodes are prefixed by « xsd » because their definition use a XML Namespace (xmlns) on the first line. Namespaces are a way to differentiate header declarations from one another, as a Java package would do.</p>
<p>Variables are typed following <a href="http://www.w3.org/TR/xmlschema-0/#CreatDt" title="the w3c recommandation" >the w3c recommandation</a>. When a primitive typed list is used (menu node), no new object is needed. However, an object is needed (step node) when a value and some attributes are both present. By default, it&#8217;s either one or another, but not both.</p>
<p>Here is the generated code from the schema:</p>
<pre class="brush: java; title: ; notranslate">
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = &quot;recipe&quot;)
public class Recipe {
    protected List&lt;String&gt; menu;
    protected Cooking cooking;
    @XmlAttribute
    protected String name;
    @XmlAttribute
    protected String type;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = &quot;cooking&quot;)
public class Cooking {
    protected List&lt;Step&gt; step;
    @XmlAttribute
    protected Integer duration;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = &quot;step&quot;)
public class Step {
    @XmlValue
    protected String content;
    @XmlAttribute
    protected Boolean optional;
}
</pre>
<p>Only one class is annotated @XmlRootElement. It&#8217;s the only one (in this schema) that can be the first node of the output. Once the object graph is generated, 3 lines of code are enough to parse a XML string:</p>
<pre class="brush: java; title: ; notranslate">
public class JaxbTest {
    @Test
    public void should_parse_recipe() throws JAXBException {
        URL xmlUrl = Resources.getResource(&quot;recipe.xml&quot;);
        Recipe recipe = parse(xmlUrl, Recipe.class);
        assertEquals(Integer.valueOf(15), recipe.getCooking().getDuration());
    }

    private &lt;T&gt; T parse(URL url, Class&lt;T&gt; clazz) throws JAXBException {
        Unmarshaller unmarsh = JAXBContext.newInstance(clazz).createUnmarshaller();
        return clazz.cast(unmarsh.unmarshal(url));
    }
}
</pre>
<p>Compared to low level API, no conversion is needed: declaring types in the schema is enough. In case of a conversion error (a string non convertible to a type) an appropriate IllegalArgumentException is thrown. When a node is missing, the corresponding variables are null.</p>
<h3><a name="Refine"></a>Refine the exchange format</h3>
<p>Once the data binding is successful, more control is needed:</p>
<ol>
<li>restrict a value to a range of possibilities;</li>
<li>manipulate java date instead of XMLGregorianCalendar used by default by JAXB;</li>
<li>use a different class name to represent an element;</li>
<li>use object inheritance between elements;</li>
<li>annotate existing classes manually.</li>
</ol>
<h4><a name="Restrictavaluetoarangeofpossib"></a>Restrict a value to a range of possibilities</h4>
<p>Restrict attribute « type » to « starter, main, desert » can be done this way:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xsd:element name=&quot;recipe&quot;&gt;
    &lt;xsd:attribute name=&quot;type&quot; type=&quot;course&quot; /&gt;
&lt;/xsd:element&gt;

&lt;xsd:simpleType name=&quot;course&quot;&gt;
    &lt;xsd:restriction base=&quot;xsd:string&quot;&gt;
        &lt;xsd:enumeration value=&quot;starter&quot;&gt;&lt;/xsd:enumeration&gt;
        &lt;xsd:enumeration value=&quot;main&quot;&gt;&lt;/xsd:enumeration&gt;
        &lt;xsd:enumeration value=&quot;desert&quot;&gt;&lt;/xsd:enumeration&gt;
    &lt;/xsd:restriction&gt;
&lt;/xsd:simpleType&gt;
</pre>
<p>Which gives us, when generated:</p>
<pre class="brush: java; title: ; notranslate">
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = &quot;recipe&quot;)
public class Recipe {
    @XmlAttribute
    protected Course type;
}

@XmlEnum
public enum Course {
    @XmlEnumValue(&quot;starter&quot;)
    STARTER(&quot;starter&quot;),
    @XmlEnumValue(&quot;main&quot;)
    MAIN(&quot;main&quot;),
    @XmlEnumValue(&quot;desert&quot;)
    DESERT(&quot;desert&quot;);
    private final String value;
}
</pre>
<p>When binding happens, if the value does not match any of the listed possibilities, a null value is users by default. By convention, JAXB uses a null value when a problem occurs and throws an exception for typing problems.</p>
<h4><a name="Usejavadates"></a>Use java dates</h4>
<p>To use a simple date instead of a XMLGregorianCalendar used by default in JAXB, a converter is required. Be careful, a new namespace has been declared on the root element. It allows us to redefine the date standard type.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;
            xmlns:jxb=&quot;http://java.sun.com/xml/ns/jaxb&quot;
            jxb:version=&quot;2.0&quot;&gt;

    &lt;xsd:annotation&gt;&lt;xsd:appinfo&gt;
        &lt;jxb:globalBindings&gt;
            &lt;jxb:javaType name=&quot;java.util.Date&quot; xmlType=&quot;xsd:dateTime&quot;
                          parseMethod=&quot;com.xebia.jaxb.JaxbDateConverter.parseDate&quot; /&gt;
        &lt;/jxb:globalBindings&gt;
    &lt;/xsd:appinfo&gt;&lt;/xsd:annotation&gt;

    &lt;xsd:element name=&quot;menu&quot; type=&quot;xsd:dateTime&quot; /&gt;
&lt;/xsd:schema&gt;
</pre>
<p>The converter must adhere to JAXB conventions, if the value does not fit, no exception is thrown but a null value is returned instead.</p>
<pre class="brush: java; title: ; notranslate">
public class JaxbDateConverter {

    public static Date parseDate(String s) {
        DateFormat formatter = new SimpleDateFormat(&quot;dd-MM-yyyy&quot;);
        try {
            return formatter.parse(s);
        } catch (ParseException e) {
            return null;
        }
    }
}
</pre>
<p>When generating classes, JAXB creates an adapter class binded to the static methods of the converter.</p>
<pre class="brush: java; title: ; notranslate">
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = &quot;recipe&quot;)
public class Recipe {
    @XmlElement(type = String.class)
    @XmlJavaTypeAdapter(Adapter1.class)
    @XmlSchemaType(name = &quot;dateTime&quot;)
    protected List&lt;Date&gt; menu;
</pre>
<h4><a name="Useadifferentclassnameforarepr"></a>Use a different class name to represent element</h4>
<p>To name a class deferred to the represented element, modifying the schema in the following manner is enough (be careful to add both namespaces):</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xsd:element name=&quot;menu&quot; type=&quot;xsd:dateTime&quot; /&gt;
&lt;xsd:annotation&gt;&lt;xsd:appinfo&gt;
    &lt;jxb:class name=&quot;meal&quot; /&gt;
&lt;/xsd:appinfo&gt;&lt;/xsd:annotation&gt;
</pre>
<h4><a name="Useobjectinheritance"></a>Use object inheritance</h4>
<p>Using object inheritance is easy (generated objects will inherit one another, naturally):</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xsd:complexType name=&quot;menuxl&quot;&gt;
    &lt;xsd:complexContent&gt;
        &lt;xsd:extension base=&quot;menu&quot; /&gt;
    &lt;/xsd:complexContent&gt;
    &lt;xsd:attribute name=&quot;cook&quot; type=&quot;xsd:string&quot; /&gt;
&lt;/xsd:complexType&gt;
</pre>
<h4><a name="Annotateexistingclassesmanuall"></a>Annotate existing classes manually</h4>
<p>So far, we have used only generated classes thanks to the schema. But we can also manually annotate a class to bind the XML. A schema can even be generated from the annotated source code.</p>
<p>Manual annotations give more control over objects, their type and the opportunity to use already existing ones that were used for other purposes (adding a non bindable attribute can be done with @XmlTransient).</p>
<p>Once again we have to adhere to JAXB convention. In its generated code JAXB overloads the getters to return empty lists instead of null. It is advised to do the same.</p>
<pre class="brush: java; title: ; notranslate">
public List&lt;String&gt; getMenu() {
    if (menu == null) {
        menu = new ArrayList&lt;String&gt;();
    }
    return menu;
}
</pre>
<h3><a name="Epilogue"></a>Epilogue: exchange format on the server</h3>
<p>Until now, we have assumed that no mechanism describing nodes organisation was provided from producer to consumers; this was resolved eventually by exchange formats. It is better, when possible, to remove that constraint by giving consumers a schema with data.</p>
<p>To do that, it is wise to opt for a contract first development style. To limit coupling between the schema and its implementation, it is advised to generate objects on the server side rather than annotating them. To bear within the limits of a XSD schema types and organisation, guarantees the compatibility of the output to any kind of clients (more particularly to non java ones). <a href="http://static.springsource.org/spring-ws/site/reference/html/why-contract-first.html" title="The Spring reference documentation" >The Spring reference documentation</a> champions this idea.</p>
<h3><a name="Appendixtools"></a>Appendix: tools</h3>
<p>In order to run the samples, you will need the following : <a href="http://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl" title="the maven dependency to JAXB project" >JAXB maven dependency</a> and <a href="http://mojo.codehaus.org/jaxb2-maven-plugin/usage.html" title="the associated generation plugin" >the associated generation plugin</a>. To ease testing, we also provide a simple plugin configuration (generation can be launched using <strong>mvn jaxb2:xjc</strong>):</p>
<pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;jaxb2-maven-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
    	&lt;outputDirectory&gt;${basedir}/src/main/java&lt;/outputDirectory&gt;
    	&lt;schemaDirectory&gt;${basedir}/src/main/resources/xsd&lt;/schemaDirectory&gt;
    	&lt;packageName&gt;com.xebia.jaxb.generated&lt;/packageName&gt;
    	&lt;schemaFiles&gt;schema.xsd&lt;/schemaFiles&gt;
    &lt;/configuration&gt;
&lt;/plugin&gt;
</pre>
<p>To dig further on data binding with JAXB, <a href="http://jaxb.java.net/tutorial" title="a wellstocked documentation is available here" >a well-stocked documentation is available here</a>.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/03/17/jaxb-xml-data-binding/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F03%2F17%2Fjaxb-xml-data-binding%2F&amp;title=JAXB%2C%20XML%20Data%20Binding" id="wpa2a_16"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/03/17/jaxb-xml-data-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making the bootstrap loader &#8220;just another ClassLoader&#8221;</title>
		<link>http://blog.xebia.com/2011/02/24/making-the-bootstrap-loader-just-another-classloader/</link>
		<comments>http://blog.xebia.com/2011/02/24/making-the-bootstrap-loader-just-another-classloader/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 11:37:00 +0000</pubDate>
		<dc:creator>Andrew Phillips</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[class loader]]></category>

	<!-- AutoMeta Start -->
	<category>loader</category>
	<category>loader</category>
	<category>bootstrap</category>
	<category>getloader</category>
	<category>loadclass</category>
	<category>classloader</category>
	<category>getcontextclassloader</category>
	<category>getsystemclassloader</category>
	<category>loader</category>
	<category>loader</category>
	<category>bootstrap</category>
	<category>getloader</category>
	<category>loadclass</category>
	<category>classloader</category>
	<category>getcontextclassloader</category>
	<category>getsystemclassloader</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6078</guid>
		<description><![CDATA[Recently, I was tweaking MultiSPI to add the following class loading fallback logic: and realized that it&#8217;s not immediately evident how to do this in a uniform way. But actually, it&#8217;s quite simple&#8230;getting a ClassLoader object for the bootstrap loader is just a couple of lines of code. So what&#8217;s the problem? Well, if you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was tweaking <a href="http://blog.xebia.com/2011/02/13/multispi-consuming-service-provider-interfaces-in-2011/" target="_new">MultiSPI</a> to add the following class loading fallback logic:</p>
<pre class="brush: java; title: ; notranslate">
if (threadContextLoader != null) {
  loadFromContextLoader(className);
} else if (systemLoader != null) {
  loadFromSystemLoader(className);
} else {
  loadFromBootstrapLoader(className);
}
</pre>
<p>and realized that it&#8217;s not immediately evident how to do this in a uniform way. But actually, it&#8217;s quite simple&#8230;getting a <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html" target="_new">ClassLoader</a> object for the bootstrap loader is just a couple of lines of code.<br />
<span id="more-6078"></span></p>
<h3>So what&#8217;s the problem?</h3>
<p>Well, if you&#8217;re happy with a literal implementation of the pseudo-code above, there obviously isn&#8217;t a problem. </p>
<pre class="brush: java; title: ; notranslate">
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader != null) {
  return loader.loadClass(className);
}

loader = ClassLoader.getSystemClassLoader();
if (loader != null) {
  return loader.loadClass(className);
}

// null is the bootstrap loader
return Class.forName(className, true, null);
</pre>
<p>But this is very procedural code<sup>1</sup>, and it would already be much more OO if we could do something like:</p>
<pre class="brush: java; title: ; notranslate">
getLoader().loadClass(className);

ClassLoader getLoader() {
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  if (loader != null) {
    return loader;
  }

  loader = ClassLoader.getSystemClassLoader();
  if (loader != null) {
    return loader;
  }

  return ...???????
}
</pre>
<p>The problem is that there simply isn&#8217;t a <tt>ClassLoader.getBootstrapClassLoader()</tt> or equivalent method. You can try to walk up the system loader&#8217;s <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getParent()" target="_new">parent</a> hierarchy, of course, but what you&#8217;re likely to find is that the bootstrap loader will be <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getParent()" target="_new">represented by <tt>null</tt></a> &#8211; not very useful in our circumstances.</p>
<h3>Writing BootstrapClassLoader</h3>
<p>So what we want is to come up with a <tt>ClassLoader</tt> implementation that delegates straight to the bootstrap loader. One option would be to override <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#loadClass(java.lang.String)" target="_new">loadClass</a> to simply call <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#forName(java.lang.String, boolean, java.lang.ClassLoader)" target="_new">Class.forName</a> with the above arguments, but there&#8217;s actually an even easier<sup>2</sup> way:</p>
<pre class="brush: java; title: ; notranslate">
class BootstrapClassLoader extends ClassLoader {
    BootstrapClassLoader() {
        /*
         * The default classloader implementation will use the bootstrap loader
         * if it finds a null parent.
         */
        super(null);
    }
}
</pre>
<p>Now we can finish our <tt>getLoader</tt> method:</p>
<pre class="brush: java; title: ; notranslate">
// or simply &quot;new ClassLoader(null) {};&quot;
final ClassLoader BOOTSTRAP_LOADER = new BootstrapClassLoader();

ClassLoader getLoader() {
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  if (loader != null) {
    return loader;
  }

  loader = ClassLoader.getSystemClassLoader();
  if (loader != null) {
    return loader;
  }

  return BOOTSTRAP_LOADER;
}
</pre>
<p>Unless we&#8217;re being really performance-conscious, we can even turn this into the almost functional<sup>3</sup>:</p>
<pre class="brush: java; title: ; notranslate">
ClassLoader getLoader() {
  return Iterables.find(asList(Thread.currentThread().getContextClassLoader(),
      ClassLoader.getSystemClassLoader(), BOOTSTRAP_LOADER), Predicates.notNull());
}
</pre>
<p>There&#8217;s a demo snippet on PasteBin <a href="http://pastebin.com/nJVXMucK" target="_new">here</a>.</p>
<div style="background-color: #EFEEEA; border: 1px solid #AAAAAA; margin: 0.8em; padding: 0.4em; font-size: 85%;">
<strong>Footnotes</strong></p>
<ol>
<li>Indeed, I hope your immediate reaction was something like <em>urgh!</em></li>
<li>and, to my mind, more elegant</li>
<li>Heavy use of <a href="http://code.google.com/p/guava-libraries/" target="_new">Guava</a> ahead!</li>
</ol>
</div>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/02/24/making-the-bootstrap-loader-just-another-classloader/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F02%2F24%2Fmaking-the-bootstrap-loader-just-another-classloader%2F&amp;title=Making%20the%20bootstrap%20loader%20%26%238220%3Bjust%20another%20ClassLoader%26%238221%3B" id="wpa2a_18"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/02/24/making-the-bootstrap-loader-just-another-classloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MultiSPI &#8211; consuming service provider interfaces in 2011</title>
		<link>http://blog.xebia.com/2011/02/13/multispi-consuming-service-provider-interfaces-in-2011/</link>
		<comments>http://blog.xebia.com/2011/02/13/multispi-consuming-service-provider-interfaces-in-2011/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 09:11:11 +0000</pubDate>
		<dc:creator>Andrew Phillips</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[spi]]></category>

	<!-- AutoMeta Start -->
	<category>multispi</category>
	<category>serviceloader</category>
	<category>qrmedia</category>
	<category>aphillips</category>
	<category>googlecode</category>
	<category>snapshots</category>
	<category>snapshot</category>
	<category>spis</category>
	<category>multispi</category>
	<category>serviceloader</category>
	<category>qrmedia</category>
	<category>aphillips</category>
	<category>googlecode</category>
	<category>snapshots</category>
	<category>snapshot</category>
	<category>spis</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6071</guid>
		<description><![CDATA[Implementing a Java SPI isn&#8217;t a particularly 2011 experience1. Creating a correctly-named text file in META-INF/services, making sure it is correctly packaged and remembering to keep it up to date when you refactor is sufficiently annoying and error-prone that there are at least a couple of utils that aim to make this easier. At XebiaLabs, [...]]]></description>
			<content:encoded><![CDATA[<p>Implementing a Java SPI isn&#8217;t a particularly 2011 experience<sup>1</sup>. Creating a correctly-named text file in META-INF/services, making sure it is correctly packaged and remembering to keep it up to date when you refactor is sufficiently annoying and error-prone that there are at least a <a href="http://code.google.com/p/spi/" target="_new">couple</a> <a href="http://weblogs.java.net/blog/kohsuke/archive/2009/03/my_project_of_t.html" target="_new">of</a> utils that aim to make this easier.</p>
<p>At <a href="http://www.xebialabs.com/features" target="_new">XebiaLabs</a>, however, we&#8217;re not just the implementors of our plugin SPI. We also write the deployment engine that <em>consumes</em> these plugins. And unfortunately, there isn&#8217;t much out there to help you read, load and verify services. Hence <a href="http://aphillips.googlecode.com/svn/maven-sites/multi-spi/1.0-SNAPSHOT/index.html" target="_new">MultiSPI</a>.<br />
<span id="more-6071"></span></p>
<h3>What about ServiceLoader?</h3>
<p>Evidently, the engineers at <strike>Sun</strike>Oracle &#8211; as prominent SPI consumers &#8211; shared this frustration. In Java 6, they introduced <a href="http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html" target="_new">ServiceLoader</a> to at least make &#8220;vanilla&#8221; SPI consumption easier. MultiSPI isn&#8217;t just a fully-compatible alternative for those still working with Java 5, however. It also supports a number of common additional use cases:</p>
<ol>
<li><strong>Inspecting the list of class names before they are loaded</strong>, for instance to remove or replace some items (think user-definable overrides), to use different class loaders for different packages (think OSGi) etc.</li>
<li><strong>Inspecting the classes before they are instantiated</strong>, for instance to check for required annotations or implemented interfaces, to delay creation of instances etc.</li>
<li><strong>Using non-vanilla instantiation strategies</strong>, for instance to support factory methods, or in conjunction with dependency injection etc.</li>
</ol>
<h3>Providing services in 2011</h3>
<p>More importantly, though, MultiSPI doesn&#8217;t just support reading service implementations from META-INF/services files. Because let&#8217;s face it, if you&#8217;re designing a component-provider mechanism today, it probably won&#8217;t be based on the <a href="http://download.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider" target="_new">vanilla SPI specification</a>.</p>
<p>MultiSPI supports <a href="http://aphillips.googlecode.com/svn/maven-sites/multi-spi/1.0-SNAPSHOT/apidocs/com/qrmedia/commons/multispi/config/MultiSpiBuilder.html#withAnnotationScanning(java.lang.Class, java.lang.String)" target="_new">annotation-</a> and <a href="http://aphillips.googlecode.com/svn/maven-sites/multi-spi/1.0-SNAPSHOT/apidocs/com/qrmedia/commons/multispi/config/MultiSpiBuilder.html#withManifestServiceClassnameAttributeScanning()" target="_new">manifest-scanning</a> out-of-the-box, but you can <a href="http://aphillips.googlecode.com/svn/maven-sites/multi-spi/1.0-SNAPSHOT/apidocs/com/qrmedia/commons/multispi/config/MultiSpiBuilder.html#withProviders()" target="_new">add providers</a> for any scheme of your choice, be it XML descriptors, system properties, environment variables or whatever. Of course, you can also mix and match different providers, especially useful if (as in our case with <a href="http://www.xebialabs.com/features" target="_new">Labs</a>) you are supporting multiple versions of an SPI.</p>
<h3>SPIs and dependency injection</h3>
<p>Ultimately, of course, SPIs are just service factories, and if you&#8217;re working within a dependency injection context you probably don&#8217;t want to invoke an SPI loader explicitly, you just want the resulting services to &#8220;be available&#8221; for injection into your business logic.<br />
Indeed, Spring added a <a href="http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.html" target="_new">ServiceLoader-backed factory</a> in 2.5, and of course you can do the same with MultiSPI, whether you want the implementation class names, the classes or the instances themselves. There&#8217;s <a href="http://code.google.com/p/aphillips/source/browse/multi-spi/trunk/src/test/java/com/qrmedia/commons/multispi/example/SpringAgentExample.java" target="_new">Spring</a> and <a href="http://code.google.com/p/aphillips/source/browse/multi-spi/trunk/src/test/java/com/qrmedia/commons/multispi/example/GuiceAgentExample.java" target="_new">Guice</a> examples; here&#8217;s the <a href="http://code.google.com/p/aphillips/source/browse/multi-spi/trunk/src/test/resources/agentContext.xml" target="_new">Spring context</a> that prepares a set of class names, classes and instances, for example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;bean id=&quot;multiSpi&quot; class=&quot;com.qrmedia.commons.multispi.MultiSpi&quot;&gt;
  &lt;constructor-arg&gt;
    &lt;set&gt;
      &lt;bean class=&quot;com.qrmedia.commons.multispi.provider.MetaInfServicesProvider&quot; /&gt;
      &lt;bean class=&quot;com.qrmedia.commons.multispi.provider.AnnotationScanningProvider&quot;&gt;
        &lt;constructor-arg value=&quot;uk.gov.mi6.LicenseToKill&quot; /&gt;
        &lt;constructor-arg value=&quot;uk.gov&quot; /&gt;
      &lt;/bean&gt;
    &lt;/set&gt;
  &lt;/constructor-arg&gt;
&lt;/bean&gt;

&lt;bean id=&quot;agentNames&quot; factory-bean=&quot;multiSpi&quot; factory-method=&quot;findImplementationNames&quot;&gt;
  &lt;constructor-arg value=&quot;uk.gov.mi6.Agent&quot; /&gt;
&lt;/bean&gt;

&lt;bean id=&quot;agentClasses&quot; factory-bean=&quot;multiSpi&quot; factory-method=&quot;findImplementations&quot;&gt;
  &lt;constructor-arg value=&quot;uk.gov.mi6.Agent&quot; /&gt;
&lt;/bean&gt;

&lt;bean id=&quot;agents&quot; factory-bean=&quot;multiSpi&quot; factory-method=&quot;loadImplementations&quot;&gt;
  &lt;constructor-arg value=&quot;uk.gov.mi6.Agent&quot; /&gt;
&lt;/bean&gt;
</pre>
<p>Of course you can use many different <a href="http://aphillips.googlecode.com/svn/maven-sites/multi-spi/1.0-SNAPSHOT/apidocs/com/qrmedia/commons/multispi/MultiSpi.html" target="_new">MultiSpi</a> instances, with different provider configurations, in your application at the same time.</p>
<h3>Using MultiSPI</h3>
<p>To use MultiSPI, just add the following dependency and repositories to your POM:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
  &lt;groupId&gt;com.qrmedia.commons&lt;/groupId&gt;
  &lt;artifactId&gt;multi-spi&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;/dependency&gt; 

&lt;repository&gt;
  &lt;id&gt;qrmedia-releases&lt;/id&gt;
  &lt;url&gt;http://aphillips.googlecode.com/svn/maven-repository/releases&lt;/url&gt;
  &lt;releases&gt;
    &lt;enabled&gt;true&lt;/enabled&gt;
  &lt;/releases&gt;
  &lt;snapshots&gt;
    &lt;enabled&gt;false&lt;/enabled&gt;
  &lt;/snapshots&gt;
&lt;/repository&gt;
&lt;repository&gt;
  &lt;id&gt;qrmedia-snapshots&lt;/id&gt;
  &lt;url&gt;http://aphillips.googlecode.com/svn/maven-repository/snapshots&lt;/url&gt;
  &lt;releases&gt;
    &lt;enabled&gt;false&lt;/enabled&gt;
  &lt;/releases&gt;
  &lt;snapshots&gt;
    &lt;enabled&gt;true&lt;/enabled&gt;
  &lt;/snapshots&gt;
&lt;/repository&gt;
</pre>
<p>If you think you might run into conflicting <a href="http://aphillips.googlecode.com/svn/maven-sites/multi-spi/1.0-SNAPSHOT/dependencies.html" target="_new">dependencies</a> and want something that just works without having to deal with &lt;excludes&gt;, you can use:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;dependency&gt;
  &lt;groupId&gt;com.qrmedia.commons&lt;/groupId&gt;
  &lt;artifactId&gt;multi-spi&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;classifier&gt;jar-with-dependencies&lt;/classifier&gt;
&lt;/dependency&gt;
</pre>
<p>instead.</p>
<p>The Maven site and project reports are <a href="http://aphillips.googlecode.com/svn/maven-sites/multi-spi/1.0-SNAPSHOT/project-info.html" target="_new">here</a>.</p>
<div style="background-color: #EFEEEA; border: 1px solid #AAAAAA; margin: 0.8em; padding: 0.4em; font-size: 85%;">
<strong>Footnotes</strong></p>
<ol>
<li>I&#8217;ll leave the debate about whether even writing <em>Java</em> can still be considered a 2011 experience to our <a href="http://maurits.wordpress.com/" target="_new">Clojure</a>, <a href="http://dutch-scala-enthusiasts.ning.com/" target="_new">Scala</a> etc. fans <img src='http://blog.xebia.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
</ol>
</div>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/02/13/multispi-consuming-service-provider-interfaces-in-2011/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F02%2F13%2Fmultispi-consuming-service-provider-interfaces-in-2011%2F&amp;title=MultiSPI%20%26%238211%3B%20consuming%20service%20provider%20interfaces%20in%202011" id="wpa2a_20"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/02/13/multispi-consuming-service-provider-interfaces-in-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.xebia.com/category/tools/feed/ ) in 0.88025 seconds, on Feb 9th, 2012 at 3:59 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 4:59 pm UTC -->
