<?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>David Simpson &#187; java</title>
	<atom:link href="http://davidsimpson.me/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidsimpson.me</link>
	<description>Developing the web, one page at a time.</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:02:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Some thoughts on developing my first Confluence plugin</title>
		<link>http://davidsimpson.me/2010/01/25/some-thoughts-on-developing-my-first-confluence-plugin/</link>
		<comments>http://davidsimpson.me/2010/01/25/some-thoughts-on-developing-my-first-confluence-plugin/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 12:42:04 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorised]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[atlassian]]></category>
		<category><![CDATA[confluence]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://davidsimpson.me/?p=503</guid>
		<description><![CDATA[I recently started building Confluence plugins. The first one being my Google Analytics plugin for Confluence. This post outlines my &#8220;journey&#8221; into Confluence plugin development. It documents a beginner&#8217;s pitfalls when developing with the Atlassian Plugin SDK. Hopefully others can learn from, or at least laugh at my mistakes. Where I was starting from: No [...]]]></description>
			<content:encoded><![CDATA[<div id="tweetbutton503" class="tw_button" style=""><a href="http://twitter.com/share?url=http%3A%2F%2Fdavidsimpson.me%2F2010%2F01%2F25%2Fsome-thoughts-on-developing-my-first-confluence-plugin%2F&amp;text=Some%20thoughts%20on%20developing%20my%20first%20Confluence%20plugin&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fdavidsimpson.me%2F2010%2F01%2F25%2Fsome-thoughts-on-developing-my-first-confluence-plugin%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://davidsimpson.me/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;"></a></div><p><img class="alignnone" title="ga-idea" src="/wp-content/uploads/2010/01/ga-idea2.png" alt="ga-idea" /></p>
<p><!-- Some thoughts on developing my first Confluence plugin  or A bluffer's guide to developing Confluence plugins --></p>
<p>I recently started building Confluence plugins.  The first one being my <a href="/2010/01/02/announcing-google-analytics-plugin-for-confluence/">Google Analytics plugin for Confluence</a>. This post outlines my &#8220;journey&#8221; into Confluence plugin development.  It documents a beginner&#8217;s pitfalls when developing with the Atlassian Plugin SDK. Hopefully others can learn from, or at least laugh at my mistakes.</p>
<p>Where I was starting from:</p>
<ul>
<li>No experience of <a href="http://maven.apache.org/">maven</a></li>
<li>No understanding of how Confluence plugins work or how they are written</li>
<li>Some experience of Java &#8211; Mainly <a href="http://www.jasig.org/uportal">uPortal</a>/<a href="http://www.sungardhe.com/products/luminis-platform">Luminis</a> portal development for the <a href="http://my.nottingham.ac.uk/">University of Nottingham</a> and some consultancy work e.g. for Astra Zeneca, Documentum and 3Com</li>
<li>No experience of unit testing or integration testing in Java &#8211; oh dear</li>
<li>I prefer UI work to real programming</li>
</ul>
<p><span id="more-503"></span></p>
<h2>Initial failure</h2>
<p>I tried to setup a development environment for plugin development using Atlassian&#8217;s <a href="http://confluence.atlassian.com/display/DEVNET/How+to+Build+an+Atlassian+Plugin">documentation</a> a little before the beta release of version 3 of the Atlassian Plugin SDK.  It was a pain. This was no fault of the documentation — it was really just to do with my schedules and available time to experiment.</p>
<p>The problem was two-fold:</p>
<ol>
<li>I&#8217;d not done this before, so was clueless to what was involved</li>
<li>The setup was a complete ball-ache considering the time restraints</li>
</ol>
<p>I was well aware of point 1 and the pain it was likely to cause.  Point 2 seemed to be the old chestnut &#8211; install and configure the exact correct versions of the software you need in the correct sequence, then start.</p>
<p>Wait.  I don&#8217;t know what that means, see point 1. Yes, I&#8217;ve got maven installed on my MacBook! Woo! Let&#8217;s go.  Hang on, it&#8217;s not the correct version. Where do I get that from?</p>
<p>In many ways, it reminded me of my initial experience of building and installing Apache 1.x on Solaris SPARC boxes back in the day:</p>
<blockquote><p>cd /path/to/apache/source; make; make install;<br />
Oh. Wrong version of make. Where do I get that from?  Hmmm.<br />
Install correct version of make. Damn, make needs the correct version of gcc. Where do I get that from?<br />
And so on. Moving further and further away from the problem you&#8217;re trying to solve.</p></blockquote>
<p>So, I stopped there.  No shiny Confluence plugins for me.  I&#8217;ve got plenty of other things to do anyway thank you very much.</p>
<h2>Reboot</h2>
<p>Then Atlassian released the Plugin SDK beta and all this nastiness was removed.  Everything you need to build an Atlassian plugin was bundled in one place.  Refreshing. All commands have been wrapped and so are prefixed with <code>atlas-</code> to prevent conflict with whatever else you&#8217;ve got installed.</p>
<p>For the impatient, this really drives down the barriers to entry for plugin development.</p>
<p>Following the documentation for <a href="http://confluence.atlassian.com/display/DEVNET/Setting+up+your+Plugin+Development+Environment">installing the Plugin SDK</a> was a piece of cake.  It just worked.</p>
<ul>
<li>Download</li>
<li>Unzip</li>
<li>Add some environment settings. Edit <code>~/.profile</code> and add:
<pre class="brush: bash; title: ;">
PATH=$PATH:.
PATH=$PATH:$HOME/
PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/atlassian-plugin-sdk/atlassian-plugin-sdk-3.0-beta3
PATH=$PATH:$HOME/atlassian-plugin-sdk/atlassian-plugin-sdk-3.0-beta3/bin
export PATH
</pre>
</li>
<li>Start building a plugin</li>
</ul>
<p>Starting out to build your Atlassian plugin is <a href="http://confluence.atlassian.com/display/DEVNET/Developing+your+Plugin+using+the+Atlassian+Plugin+SDK">documented here</a>. It&#8217;s a fairly straightforward set of instructions.</p>
<p>You start by doing something like this:</p>
<pre class="brush: bash; title: ;">
mkdir ~/projects/davidsimpson.me/
mkdir ~/projects/davidsimpson.me/confluence
cd  ~/projects/davidsimpson.me/confluence

atlas-create-confluence-plugin
...
...
...
When prompted
Define value for groupId: : me.davdsimpson.confluence.plugins
Define value for artifactId: : googleanalytics
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  me.davdsimpson.confluence.plugins: :
Confirm properties configuration:
groupId: me.davdsimpson.confluence.plugins
artifactId: googleanalytics
version: 1.0-SNAPSHOT
package: me.davdsimpson.confluence.plugins
</pre>
<p>Then type&#8230;</p>
<pre class="brush: bash; title: ;">cd googleanalytics
atlas-run</pre>
<p>&#8230;and sit back.  If maven doesn&#8217;t fall over for lack of memory at this point, you&#8217;re laughing.  Go away, have a beer or two.  This may take some time.</p>
<p><img class="aligncenter size-medium wp-image-525" title="Beer" src="/wp-content/uploads/2010/01/iStock_000009660877XSmall.jpg" alt="Beer" width="440" height="175" /></p>
<p>On your return, maven will hopefully have finished dragging all manner of nonsense from Australia and installed a working copy of Confluence, together with an empty plugin onto your computer. Nice.  Next, write some code.</p>
<p><strong>I like to run before I can walk.</strong> It seems like much more fun to attempt something that&#8217;s harder.  You do fall over a lot more often though.  So rather than some kind of silly little hello world or equivalent plugin, my first plugin was an integration of Google Analytics with Confluence using the Google Analytics API to fetch data from Google.  It requires some additional JARs from Google.</p>
<p>Google doesn&#8217;t have a public maven repository to my knowledge and I&#8217;d no idea how to get these JARs added into maven.  Luckily, people had already written about <a href="http://www.techbits.de/2009/08/06/adding-googles-gdata-java-api-to-your-maven-repository/">parts</a> of <a href="http://blog.stuartlewis.com/2009/05/29/surfacing-google-analytics-stats-in-dspace/">this</a>, so I put 2 and 2 together.</p>
<p><strong>Add Google Analytics JARs to maven:</strong></p>
<pre class="brush: bash; title: ;">
atlas-mvn install:install-file -DgroupId=com.google.gdata
    -DartifactId=gdata-core
    -Dversion=1.0
    -Dpackaging=jar
    -Dfile=/path/to/gdata-core-1.0.jar
    -DgeneratePom=true

atlas-mvn install:install-file -DgroupId=com.google.gdata
    -DartifactId=gdata-analytics
    -Dversion=2.0
    -Dpackaging=jar
    -Dfile=/path/to/gdata-analytics-2.0.jar
    -DgeneratePom=true

atlas-mvn install:install-file -DgroupId=com.google.collect
    -DartifactId=google-collect
    -Dversion=1.0
    -Dpackaging=jar
    -Dfile=/path/to/google-collect-1.0-rc3.jar
</pre>
<p><strong>Edit the Project Object Model (POM) to add the dependencies</strong></p>
<p>Edit the pom:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vi</span> ~<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span>davidsimpson.me<span style="color: #000000; font-weight: bold;">/</span>confluence<span style="color: #000000; font-weight: bold;">/</span>googleanalytics<span style="color: #000000; font-weight: bold;">/</span>pom.xml</pre></div></div>

<p>Add this bit to the end of the dependencies node:</p>
<pre class="brush: xml; title: ;">
&lt;!-- Add Google Analytics dependencies: --&gt;

       com.google.gdata
       gdata-core
       1.0

       com.google.gdata
       gdata-analytics
       2.0

	com.google.collect
	google-collect
	1.0
</pre>
<p><strong>Next, fire up your IDE</strong></p>
<p>My chosen IDE is <a href="http://www.jetbrains.com/idea/">IntelliJ IDEA</a>.</p>
<ul>
<li>Open the pom.xml in IntelliJ IDEA (File | Open project)</li>
<li>Override/set the maven home directory:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>davidsimpson<span style="color: #000000; font-weight: bold;">/</span>atlassian-plugin-sdk-<span style="color: #000000;">3.0</span>-beta3<span style="color: #000000; font-weight: bold;">/</span>apache-maven</pre></div></div>

</li>
<li>Set the JDK for build as 1.5 or 1.6</li>
<li>Start editing the plugin</li>
</ul>
<h2>Hiccups</h2>
<p>It&#8217;s not all straightforward.  Here&#8217;s some of the annoyances that I came across.</p>
<h3>Maven needs more memory</h3>
<p>I needed more memory for maven.  Not really a problem &#8211; append to <code>~/.profile</code>:</p>
<pre class="brush: bash; title: ;">
MAVEN_OPTS=-Xmx512m
export MAVEN_OPTS
</pre>
<h3>Annoying warnings on <code>atlas-run</code></h3>
<p>I noticed this on running <code>atlas-run</code> &#8211; it probably shouldn&#8217;t be there:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>WARNING<span style="color: #7a0874; font-weight: bold;">&#93;</span> Using platform encoding <span style="color: #7a0874; font-weight: bold;">&#40;</span>MacRoman actually<span style="color: #7a0874; font-weight: bold;">&#41;</span> to copy filtered resources, i.e. build is platform dependent<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>Of course, someone has already blogged about it — <a href="http://www.redleopard.com/2009/04/macroman-encoding-creeps-into-maven/">Red Leopard</a> — and it&#8217;s easily fixed by editing the POM to add the correct encoding.</p>
<pre class="brush: xml; title: ;">
3.0.2
    3.0

    &lt;!-- Fix for MacRoman warnings on build --&gt;
    UTF-8
    UTF-8
</pre>
<p>Now, we have no nasty warnings.</p>
<h3>The macro browser icon</h3>
<p>I love the Macro Browser in Confluence.  It&#8217;s a nice step forward in the evolution of the UI.  So as a result, I wanted my macro to have a  shiny icon in the macro browser.   That damn Macro Browser icon ate up several hours of my life.  Looking at the comments on the <a href="http://confluence.atlassian.com/display/CONFDEV/Updating+macros+for+the+Macro+Browser">documentation</a> page, several other people have had a whole load of fun getting their pretty icon to show up too.</p>
<div id="attachment_521" class="wp-caption alignnone" style="width: 450px"><a href="http://localhost/davidsimpson.me/wp-content/uploads/2010/01/macro-browser1.png" rel="lightbox[503]" title="macro-browser"><img class="size-medium wp-image-521" title="macro-browser" src="http://davidsimpson.me/wp-content/uploads/2010/01/macro-browser1.png" alt="The macro browser icon: What we're aiming for"  /></a><p class="wp-caption-text">The macro browser icon: What we</p></div>
<p>Could I get the Macro Browser to show my plugin&#8217;s icon. No.  I followed the <a href="http://confluence.atlassian.com/display/CONFDEV/Updating+macros+for+the+Macro+Browser">documentation</a>.  It did not work.  I looked again. This time I <em>really</em> paid attention.  Was it my fat fingers?  Was I just being stupid? (Probably.)  I ignored this for a while — maybe it would be better after a night&#8217;s sleep.</p>
<p>Everything <a href="http://twitter.com/dvdsmpsn/status/5796289204">seemed to work a whole lot better</a> when I dropped the beta and moved to version 3.0.2 of the Plugin SDK.<br />
<strong>Note:</strong> I had to update my <code>~/.profile</code> to point to the new version of the SDK and update the references to maven in Intelli-J at this point.</p>
<p>I also followed a different tack on getting the macro browser icon to work</p>
<ul>
<li>Find a macro that has a custom icon in the macro browser</li>
<li>Go to the Atlassian public subversion repository and browse to the source for that macro plugin.</li>
<li>Copy the exact syntax from the <code>atlassian-plugin.xml</code> and paste into your macro&#8217;s own <code>atlassian-plugin.xml</code></li>
<li>Name the icon exactly the same as in the <code>atlassian-plugin.xml</code> and put it in the correct place in the directory structure</li>
</ul>
<p>I&#8217;m not entirely sure whether it was the copy and paste approach that helped or moving away from the beta.  It works now, so I&#8217;m not going to loose sleep on why.</p>
<h3>Adding a configuring UI to the plugin</h3>
<p>My plugin needed to store Google account credentials and display a list of Google Analytics sites, so you can choose the correct profile.   How do you do that?  Hmmm. Go back to the <a href="http://confluence.atlassian.com/display/CONFDEV/Adding+a+Configuration+UI+for+your+Plugin">documentation</a>.  It wasn&#8217;t nearly detailed enough for my liking, so time to vent a <a href="http://twitter.com/dvdsmpsn/status/5719013792">little</a>.</p>
<p>Again, it seemed the best way to learn was to find a plugin that has a similar kind of configuration to that you&#8217;re hoping for and start appropriating the code.</p>
<h3>Unit testing and integration testing</h3>
<p>This is a good idea. Period. Did I have a clue how to do it for Confluence?  Of course not.</p>
<p>Again, the community helped out.  Atlassian partners at Adaptavist, Comala Technology and Customware have written about this:</p>
<ul>
<li><a href="http://www.customware.net/repository/display/GREENHOUSE/2009/03/18/Integration+Testing+of+Confluence+Plugins">Integration Testing of Confluence Plugins</a> by Bo Wang</li>
<li><a href="http://www.adaptavist.com/display/~erobertshaw/2009/08/17/Unit+testing+a+Confluence+Action">Unit testing a Confluence Action</a> by Edward Robertshaw</li>
<li><a href="http://www.adaptavist.com/display/~erobertshaw/Unit+testing+a+Confluence+Macro">Unit testing a Confluence Macro</a> by Edward Robertshaw</li>
<li><a href="http://www.mundoreves.com/display/HOME/2009/01/29/Confluence+plugin+integration+testing"> Confluence plugin integration testing </a> by Roberto Dominguez</li>
</ul>
<p>Browsing around the Atlassian public subversion repository was also a help.  I&#8217;ve got to say that I&#8217;m an easy convert to testing.  It just makes sense.</p>
<p><strong>Update (2010-05-04):</strong> A nice feature of the SDK is running or testing your plugin against different versions of the product.  This is straightforward:</p>
<pre class="brush: bash; title: ;">
# Integration tests for different versions
atlas-integration-test -v 3.0
atlas-integration-test -v 3.1
atlas-integration-test -v 3.2
# Run different versions of Confluence
atlas-run -v 3.0
atlas-run -v 3.1
atlas-run -v 3.2
</pre>
<h2>Wrapping up</h2>
<p>After a good deal of stumbling around, it turns out that I can write a Confluence plugin after all.  Everything started working a lot better after I updated from the beta version, but that could just be coincidence.  The documentation <em>could</em> be a little better to help the uninitiated  but it was equally my fault for not learning to walk first.  There is a lot of good information, but it is spread over a few different spaces.</p>
<p>My next step was to get the plugin added to Atlassian <a href="https://plugins.atlassian.com/plugin/home">Plugin Exchange</a>.  It took a little while to get this done — maybe that&#8217;s best saved for a follow up post.  The plugin is now <a href="https://plugins.atlassian.com/plugin/details/16722">available</a> on Atlassian Plugin Exchange.  I hope other people get some use out of it.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://davidsimpson.me/2010/01/25/some-thoughts-on-developing-my-first-confluence-plugin/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

