<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://beust.com/weblog/wp-atom.php">
	<title type="text">Otaku, Cedric's blog</title>
	<subtitle type="text">Thoughts about software development</subtitle>

	<updated>2010-07-29T14:25:42Z</updated>
	<generator uri="http://wordpress.org/" version="2.9.2">WordPress</generator>

	<link rel="alternate" type="text/html" href="http://beust.com/weblog" />
	<id>http://beust.com/weblog/feed/atom/</id>
	

			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/beust/OtakuRdf" /><feedburner:info uri="beust/otakurdf" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[JCommander 1.4]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/99apRIGp2bY/" />
		<id>http://beust.com/weblog/?p=803</id>
		<updated>2010-07-29T14:25:42Z</updated>
		<published>2010-07-29T14:25:42Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[They say that a Java framework is not complete until it provides factories, and since it&#8217;s something that JCommander was still lacking, it had to be fixed.

Introducing JCommander 1.4.

Here is what&#8217;s new:

You can now specify default values in a more flexible way than at field declaration time (documentation).
You can use string converter factories instead of [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/29/jcommander-1-4/"><![CDATA[<p>They say that a Java framework is not complete until it provides factories, and since it&#8217;s something that JCommander was still lacking, it had to be fixed.</p>
<p>
Introducing JCommander 1.4.</p>
<p>
Here is what&#8217;s new:</p>
<ul>
<li>You can now specify default values in a more flexible way than at field declaration time (<a href="http://beust.com/jcommander#Default_values">documentation</a>).
<li>You can use string converter factories instead of specifying converter classes on each <tt>@Parameter</tt> annotation (<a href="http://beust.com/jcommander#Custom_types">documentation</a>).
<li>The usage is now prettier:
<pre class="brush: plain">
Usage: &lt;main class&gt; [options]
  Options:
    -debug          Debug mode (default: false)
    -groups         Comma-separated list of group names to be run
  * -log, -verbose  Level of verbosity (default: 1)
    -long           A long number (default: 0)
</pre>
<li>Many bug fixes and a more clever option parsing to cover odd cases.
<li>This release actually contains more features but I&#8217;m not telling.
</ul>
<p>All the goodness available <a href="http://beust.com/jcommander">at the usual place</a>. Operators are standing by, order now!</p>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/29/jcommander-1-4/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/29/jcommander-1-4/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/29/jcommander-1-4/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[Now, *this* is a feature that gets me excited about Firefox 4]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/eKi7Zl1urR0/" />
		<id>http://beust.com/weblog/?p=806</id>
		<updated>2010-07-29T05:49:54Z</updated>
		<published>2010-07-29T05:49:54Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[App Tabs in Firefox 4 Beta 2 « Alex Faaborg.
]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/28/now-this-is-a-feature-that-gets-me-excited-about-firefox-4/"><![CDATA[<p><a href="http://blog.mozilla.com/faaborg/2010/07/28/app-tabs-in-firefox-4-beta-2/">App Tabs in Firefox 4 Beta 2 « Alex Faaborg</a>.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/28/now-this-is-a-feature-that-gets-me-excited-about-firefox-4/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/28/now-this-is-a-feature-that-gets-me-excited-about-firefox-4/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/28/now-this-is-a-feature-that-gets-me-excited-about-firefox-4/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[Why Scala&#8217;s &#8220;Option&#8221; and Haskell&#8217;s &#8220;Maybe&#8221; types won&#8217;t save you from null]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/TZslamYiGGc/" />
		<id>http://beust.com/weblog/?p=795</id>
		<updated>2010-07-28T21:43:34Z</updated>
		<published>2010-07-28T20:59:43Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[The more I think about it, the less I understand the point in Scala&#8217;s Option class (which originated in Haskell under the name Maybe).
If you read the voluminous material that describes the concepts behind the Option class, there are two main benefits:

It saves you from NullPointerException
It allows you to tell whether null means &#8220;no object&#8221; [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/28/why-scalas-option-and-haskells-maybe-types-wont-save-you-from-null/"><![CDATA[<p>The more I think about it, the less I understand the point in Scala&#8217;s <tt>Option</tt> class (which originated in Haskell under the name <tt>Maybe</tt>).</p>
<p>If you read the voluminous material that describes the concepts behind the <tt>Option</tt> class, there are two main benefits:</p>
<ul>
<li>It saves you from <tt>NullPointerException</tt>
<li>It allows you to tell whether <tt>null</tt> means &#8220;no object&#8221; or &#8220;an object whose value is null&#8221;
</ul>
<p>I claim that <tt>Option</tt> solves none of these problems. Here is why.</p>
<p>Here is a <a href="http://blog.danielwellman.com/2008/03/using-scalas-op.html">typical blog post showing the wonders of <tt>Option</tt></a> (I&#8217;m not singling out this particular person, you will find many posts making similar claims).</p>
<p>
The examples in this post show that with the <tt>Option</tt> class, you can now have hash tables that contain null values and never be confused when a <tt>get()</tt> returns <tt>null</tt>. Fine, but in practice, I find that hash tables allowing <tt>null</tt> values are rare to the point where this limitation has never bothered me in fifteen years of Java.</p>
<p>The claim that <tt>Option</tt> eliminates <tt>NullPointerException</tt> is more outrageous and completely bogus. Here is how you avoid a null pointer exception with the <tt>Option</tt> class (from the blog):</p>
<pre class="brush: scala">
val result = map.get( "Hello" )

result match {
  case None => print "No key with that name!"
  case Some(x) => print "Found value" + x
}
</pre>
<p>See what&#8217;s going on here? You avoid a <tt>NullPointerException</tt> by&#8230; testing against </tt>null</tt>, except that it's called <tt>None</tt>. What have we gained, exactly?</p>
<p>The worst part about this example is that it forces me to deal with the <tt>null</tt> case right here. Sometimes, that's what I want to do but what if such an error is a programming error (e.g. an assertion error) that should simply never happen? In this case, I just want to assume that I will never receive null and I don't want to waste time testing for this case: my application should simply blow up if I get a null at this point.</p>
<p>
And you know what construct does exactly this? <tt>NullPointerException</tt>! Try to reference a null pointer and that exception will be thrown. It will make its way up the stack frames since you probably never catch it anywhere (nor should you) and it will show you a clear stack trace telling you exactly what happened and where.</p>
<p>
In other words, it seems to me that the <tt>Option</tt> class is bringing us back into the stone age of using return values to signal errors. I can't imagine this being a progress (and I'm equally irritated at the Go language for making the same mistake).</p>
<p>When it comes to alleviating the problems caused by null pointer exceptions, the only approach I've seen recently that demonstrates a technical improvement is Fantom (Groovy also supports a similar approach), which attacks the problem from two different angles, static and runtime:</p>
<ul>
<li><b>Static</b>: In Fantom, the fact that a variable can be null or not is captured by a question mark appended to its type:
<pre class="brush: java">
Str   // never stores null
Str?  // might store null
</pre>
<p>  This allows the compiler to reason about the nullability of your code.</p>
<li><b>Runtime</b>: The second aspect is solved by Fantom's "safe invoke" operator, <tt>?.</tt>. This operator allows you to dereference a null pointer without receiving a null pointer exception:
<pre class="brush: java">
// hard way
Str? email := null
if (userList != null)
{
  user := userList.findUser("bob")
  if (user != null) email = user.email
}

// easy way
email := userList?.findUser("bob")?.email
  </pre>
<p>  Note how this second example is semantically equivalent to the first one but with a lot of needless boiler plate removed.
  </ul>
<p>So, can someone explain to me how <tt>Option</tt> addresses the null pointer problem better than Fantom's approach?</p>
<p>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/28/why-scalas-option-and-haskells-maybe-types-wont-save-you-from-null/#comments" thr:count="31" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/28/why-scalas-option-and-haskells-maybe-types-wont-save-you-from-null/feed/atom/" thr:count="31" />
		<thr:total>31</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/28/why-scalas-option-and-haskells-maybe-types-wont-save-you-from-null/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[Local message bus]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/qfNORM-_Mkw/" />
		<id>http://beust.com/weblog/?p=778</id>
		<updated>2010-07-26T18:09:59Z</updated>
		<published>2010-07-26T18:09:59Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[Recently, I started wondering how I could improve the TestNG listener architecture.

TestNG exposes a lot of different listeners, which users can specify before starting a test run (using either of the command line, ant, Maven, testng.xml or programmatically).
These listeners tell you whenever:

A test succeeds, fails or is skipped.
A test method is about to be called [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/26/local-message-bus/"><![CDATA[<p>Recently, I started wondering how I could improve the TestNG listener architecture.</p>
<p>
TestNG exposes a lot of different listeners, which users can specify before starting a test run (using either of the command line, ant, Maven, testng.xml or programmatically).</p>
<p>These listeners tell you whenever:</p>
<ul>
<li>A test succeeds, fails or is skipped.
<li>A test method is about to be called and when it returns.
<li>A configuration method starts or finishes (there are five types of each: suite, test, class, method and group, and you have a before and an after event for each).
<li>A reporter should be notified to update its results (either at the end of the suite run or after each test methd).
</ul>
<p>All these listeners are captured <a href="http://testng.org/javadocs/org/testng/IInvokedMethod.html">by</a> <a href="http://testng.org/javadocs/org/testng/IReporter.html">different</a> <a href="http://testng.org/javadocs/org/testng/ISuiteListener.html">interfaces</a> and they have evolved somewhat organically over these past six years as the needs and requests emerged, showing some overlap in functionalities and also requiring the awkward interface evolution that Java imposes (<a href="http://testng.org/javadocs/org/testng/IAnnotationTransformer.html">exhibit A</a> and <A href="http://testng.org/javadocs/org/testng/IAnnotationTransformer2.html">exhibit B</a>).</p>
<p>One possible solution to such a problem is a message (or event) bus.</p>
<p>Message buses have been around for a very long time and most of <a href="http://picasaweb.google.com/lh/photo/wTJOoGA-teAcWiq0fgWLW5W9A4YlyCGvBl_1gZdsJDM?feat=directlink">my PhD thesis</a> revolved around their usage and their impact on distributed applications. I even wrote one for my PhD called <a href="http://old.koalateam.com/ftp/pub/KoalaTalk/koalatalk.html">Koala Talk</a>. This was around 1993, almost twenty years ago.</p>
<p>
The <em>de facto</em> standard in the Java world is the JMS specification, which has been implemented in many products such as ActiveMQ or RabbitMQ. Both the specification and implementations have been battle tested and proven to be of great usefulness for today&#8217;s software.</p>
<p>
However, JMS is overkill for what I need to do. First of all in terms of functionalities, but also more simply because I need a local software bus, one that will always be passing messages within the same JVM. No network is necessary.</p>
<p>The message bus model brings a lot of simplification to a listener heavy framework such as TestNG. Instead of having to decide which interface and which method are applicable when, all TestNG needs to do is publish events as a test run is progressing. Where these events get handled and who they eventually reach is resolved outside of the TestNG engine.</p>
<p>
Another benefit is that looking at the system in terms of events will allow to remove quite a bit of overlap. For example, in TestNG, you can be notified both when a suite finishes and when your reporter should start doing its work (generating reports). Most of the time, these events coincide.</p>
<p>I started sketching out what such an API could look like and I came up with the following very early draft:</p>
<pre class="brush: java">
public class App {

  @Subscriber
  public void event1(NotifyEvent ne) {
    System.out.println("event1: " + ne);
  }

}
</pre>
<pre class="brush: java">
MessageBus mb = new MessageBus();
mb.register(new App());
mb.post(new NotifyEvent("notify"));
</pre>
<p>Receivers describe the kind of events they are interested in and publishers simply post these events. With these ideas in mind, I started looking around to see if anything like this exists and I quickly came across <a href="http://eventbus.org/">EventBus</a>, by Michael Bushe.</p>
<p>
EventBus turns out to be remarkably close to what I had in mind, including annotation support and type based dispatching. EventBus also supports all kinds of other mechanisms, some I had in mind (string based publishing with regexp matching, event inheritance) and a few others I didn&#8217;t think of (vetos).</p>
<p>
EventBus seems to be very extensive, very well designed and tested (nice job, Michael!), but probably too big for what I need. It also contains quite a few ties to Swing because it apparently started as a support library for Swing applications that publish events (something that Swing developers have to deal with all the time). Admittedly, there is a portion of EventBus that seems to be graphic independent, but I haven&#8217;t been able to really understand its full extent and whether it&#8217;s possible to carve it out at all (I have no interest in dragging in Swing dependencies).</p>
<p>Interestingly, it&#8217;s the only library of that type that I was able to find, so before I dig further, has anyone heard of a framework allowing the kind of simple intra JVM publish/subscribe functionality I&#8217;m looking for?</p>
<p>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/26/local-message-bus/#comments" thr:count="11" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/26/local-message-bus/feed/atom/" thr:count="11" />
		<thr:total>11</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/26/local-message-bus/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[JCommander 1.3]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/2H_Hg6gQ04k/" />
		<id>http://beust.com/weblog/?p=772</id>
		<updated>2010-07-26T15:05:25Z</updated>
		<published>2010-07-26T15:05:25Z</published>
		<category scheme="http://beust.com/weblog" term="General" /><category scheme="http://beust.com/weblog" term="jcommander" />		<summary type="html"><![CDATA[I just released JCommander 1.3, here are the new features:

@ResourceBundle is deprecated and replaced with @Parameters:

@Parameters(resourceBundle = "MessageBundle")
public class ArgsI18N2New {
  
  I had to deprecate @ResourceBundle because I needed a more general annotation in order to implement the next new feature.

You can now use different separators for your options:

java Main -log:3

or

java Main [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/26/jcommander-1-3/"><![CDATA[<p>I just released JCommander 1.3, here are the new features:</p>
<ul>
<li><tt>@ResourceBundle</tt> is deprecated and replaced with <tt>@Parameters</tt>:
<pre class="brush: java">
@Parameters(resourceBundle = "MessageBundle")
public class ArgsI18N2New {
  </pre>
<p>  I had to deprecate <tt>@ResourceBundle</tt> because I needed a more general annotation in order to implement the next new feature.</p>
<p>
<li>You can now use different separators for your options:</p>
<pre class="brush: bash">
java Main -log:3
</pre>
<p>or</p>
<pre class="brush: bash">
java Main -level=42
</pre>
<p>You define the separator with the <tt>@Parameters</tt> annotation:</p>
<pre class="brush: java">
@Parameters(separators = "=")
public class SeparatorEqual {
  @Parameter(names = "-level")
  public Integer level = 2;
}
</pre>
<p>
<li>Parameters can now be hidden, in which case they will not appear in the usage:</p>
<pre class="brush: java">
@Parameter(names = "-debug", description = "Debug mode", hidden = true)
public boolean debug = false;
</pre>
<p>
<li>The usage output is now sorted alphabetically and cleanly aligned:</p>
<pre class="brush: shell">
Usage: [main class] [options] list of files
  Options:
    -b, --bonjour             enable Bonjour.
    -e, --export-preferences  export preferences into the given file.
    -F, --flush-preferences   flush gui preferences.
    -h, --help                show this help.
    -i, --import-preferences  import preferences from the given file.
</pre>
</ul>
<p>Download either <a href="http://beust.com/jcommander">directly</a> or with Maven:</p>
<pre class="brush: xml">
    <dependency>
    	<groupId>com.beust</groupId>
    	<artifactId>jcommander</artifactId>
    	<version>1.3</version>
    </dependency>
</pre>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/26/jcommander-1-3/#comments" thr:count="8" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/26/jcommander-1-3/feed/atom/" thr:count="8" />
		<thr:total>8</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/26/jcommander-1-3/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[Firefox&#8217;s &#8220;Tab Candy&#8221;: pretty, but&#8230;]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/X2H6vYKzqoU/" />
		<id>http://beust.com/weblog/?p=768</id>
		<updated>2010-07-24T15:56:01Z</updated>
		<published>2010-07-24T15:56:01Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[


I&#8217;m not a big fan of Firefox&#8217;s latest experimental feature &#8220;Tab Candy&#8221; for a couple of reasons.

First, I don&#8217;t think that having an application reinvent its own window management system is a step in the direction of better usability. Whatever operating system you are using, it&#8217;s already difficult to navigate through windows efficiently as it [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/24/firefoxs-tab-candy-pretty-but/"><![CDATA[<p align="center">
<img src="http://beust.com/pics/candy-tabs.png" />
</p>
<p>I&#8217;m not a big fan of <a href="http://www.azarask.in/blog/post/tabcandy/"/>Firefox&#8217;s latest experimental feature &#8220;Tab Candy&#8221;</a> for a couple of reasons.</p>
<p>
First, I don&#8217;t think that having an application reinvent its own window management system is a step in the direction of better usability. Whatever operating system you are using, it&#8217;s already difficult to navigate through windows efficiently as it is, but after some time, you become reasonably proficient with it. And now, you find yourself having to learn yet another window management paradigm, with shortcuts that are by definition different from the ones you are used on the desktop, and a space and interaction logic that is going to be subtly different from the OS.</p>
<p>
Second, I tend to use the keyboard to select my windows a lot more than the mouse, so functionalites like Expos&eacute; are of no use to me. Tab Candy seems to be no different.</p>
<p>
What I really need is an extension that lets me switch to a tab by typing a few letters from either its title or its content. Just now, as I was starting to write this entry, I found myself having to find the article I linked above. I have currently about ten Firefox windows open and each of them has anywhere between one and ten tabs. Finding the correct window required a few <tt>Alt-Tab</tt> and quite a few <tt>Alt-~</tt>. And even then, the correct window popped up on my screen several times but I missed it because the tab I was looking for was the fourth in in a group of ten.</p>
<p>
What would have been ideal: a text box where I can type &#8220;candy&#8221; and a drop down containing all the tabs that match the string I just type.</p>
<p>
I&#8217;m aware of a few Chrome extensions that do this but all of them open a new window when you select the tab, instead of just taking you to the existing one, which defeats the purpose of the idea since it loads the page again and loses the position you were last reading.</p>
<p>
Please let me know if you know of any extension that accomplishes what I&#8217;m looking for (ideally on Firefox).</p>
<p>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/24/firefoxs-tab-candy-pretty-but/#comments" thr:count="6" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/24/firefoxs-tab-candy-pretty-but/feed/atom/" thr:count="6" />
		<thr:total>6</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/24/firefoxs-tab-candy-pretty-but/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[MacPaint source code]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/lAUin38DR4I/" />
		<id>http://beust.com/weblog/?p=766</id>
		<updated>2010-07-20T15:12:43Z</updated>
		<published>2010-07-20T15:12:43Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[


Apple gracefully donated the source code of MacPaint and QuickDraw to the San Jose Museum of Computer History. For those of you who don&#8217;t want to bother with downloading and unzipping, here are the full sources.
]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/20/macpaint-source-code/"><![CDATA[<p align="center">
<img src="http://beust.com/pics/macpaint.jpg" />
</p>
<p>Apple gracefully <a href="http://www.computerhistory.org/highlights/macpaint/">donated the source code of MacPaint and QuickDraw to the San Jose Museum of Computer History</a>. For those of you who don&#8217;t want to bother with downloading and unzipping, <a href="http://beust.com/macpaint">here are the full sources</a>.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/20/macpaint-source-code/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/20/macpaint-source-code/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/20/macpaint-source-code/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[JCommander 1.1]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/CEu-NCOGv3g/" />
		<id>http://beust.com/weblog/?p=756</id>
		<updated>2010-07-19T18:45:02Z</updated>
		<published>2010-07-19T17:25:29Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[Version 1.1 of JCommander is now available, here are the new features:
Type converters
By default, JCommander parses the command line into basic types only (strings, booleans, integers and longs). Very often, your application actually needs more complex types, such as files, host names, lists, etc&#8230; You can now write your own type converters by implementing the [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/19/jcommander-1-1/"><![CDATA[<p>Version 1.1 of <a href="http://beust.com/jcommander">JCommander</a> is now available, here are the new features:</p>
<p><h3>Type converters</h3>
<p>By default, JCommander parses the command line into basic types only (strings, booleans, integers and longs). Very often, your application actually needs more complex types, such as files, host names, lists, etc&#8230; You can now write your own type converters by implementing the following interface:</p>
<pre class="brush: java">
public interface IStringConverter&lt;T&gt; {
  T convert(String value);
}
</pre>
<p>For example, here is a converter that turns a string into a <tt>File</tt>:</p>
<pre class="brush: java">
public class FileConverter implements IStringConverter&lt;File&gt; {
  @Override
  public File convert(String value) {
    return new File(value);
  }
}
</pre>
<p>Then, all you need to do is declare your field with the correct type and specify the converter as an attribute:</p>
<pre class="brush: java">
@Parameter(names = "-file", converter = FileConverter.class)
File file;
</pre>
<p>JCommander ships with a few common converters (e.g. one that turns a comma separated list into a <tt>List&lt;String&gt;</tt>.</p>
<h3>Simple internationalization</h3>
<p>The new <tt>@ResourceBundle</tt> annotation lets you specify the bundle to be used on your parameter class itself. After this, JCommander will use the default locale to resolve your string:</p>
<pre class="brush: java">
@ResourceBundle("MessageBundle")
public class ArgsI18N2 {
  @Parameter(names = "-host", descriptionKey = "host")
  String hostName;
}
</pre>
<h3>Password parameters</h3>
<p>If one of your parameters is a password or some other value that you do not wish to appear in your history or in clear, you can declare it of type <tt>password</tt> and JCommander will then ask you to enter it in the console:</p>
<pre class="brush: java">
public class ArgsPassword {
  @Parameter(names = "-password", description = "Connection password", password = true)
  public String password;
}
</pre>
<p>When you run your program, you will get the following prompt:</p>
<pre class="brush: bash">
Value for -password (Connection password):
</pre>
<p>You will need to type the value at this point before JCommander resumes.</p>
<h3>Installation</h3>
<p>JCommander is available either <a href="http://beust.com/jcommander">directly</a> or from Maven:</p>
<pre class="brush: xml">
    <dependency>
      <groupId>com.beust</groupId>
      <artifactId>jcommander</artifactId>
      <version>1.1</version>
    </dependency>
</pre>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/19/jcommander-1-1/#comments" thr:count="14" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/19/jcommander-1-1/feed/atom/" thr:count="14" />
		<thr:total>14</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/19/jcommander-1-1/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[New features in JCommander and Maven availability]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/eC6CY33AQtk/" />
		<id>http://beust.com/weblog/?p=746</id>
		<updated>2010-07-15T21:08:00Z</updated>
		<published>2010-07-15T21:08:00Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[I received a good amount of feedback about JCommander, and I&#8217;ve been adding a few functionalities these past few days:

Support for multiple definition classes. Christian Gruber pointed out that it might be nice to not be restricted to just one class when you declare all your @Parameter fields. For example:
ArgsMaster.java

public class ArgsMaster {
  @Parameter(names [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/15/new-features-in-jcommander-and-maven-availability/"><![CDATA[<p>I received a good amount of feedback about JCommander, and I&#8217;ve been adding a few functionalities these past few days:</p>
<ul>
<li>Support for multiple definition classes. Christian Gruber pointed out that it might be nice to not be restricted to just one class when you declare all your <tt>@Parameter</tt> fields. For example:
<p><h3 class="sourcetitle">ArgsMaster.java</h3>
<pre class="brush: java">
public class ArgsMaster {
  @Parameter(names = "-master")
  public String master;
}
</pre>
<h3 class="sourcetitle">ArgsSlave.java</h3>
<pre class="brush: java">
public class ArgsSlave {
  @Parameter(names = "-slave")
  public String slave;
}
</pre>
<p>You then pass these objects when you create your JCommander instance, which will collect all the parameter definitions from both objects.</p>
<pre class="brush: java">
ArgsMaster m = new ArgsMaster();
ArgsSlave s = new ArgsSlave();
String[] argv = { "-master", "master", "-slave", "slave" };
new JCommander(new Object[] { m , s }, argv);

Assert.assertEquals(m.master, "master");
Assert.assertEquals(s.slave, "slave");
</pre>
<li>Support for <tt>required</tt>. For simple applications, you can just declare <tt>@Parameter(required = true)</tt> and JCommander will enforce that all such parameters are assigned a value (<a href="http://beust.com/jcommander/#Required_and_optional">example</a>).
<li>Internationalization. You can now use the standard Java resource bundle mechanism to write the descriptions of your options and have JCommander automatically use the translated strings (<a href="http://beust.com/jcommander/#Internationalization">example</a>).
<li>Parameters that take more than one value (arities). This functionality allows you to parse command lines such as:
<pre class="brush: bash">
  java Main -pairs slave master foo.xml
  </pre>
<p>  Here, the parameter <tt>-pairs</tt> needs the next two arguments (<a href="http://beust.com/jcommander/#Arities">example</a>).</p>
</ul>
<p>All these features are now available in JCommander 1.0, which Maven users can download automatically with the following dependency:</p>
<pre class="brush:xml">
<dependency>
  <groupId>com.beust</groupId>
  <artifactId>jcommander</artifactId>
  <version>1.0</version>
</dependency>
</pre>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/15/new-features-in-jcommander-and-maven-availability/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/15/new-features-in-jcommander-and-maven-availability/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/15/new-features-in-jcommander-and-maven-availability/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Cedric</name>
					</author>
		<title type="html"><![CDATA[Announcing JCommander 1.0]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/beust/OtakuRdf/~3/-NrE0Cl3cOE/" />
		<id>http://beust.com/weblog/?p=740</id>
		<updated>2010-07-13T14:19:59Z</updated>
		<published>2010-07-13T14:19:59Z</published>
		<category scheme="http://beust.com/weblog" term="General" />		<summary type="html"><![CDATA[
import com.beust.jcommander.Parameter;

public class JCommanderTest {
  @Parameter
  public List&#60;String&#62; parameters = Lists.newArrayList();

  @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
  public Integer verbose = 1;

  @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
  public String groups;

  @Parameter(names = "-debug", description = [...]]]></summary>
		<content type="html" xml:base="http://beust.com/weblog/2010/07/13/announcing-jcommander-1-0/"><![CDATA[<pre class="brush:java">
import com.beust.jcommander.Parameter;

public class JCommanderTest {
  @Parameter
  public List&lt;String&gt; parameters = Lists.newArrayList();

  @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
  public Integer verbose = 1;

  @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
  public String groups;

  @Parameter(names = "-debug", description = "Debug mode")
  public boolean debug = false;
}
</pre>
<p>Recently, I got tired of having to handle command line parsing manually. I took a look at existing frameworks and all the ones that I found (JOpts, JArgs, commons-cli) suffered from the same limitations that I was trying to avoid: they barely cut down on the boiler plate code and they are not very type safe.</p>
<p>So I came up with my own framework, which I called <a href="http://beust.com/jcommander">JCommander</a>.</p>
<p>The snippet of code above should give you a pretty good idea of what JCommander looks like, and if you need more information, just head over to the <a href="http://beust.com/jcommander">main site</a>.  I have already integrated JCommander in <a href="http://testng.org">TestNG</a> and it has already reduced the code base to handle this simple task significantly.</p>
<p>Let me know what you think.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://beust.com/weblog/2010/07/13/announcing-jcommander-1-0/#comments" thr:count="25" />
		<link rel="replies" type="application/atom+xml" href="http://beust.com/weblog/2010/07/13/announcing-jcommander-1-0/feed/atom/" thr:count="25" />
		<thr:total>25</thr:total>
	<feedburner:origLink>http://beust.com/weblog/2010/07/13/announcing-jcommander-1-0/</feedburner:origLink></entry>
	</feed>
