<?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"
	>

<channel>
	<title>Jabbering Giraffe</title>
	<atom:link href="http://happygiraffe.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<pubDate>Thu, 20 Nov 2008 23:15:58 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>NetBeans 6.5</title>
		<link>http://happygiraffe.net/blog/2008/11/20/netbeans-65/</link>
		<comments>http://happygiraffe.net/blog/2008/11/20/netbeans-65/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 23:15:56 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[eclipse]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[maven]]></category>

		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1416</guid>
		<description><![CDATA[Today NetBeans 6.5 got released.  Congratulations, guys!  I&#8217;m primarily an Eclipse user1, but I keep hearing about NetBeans through the Java Posse and heck, I even subscribe to the NetBeans podcast to try and keep an eye on what&#8217;s up.  Every time a new release comes out, I give it a whirl.
So [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a href="http://www.netbeans.org/community/releases/65/">NetBeans 6.5</a> got released.  Congratulations, guys!  I&#8217;m primarily an Eclipse user<sup><a href="#fn1">1</a></sup>, but I keep hearing about NetBeans through the <a href="http://javaposse.com/">Java Posse</a> and heck, I even subscribe to the <a href="http://blogs.sun.com/geertjan/entry/netbeans_podcast_episode_44">NetBeans podcast</a> to try and keep an eye on what&#8217;s up.  Every time a new release comes out, I give it a whirl.</p>
<p>So this time, now I&#8217;m looking at 6.5.  And it&#8217;s really nice on a lot of fronts.  Most of the improvements in 6.5 aren&#8217;t <em>directly</em> relevant to me — they&#8217;re related to scripting languages I don&#8217;t use.  What I&#8217;m particularly interested in is the core Java SE support.  And NetBeans is really very good.  It&#8217;s just not quite as good as Eclipse.  Or (more likely) I can&#8217;t figure out a way to make it do what I want.</p>
<p>There are a couple of things I do all the time in Eclipse.  First, <code>⌘-T</code>, which shows type hierarchies.  But that&#8217;s putting it simply.  If you pop it over a class, it shows the subtype hierarchy.  Press it again and it shows the supertype hierarchy.  What&#8217;s neat is that if you do it over a method, it greys out those classes that don&#8217;t have an implementation of that method.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2008/11/eclipse-cmd-t.png" alt="⌘-T in Eclipse" border="0" width="419" height="190" /></div>
<p>But what makes it particularly useful is that it doesn&#8217;t pop up a proper window, just a little floater (I have no idea what it&#8217;s really meant to be called).  As soon as you click somewhere, it disappears.  This makes it incredibly fast to navigate code.</p>
<p>As far as I can see, the closest that NetBeans has is &#8220;File Hierarchy&#8221; on <code>^⇧<span style="font-variant: small-caps">F12</span></code>.  But this pops up a big old clunky dialog box.</p>
<p>That&#8217;s one more thing about NetBeans — the key bindings are <em>weird</em>.  And I speak as a long time emacs user.  Now I&#8217;ll learn them (as it&#8217;s annoying to carry my customisations everywhere).  But they conflict badly with a lot of Mac keyboards, because they&#8217;re extremely function-key heavy, and the mac likes to take over the function keys for itself.</p>
<p>The other Eclipse feature I use the whole damn time is &#8220;assign to local variable&#8221;.  Yes, you can curse me for being damned lazy.  But, I want to be able to type <code>new PhoneImpl("01273", "123456");</code> then hit a key and get it assigned to a variable.  In Eclipse, that&#8217;s <code>⌘-T L</code>.  I couldn&#8217;t find a way to do it in NetBeans.  The compiler knows what type it&#8217;s going to be.  Why should I have to remember?  Otherwise I&#8217;d be back in Emacs.</p>
<p>There are a couple of missing refactorings I use a lot: &#8220;Extract to local variable&#8221; and &#8220;inline local variable&#8221;.  Both are easily replaced with cut&#8217;n'paste 90% of the time.</p>
<p>One particular feature that Eclipse and NetBeans both share is terrible defaults for exceptions.  Here&#8217;s Eclipse&#8217;s default:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://example.com/&quot;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
      e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>And here&#8217;s NetBeans.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://example.com/&quot;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>Main.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">SEVERE</span>, <span style="color: #000066; font-weight: bold;">null</span>, ex<span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Both of these are fundamentally broken, and going to catch out dozens of unwitting programmers who don&#8217;t know any better.  Yes, you can change the defaults, but most people don&#8217;t.</p>
<p>Anyway I don&#8217;t want you to think that I&#8217;m totally down on NetBeans.  The new release maintains what I first saw in 6.1: a very fast, full featured IDE.  It&#8217;s dead easy to get going, and there is loads of documentation.  I find the project view to be much more useful and better organised than the eclipse view of the same.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2008/11/netbeans-project-view.png" alt="NetBeans Project View" border="0" width="287" height="262" /></div>
<p>I suspect that most of the problems I&#8217;ve been having are down to the fact I&#8217;ve been using Eclipse for 3 years, and NetBeans for a few hours at best.</p>
<p>One thing I did like very much is that there&#8217;s builtin Maven support.  I downloaded the Java SE installation<sup><a href="#fn2">2</a></sup>, went to the plugins window and selected &#8220;maven&#8221;.  About a minute later I had a working installation.  And I can create new projects with archetypes really simply.    And it&#8217;s dead simple to add new libraries as needed (I&#8217;m guessing it uses the nexus indexer to look stuff up).  The only missing thing is the dependency viewer, but I can always run <a href="http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html">dependency:tree</a> and <a href="http://maven.apache.org/plugins/maven-dependency-plugin/analyze-mojo.html">dependency:analyze</a> manually.</p>
<p>Funnily enough, where I think NetBeans really wins is the dynamic languages support.  I&#8217;ve been following <a href="http://blogs.sun.com/tor/">Tor&#8217;s blog</a> for a little while and I&#8217;m <em>incredibly</em> impressed with what has been achieved in the Ruby support.  For developing Ruby code, I head straight for NetBeans.  Most of the issues I&#8217;ve outlined above are really specific to statically typed languages.  For dynamic languages like Ruby (and now PHP and Python), what NetBeans gives you is a big win over the standard text editor.</p>
<p>Heck, the JavaScript support is pretty decent too.  The first thing I did today was open up <a href="http://code.google.com/p/jslint4java/">jslint4java</a> and jump into <a href="http://www.JSLint.com/fulljslint.js">fulljslint.java</a>.  That&#8217;s some pretty scary code.  But NetBeans handled it with no issues at all.  And it even pointed out a warning that&#8217;s easy to overlook (a duplicate hash key).</p>
<p>So, the big question is — am I going to use NetBeans?  For any Ruby stuff, there&#8217;s no question.  For Java stuff, I&#8217;m going to give it a try.  After spending enough time with it to write this, I&#8217;ve already figured out enough stuff to use it a bit more successfully.</p>
<p><sup id="fn1">1</sup> Apart from Emacs, Vim and TextMate.  ☺</p>
<p><sup id="fn2">2</sup> I didn&#8217;t like the look of the Java EE version — I don&#8217;t really need 3 application servers bundled, do I?</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/11/20/netbeans-65/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The best subversion client</title>
		<link>http://happygiraffe.net/blog/2008/11/20/the-best-subversion-client/</link>
		<comments>http://happygiraffe.net/blog/2008/11/20/the-best-subversion-client/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 10:20:54 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[git]]></category>

		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1412</guid>
		<description><![CDATA[The best subversion client I&#8217;ve used to date?  git.  It&#8217;s so script-friendly!  This morning somebody asked me for a complete history of a project in CSV format.  Using my nicely cloned repository, it was a simple matter of giving the correct format to git log.

  &#x21D2; git log --pretty='format:%h,%ai,%an,%s' &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>The best subversion client I&#8217;ve used to date?  <a href="http://www.kernel.org/pub/software/scm/git/docs/git-svn.html"><code>git</code></a>.  It&#8217;s <em>so</em> script-friendly!  This morning somebody asked me for a complete history of a project in CSV format.  Using my nicely cloned repository, it was a simple matter of giving the correct format to <a href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html#_pretty_formats">git log</a>.</p>
<pre>
  &#x21D2; git log --pretty='format:%h,%ai,%an,%s' | head -5
  f584913,2008-09-26 21:58:02 +0000,Dominic Mitchell,Pull out a base class for OptionInstances.
  803a32a,2008-09-26 21:57:38 +0000,Dominic Mitchell,Organise imports.
  1cb0132,2008-09-26 21:57:17 +0000,Dominic Mitchell,Switch from a Set of OptionInstance to a Map from Option to OptionInstance.
  a0c1efd,2008-09-26 21:56:56 +0000,Dominic Mitchell,Introduce OptionInstance.
  a211ae3,2008-09-26 21:55:59 +0000,Dominic Mitchell,Use standard idiom for emptying a Set
</pre>
<p>I <em>love</em> how git embodies the Unix toolkit approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/11/20/the-best-subversion-client/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Time Zones, done better</title>
		<link>http://happygiraffe.net/blog/2008/11/09/time-zones-done-better/</link>
		<comments>http://happygiraffe.net/blog/2008/11/09/time-zones-done-better/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 21:48:30 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[datetime]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1409</guid>
		<description><![CDATA[A few days ago, I signed up to HuffDuffer (love the logo, BTW).  However, once I&#8217;d registered, my profile page said Huffduffing since November 1st, 2008.  Which was a little weird, as when I did this it was October 31st.
So I filed a bug report and Jeremy quickly spotted the problem: the server [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, I signed up to <a href="http://huffduffer.com/">HuffDuffer</a> (<em>love</em> the logo, BTW).  However, once I&#8217;d registered, my profile page said <q>Huffduffing since November 1st, 2008</q>.  Which was a little weird, as when I did this it was October 31<sup>st</sup>.</p>
<p>So I filed a bug report and <a href="http://adactio.com/">Jeremy</a> quickly spotted the problem: the server was running in Australia, so was using an <a href="http://en.wikipedia.org/wiki/Time_in_Australia">Australian timezone</a>.  That&#8217;s about 11 hours ahead, which would put my signup in to the next day.  His fix was simple: force huffduffer to use <a href="http://en.wikipedia.org/wiki/Greenwich_Mean_Time">GMT</a> (see <a href="http://php.net/manual/en/datetime.configuration.php">datetime configuration</a> in the PHP manual).  This isn&#8217;t a 100% correct solution, but it&#8217;s definitely the least bad approach.</p>
<p>But it set me wondering: can we do better?  The key thing is that something somewhere has to know what time zone you&#8217;re in.  That thing happens to be your browser.  JavaScript <code>Date</code> objects have a <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/getTimezoneOffset"><code>getTimezoneOffset()</code></a> method which return the minutes difference between you and GMT.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTimezoneOffset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Right now, when I <a href="javascript:alert(new Date().getTimezoneOffset());">try it</a>, it returns zero because I&#8217;m in british winter time, which just happens to be the same as GMT.  If I was in Australia, it&#8217;d return 660 (11 hours).</p>
<p>So we know the time on the server, and we know how far away from GMT we are.  So how do we get JavaScript to format the date correctly?</p>
<p>Obviously, the first step is to pass the time to the browser as GMT.  The normal approach to this is to use the <a href="http://en.wikipedia.org/wiki/Unix_time">Unix time</a> format (number of seconds since midnight 1970).  In PHP, look at <a href="http://www.php.net/manual/en/function.gmmktime.php">gmmktime()</a>.  Perl uses <a href="http://perldoc.perl.org/functions/gmtime.html">gmtime()</a>.  And JavaScript has a constructor which takes milliseconds.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>0<span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">// Thu Jan 01 1970 01:00:00 GMT+0100 (BST)</span></pre></div></div>

<p>Ooops.  That&#8217;s an hour ahead.  But it&#8217;s actually misleading: the internal representation (the milliseconds we are passing in) doesn&#8217;t have a timezone, it&#8217;s only applied when you turn it into a human readable form.  You can demonstrate this by using <a href="http://www.mozilla.org/rhino/">rhino</a> on the command line to fool Javascript in to thinking it&#8217;s in different time zones<sup><a href="#fn1">1</a></sup>.</p>
<p>First, let&#8217;s try it in my time zone:</p>
<pre>
  % java -jar js.jar -e "print(new Date(0))"
  Thu Jan 01 1970 00:00:00 GMT-0000 (GMT)
</pre>
<p>Now let&#8217;s pretend we&#8217;re in Australia:</p>
<pre>
  % TZ=Australia/Melbourne java -jar js.jar -e 'print(new Date(0))'
  Thu Jan 01 1970 10:00:00 GMT+1000 (EST)
</pre>
<p>Which makes things really easy for us: get the server to pass the unix time, create a new Date object from it and then rewrite the textual object based on the contents.</p>
<p>So, if you start out with some HTML like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">  &lt;p&gt;At the third stroke, it will be &lt;span class=&quot;datetime&quot; unixtime=&quot;1225461600&quot;&gt;2008-10-31 14:00:00&lt;/span&gt;.&lt;/p&gt;</pre></div></div>

<p>Note that we include the default (GMT) time in order to degrade gracefully.</p>
<p>Then you can use some JavaScript like this to automatically adjust it to the time zone of the browser.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span.datetime&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">hasAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'unixtime'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span>;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">var</span> unixtime <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'unixtime'</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #006600; font-style: italic;">// Convert seconds to milliseconds</span>
        <span style="color: #003366; font-weight: bold;">var</span> date <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span>unixtime <span style="color: #339933;">*</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span>;
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>format_date<span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>I&#8217;m relying on <a href="http://jquery.com/">jquery</a> a little bit in there in order to focus on the problem, not the DOM.  You can download the full source if needed (<a href="http://happygiraffe.net/blog/wp-content/uploads/2008/11/tzadjust.zip" title="tzadjust.zip">tzadjust.zip</a>).</p>
<p>This is such a teeny-tiny thing overall, but it&#8217;s part of the polish to help make your site great.</p>
<p><sup id="fn1">1</sup> You can change the timezone of any command this way in Unix.  I have <code>alias nydate='TZ=America/New_York date'</code> in my shell profile so I can quickly see what the time in New York is.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/11/09/time-zones-done-better/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Jasypt++</title>
		<link>http://happygiraffe.net/blog/2008/11/08/jasypt-2/</link>
		<comments>http://happygiraffe.net/blog/2008/11/08/jasypt-2/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 19:18:38 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1406</guid>
		<description><![CDATA[Once again, jasypt (&#8221;Java Simplified Encryption&#8221;) makes me smile.
Java comes with a comprehensive set of encryption utilities: JCE.  I had to do some decryption the other day and ended up with this code.

public class Decryptor &#123;
    private static final String ALGORITHM = &#34;PBEWithMD5AndDES&#34;;
&#160;
    private final Base64 base64 = [...]]]></description>
			<content:encoded><![CDATA[<p>Once <a href="http://happygiraffe.net/blog/2008/07/22/jasypt/">again</a>, <a href="http://jasypt.org/">jasypt</a> (&#8221;Java Simplified Encryption&#8221;) makes me smile.</p>
<p>Java comes with a comprehensive set of encryption utilities: <a href="http://java.sun.com/j2se/1.5.0/docs/guide/security/jce/JCERefGuide.html">JCE</a>.  I had to do some decryption the other day and ended up with this code.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Decryptor <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> ALGORITHM <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;PBEWithMD5AndDES&quot;</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Base64 base64 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Base64<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Cipher cipher;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Decryptor<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            cipher <span style="color: #339933;">=</span> Cipher.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>ALGORITHM<span style="color: #009900;">&#41;</span>;
&nbsp;
            <span style="color: #666666; font-style: italic;">// Just generate an empty salt as we don't want to use one.</span>
            <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> salt <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span>cipher.<span style="color: #006633;">getBlockSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>;
            <span style="color: #003399;">Arrays</span>.<span style="color: #006633;">fill</span><span style="color: #009900;">&#40;</span>salt, <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> 0<span style="color: #009900;">&#41;</span>;
&nbsp;
            <span style="color: #666666; font-style: italic;">// Set up the cipher.</span>
            PBEKeySpec pbeKeySpec <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PBEKeySpec<span style="color: #009900;">&#40;</span>password.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
            SecretKeyFactory factory <span style="color: #339933;">=</span> SecretKeyFactory.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>ALGORITHM<span style="color: #009900;">&#41;</span>;
            SecretKey key <span style="color: #339933;">=</span> factory.<span style="color: #006633;">generateSecret</span><span style="color: #009900;">&#40;</span>pbeKeySpec<span style="color: #009900;">&#41;</span>;
            PBEParameterSpec parameterSpec <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PBEParameterSpec<span style="color: #009900;">&#40;</span>salt, <span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span>;
            cipher.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>Cipher.<span style="color: #006633;">DECRYPT_MODE</span>, key, parameterSpec<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NoSuchAlgorithmException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>NoSuchPaddingException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InvalidKeySpecException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InvalidKeyException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InvalidAlgorithmParameterException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> decrypt<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> cipherText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// cipherText is base64, so will always be ASCII.</span>
            <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> cipherBytes <span style="color: #339933;">=</span> base64.<span style="color: #006633;">decode</span><span style="color: #009900;">&#40;</span>cipherText.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;US-ASCII&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> decryptedMessage <span style="color: #339933;">=</span> cipher.<span style="color: #006633;">doFinal</span><span style="color: #009900;">&#40;</span>cipherBytes<span style="color: #009900;">&#41;</span>;
            <span style="color: #666666; font-style: italic;">// Assume encrypted text is UTF-8.</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>decryptedMessage, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">UnsupportedEncodingException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>IllegalBlockSizeException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>BadPaddingException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This does also include conversion from base64 using Apache <a href="http://commons.apache.org/codec/">commons-codec</a>, but it&#8217;s a lot of code.  Even though I&#8217;ve tried to make things simpler (attempting to not use a salt [and I <em>am</em> aware of the consequences]), there&#8217;s still a lot of baggage.</p>
<p>Which is why I&#8217;m so grateful to have found jasypt.  Essentially, all the above code is wrapped up for you in a nice little API.  The above comes down to:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">  SimplePBEConfig config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimplePBEConfig<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  config.<span style="color: #006633;">setPassword</span><span style="color: #009900;">&#40;</span>password<span style="color: #009900;">&#41;</span>;
  config.<span style="color: #006633;">setSaltGenerator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> ZeroSaltGenerator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  StandardPBEStringEncryptor encryptor <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StandardPBEStringEncryptor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  encryptor.<span style="color: #006633;">decrypt</span><span style="color: #009900;">&#40;</span>cipherText<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>So why did I have to write the code in the first place?  Well, we need to get a 3rd party to implement it, and I can&#8217;t enforce dependencies upon them.  But the difference in the amount of code is shocking.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/11/08/jasypt-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>vim completion</title>
		<link>http://happygiraffe.net/blog/2008/10/30/vim-completion/</link>
		<comments>http://happygiraffe.net/blog/2008/10/30/vim-completion/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 14:54:10 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[tips]]></category>

		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1404</guid>
		<description><![CDATA[I&#8217;ve just found something rather useful in vim:  :set wildmode.  Normally in vim, you can use TAB to complete filenames.  So you enter :e some/ve&#60;TAB&#62; and vim pads it out to :e some/very_long_filename.html.  Lovely.
But in a directory full of files with similar prefixes, it&#8217;s less than helpful.  I hit :e [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just found something rather useful in <a href="http://www.vim.org/">vim</a>:  <a href="http://www.vim.org/htmldoc/options.html#%27wildmode%27">:set wildmode</a>.  Normally in vim, you can use TAB to complete filenames.  So you enter <code>:e some/ve&lt;TAB&gt;</code> and vim pads it out to <code>:e some/very_long_filename.html</code>.  Lovely.</p>
<p>But in a directory full of files with similar prefixes, it&#8217;s less than helpful.  I hit <code>:e acc&lt;TAB&gt;</code> and vim expands to <code>:e acc_click_here_to_continue.html</code>.  But then I need to backspace all the way back so it reads <code>:e acc</code> and hit TAB again.  This is a pain.</p>
<p>But, if you stick <code>set wildmode=longest,full</code> into <code>~/.vimrc</code>, then vim stops when it&#8217;s completed the longest unique prefix (&#8221;acc&#8221;) and gives you a chance to type.  Or, if you just keep banging on the TAB key like a deranged gibbon it will start rotating through all the possible completions.  But by stopping at that point, I get a chance to intervene.</p>
<p>It sounds like a teeny-tiny little thing.  But it&#8217;s one less thing that&#8217;s getting in the way of me doing things.</p>
<p>That said, any time saved has already been wiped out by writing this blog entry.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/10/30/vim-completion/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Malware removal</title>
		<link>http://happygiraffe.net/blog/2008/10/30/malware-removal/</link>
		<comments>http://happygiraffe.net/blog/2008/10/30/malware-removal/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 01:06:46 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1400</guid>
		<description><![CDATA[I&#8217;ve spent a fun evening1 trying to get rid of some insidious malware on the house gaming PC.  I think it&#8217;s mostly gone, though I&#8217;m not certain (and I don&#8217;t have the day&#8217;s time to reinstall everything).  However, I did find some useful stuff along the way.
Firstly, even though googling for something related [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent a fun evening<sup><a href="#fn1">1</a></sup> trying to get rid of some insidious malware on the house gaming PC.  I think it&#8217;s mostly gone, though I&#8217;m not certain (and I don&#8217;t have the day&#8217;s time to reinstall everything).  However, I did find some useful stuff along the way.</p>
<p>Firstly, even though googling for something related to the malware will turn up <a href="http://www.symantec.com/security_response/writeup.jsp?docid=2008-050916-1055-99&#038;tabid=2">some</a> <a href="http://www.exterminate-it.com/malpedia/remove-tdsserv">information</a> about it, chances are that it&#8217;s a bloody <a href="http://en.wikipedia.org/wiki/Rootkit">rootkit</a> that&#8217;s thrust itself into the windows kernel like a rhino in heat.  So you won&#8217;t be able to see, or delete the files it&#8217;s talking about.</p>
<p>Finding out problems that are being covered up by the rootkit is greatly aided by the wonderful <a href="http://technet.microsoft.com/en-us/sysinternals/default.aspx">sysinternals</a> utilities.  In particular <a href="http://technet.microsoft.com/en-us/sysinternals/bb897445.aspx">RootkitRevealer</a> successfully found a number of hidden registry entries.  Later on, <a href="http://technet.microsoft.com/en-us/sysinternals/bb963902.aspx">AutoRuns</a> helped me to find a few other things lurking around my boot process.</p>
<p>But the real <em>pièce de résistance</em> was <a href="http://home.eunet.no/pnordahl/ntpasswd/">ntpasswd</a>: a miniature bootable Linux, only 3Mb, which made finding and removing those troublesome files (even though they&#8217;re on an <a href="http://en.wikipedia.org/wiki/NTFS">NTFS</a> partition) a snap.  I like it a lot.  Plus, it&#8217;ll let you change the admin password on people&#8217;s PCs, so I may have to take it in to work.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Anyway, the end result is that I&#8217;ve spent a couple of hours working on something I don&#8217;t particularly care about by somebody on the other side of the planet who doesn&#8217;t know me from Adam.  Isn&#8217;t the Internet a sheer bloody marvel?</p>
<p>Now.  Work or bed?</p>
<p id="fn1"><sup>1</sup> as in &#8220;not fun at all.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/10/30/malware-removal/feed/</wfw:commentRss>
		</item>
		<item>
		<title>mod_perl 1 blows chunks</title>
		<link>http://happygiraffe.net/blog/2008/10/07/mod_perl-1-blows-chunks/</link>
		<comments>http://happygiraffe.net/blog/2008/10/07/mod_perl-1-blows-chunks/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 11:37:56 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[mod_perl]]></category>

		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1398</guid>
		<description><![CDATA[At $WORK, I&#8217;m looking at a web service built on mod_perl 1 / Apache 1.  The service takes XML as input and returns XML as output.  So far, so good.
Unfortunately, whilst I was testing with curl, I found something odd:

  curl -s -v -T- -H'Content-Type: text/xml;charset=UTF-8' http://localhost/api &#60; input.xml

That -T- says to [...]]]></description>
			<content:encoded><![CDATA[<p>At $WORK, I&#8217;m looking at a web service built on <a href="http://perl.apache.org/docs/1.0/index.html">mod_perl 1</a> / <a href="http://httpd.apache.org/docs/1.3/">Apache</a> 1.  The service takes XML as input and returns XML as output.  So far, so good.</p>
<p>Unfortunately, whilst I was testing with <a href="http://curl.haxx.se/">curl</a>, I found something odd:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">  curl <span style="color: #660033;">-s</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-T-</span> <span style="color: #660033;">-H</span><span style="color: #ff0000;">'Content-Type: text/xml;charset=UTF-8'</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost<span style="color: #000000; font-weight: bold;">/</span>api <span style="color: #000000; font-weight: bold;">&lt;</span> input.xml</pre></div></div>

<p>That <code>-T-</code> says to do a PUT request from stdin.  It fails and my code returned &#8220;no input&#8221;.</p>
<p>But when I did this, things worked:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">  curl <span style="color: #660033;">-s</span> <span style="color: #660033;">-v</span> -Tinput.xml <span style="color: #660033;">-H</span><span style="color: #ff0000;">'Content-Type: text/xml;charset=UTF-8'</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost<span style="color: #000000; font-weight: bold;">/</span>api</pre></div></div>

<p>That reads directly from the file.  The only difference between the two requests is that the latter includes a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13">Content-Length</a> header whilst the former has <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.41">Transfer-Encoding: chunked</a> instead.</p>
<p>This is the code that was reading the request.</p>

<div class="wp_syntax"><div class="code"><pre class="perl perl" style="font-family:monospace;">    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$content</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header_in</span><span style="color: #009900;">&#40;</span> <span style="">'Content-Type'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">read</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$content</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header_in</span><span style="color: #009900;">&#40;</span> <span style="">'Content-Length'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">return</span> <span style="color: #0000ff;">$content</span>;</pre></div></div>

<p>So, if there&#8217;s no Content-Length, what should we do?  My first stop is always the venerable <a href="http://oreilly.com/catalog/9781565925670/">eagle book</a>.  There&#8217;s a little footnote next to <a href="http://www.modperl.com/book/chapters/ch9.html#item_read">read()</a>:</p>
<blockquote cite="http://www.modperl.com/book/chapters/ch9.html#item_read">
<p>At the time of this writing, HTTP/1.1 requests which do not have a Content-Length header, such as one that uses chunked encoding, are not properly handled by this API.</p>
</blockquote>
<p>Marvellous.  Now, I had a look around in <a href="http://search.cpan.org/src/GOZER/mod_perl-1.30/Apache/Apache.pm">the source code</a> and noticed a function called <code>new_read()</code>.  Unfortunately, that failed to work.  It stopped chunked reads, but failed to work for ordinary ones.</p>
<p>I did see <a href="http://markmail.org/message/agrmbuijzmmszjsi">a post</a> on the mod_perl mailing list which reckoned you could loop and read all input.  But I was unable to get that to work either.</p>
<p>So I just decided to disallow chunked input.  That&#8217;s fairly easy to do, and HTTP has a special status code for it: <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.12">411 Length Required</a>.  It&#8217;s not ideal, but unless this project gets upgraded to Apache 2 (unlikely, quite frankly), it seems to be the best option.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/10/07/mod_perl-1-blows-chunks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Embedding the maven version number</title>
		<link>http://happygiraffe.net/blog/2008/10/01/embedding-the-maven-version-number/</link>
		<comments>http://happygiraffe.net/blog/2008/10/01/embedding-the-maven-version-number/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 21:58:08 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1396</guid>
		<description><![CDATA[If you build a jar file with maven, it helpfully embeds a properties file so that you can pull out information about the build environment.  You just need some code like this.

  String path = &#34;/META-INF/maven/groupId/artifactId/pom.properties&#34;
  InputStream stream = getClass&#40;&#41;.getResourceAsStream&#40;path&#41;;
  Properties props = new Properties&#40;&#41;;
  props.load&#40;stream&#41;;
  System.out.println&#40;&#34;my version is&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>If you build a jar file with maven, it helpfully embeds a properties file so that you can pull out information about the build environment.  You just need some code like this.</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;">  <span style="color: #003399;">String</span> path <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/META-INF/maven/groupId/artifactId/pom.properties&quot;</span>
  <span style="color: #003399;">InputStream</span> stream <span style="color: #339933;">=</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span>path<span style="color: #009900;">&#41;</span>;
  <span style="color: #003399;">Properties</span> props <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Properties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  props.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span>;
  <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my version is&quot;</span> <span style="color: #339933;">+</span> props.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;version&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Now, this is all well and good, but it only works when you&#8217;ve built the artifact<sup><a href="#fn1">1</a></sup>.  In development, it simply doesn&#8217;t exist, and you have to work around that in the code.</p>
<p>It would be much simpler if you could just compile in the version as a constant.</p>
<p>Thankfully, when I <a href="http://markmail.org/message/jyx6fasute5v3zxz">asked the question</a> on the maven-users list, Lee Meador showed me <a href="http://markmail.org/message/qaath7i2u3whlpbz">an example</a>.  In a nutshell, you use ant to generate an extra source file containing the version number.</p>
<p>First, you need a little ant script to emit some Java code.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;..&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;generate-version&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;generate-version&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${src.dir}/com/mycompany/myproject&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${src.dir}/com/mycompany/myproject/Version.java&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            package com.mycompany.myproject;
            /** Automatically generated by ant. */
            public class Version {
              public static final String VERSION = &quot;${version}&quot;;
            }
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then, you need to add the <a href="http://maven.apache.org/plugins/maven-antrun-plugin/">antrun plugin</a> to your <code>pom.xml</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.maven.plugins<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-antrun-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>generate-version-class<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>generate-sources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>run<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tasks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ant</span> <span style="color: #000066;">antfile</span>=<span style="color: #ff0000;">&quot;etc/build-version.xml&quot;</span> <span style="color: #000066;">inheritAll</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">inheritRefs</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;version&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${project.version}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;src.dir&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${project.build.directory}/generated-sources&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ant<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tasks<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sourceRoot<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            ${project.build.directory}/generated-sources
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sourceRoot<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This binds the <a href="http://maven.apache.org/plugins/maven-antrun-plugin/run-mojo.html">antrun:run</a> goal to the &#8220;generate-sources&#8221; phase (which happens right at the start of the build).  It runs the little ant script above, passing in the correct properties.  Then, it adds a new source directory, so maven knows to compile that one file that we&#8217;re generating.</p>
<p>When I initially tried this in Eclipse, it couldn&#8217;t find the <code>Version</code> class.  However,  running &#8220;Maven → Update Project Configuration&#8221; added <code>target/generated-sources</code> as a new source folder.  And everything worked just fine after that.  If you don&#8217;t have that option, you need to update to a new version of <a href="http://m2eclipse.codehaus.org/">m2eclipse</a>.  Deleting and reimporting the project should sort it out.</p>
<p>This might seem like a fairly complicated way of solving the problem of getting the maven version number.  But it&#8217;s more reliable than any of the other methods I have seen, so I&#8217;m pretty happy with it.</p>
<p><sup id="fn1">1</sup> Yeah, <a href="http://adactio.com/journal/1515/">I know</a>.  American spelling.  I&#8217;ve been polluted by years of exposure.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/10/01/embedding-the-maven-version-number/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Advertisments</title>
		<link>http://happygiraffe.net/blog/2008/09/30/advertisments/</link>
		<comments>http://happygiraffe.net/blog/2008/09/30/advertisments/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 07:59:51 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[ads]]></category>

		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1394</guid>
		<description><![CDATA[I&#8217;ve seen advertising targeted at developers for a long time.  DDJ &#038; Linux Journal are full of them.  But TV ads are somewhat of a new territory.  But I&#8217;ve realised that more and more, open source projects are doing video adverts.  What really struck it home for me was seeing the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen advertising targeted at developers for a <em>long</em> time.  <a href="http://www.ddj.com/">DDJ</a> &#038; <a href="http://www.linuxjournal.com/">Linux Journal</a> are full of them.  But TV ads are somewhat of a new territory.  But I&#8217;ve realised that more and more, open source projects are doing video adverts.  What really struck it home for me was seeing the <a href="http://googlemac.blogspot.com/2008/09/revving-software-with-update-engine.html">anouncement</a> for the new <a href="http://code.google.com/p/update-engine/">Google Update Engine</a>:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/9K_W5Af99PU&#038;hl=en&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/9K_W5Af99PU&#038;hl=en&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>It&#8217;s an advert if ever I saw one.  Yes, it&#8217;s a tech presentation, but it&#8217;s an advert.</p>
<p>Video for developers is something that&#8217;s been growing for a while.  One of the reasons for <a href="http://www.rubyonrails.org/">Rails</a> taking off  was the <a href="http://www.rubyonrails.org/screencasts">screencast</a> showing how simple it was to get started.  And I learned tonnes about Textmate from the screencasts that <a href="http://wiki.macromates.com/Profiles/AllanOdgaard">Allan Odgaard</a> posted to the <a href="http://blogmacromates.com/">textmate blog</a>.</p>
<p>But it&#8217;s not just the flashy GUI things that have videos.  If an <a href="http://ociweb.com/jnb/jnbSep2008.html">XML writing library</a> can have a <a href="http://www.youtube.com/watch?v=22aiGJhzbX8">video introduction</a>, what can&#8217;t?</p>
<p>It&#8217;s great that we have these resources, as developers.  I certainly didn&#8217;t think I&#8217;d see such <em>focused</em> media that I&#8217;m actually interested in.  But as a developer, it does raise the bar for getting your project noticed.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/09/30/advertisments/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Managing 3rd Party Code</title>
		<link>http://happygiraffe.net/blog/2008/09/23/managing-3rd-party-code/</link>
		<comments>http://happygiraffe.net/blog/2008/09/23/managing-3rd-party-code/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 22:04:31 +0000</pubDate>
		<dc:creator>dom</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[git]]></category>

		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1392</guid>
		<description><![CDATA[I&#8217;m in a pickle.  There&#8217;s a project at $WORK that I should have been paying closer attention to (but haven&#8217;t).  We&#8217;ve taken some 3rd party software (guanxi as it happens), and made some modifications in order to form our own custom distribution.  But:

We started modifying what was then the trunk.
The trunk has [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m in a pickle.  There&#8217;s a project at $WORK that I should have been paying closer attention to (but haven&#8217;t).  We&#8217;ve taken some 3rd party software (<a href="http://www.guanxi.uhi.ac.uk/">guanxi</a> as it happens), and made some modifications in order to form our own custom distribution.  But:</p>
<ul>
<li>We started modifying what was then the trunk.</li>
<li>The trunk has moved forwards.</li>
<li>Our modifications are not isolated chunks of work (though they should be).</li>
</ul>
<p>In other words, it&#8217;s a classic <a href="http://en.wikipedia.org/wiki/Merge_(revision_control)">merge</a> scenario.  Except that both our changes and the trunk are contained within a <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System">CVS</a> repository.  This means that the original ancestor (the point at which divergence started) can be somewhat difficult to ascertain.</p>
<p>Thankfully, I&#8217;ve had moderate success using <a href="http://www.kernel.org/pub/software/scm/git/docs/git-cvsimport.html"><code>git cvsimport</code></a> to pull everything into a git repository.  Well, actually five git repositories, thanks to <code>git cvsimport</code> not <em>quite</em> understanding CVS&#8217; modules file format.  So, <a href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"><code>git merge</code></a> should assist me.  But of course, I&#8217;m unfamiliar enough with the guanxi code to know how to successfully resolve conflicts.  Best of all, it looks like new development which is similar to ours is happening on a <a href="http://guanxi.cvs.sourceforge.net/guanxi/Common/?pathrev=METADATA_MANAGEMENT_010808">branch</a> destined to go into the trunk.</p>
<p>Where does this leave me?  For now, a long session of merging with the developer who did the changes.  But longer term, we also need to:</p>
<ul>
<li>Split out our code changes into their own packages (or for preference, project).</li>
<li><em>Regularly</em> merge in changes from trunk.</li>
<li>Talk to the <a href="http://codebrane.com/blog/">original developer</a> about whether or not he can make life easier for us.</li>
<li>Switch to using git proper rather than developing in the original CVS tree.</li>
</ul>
<p>It doesn&#8217;t help that the project in question is a Java webapp &#8212; we want to reuse the classes in that webapp as a jar file in our own webapp.  This is yet another complicating factor…</p>
<p>My head hurts.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/09/23/managing-3rd-party-code/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
