<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Petr Kozelka&#039;s blog</title>
	<atom:link href="http://kozelka.net/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://kozelka.net/blog</link>
	<description>On my way to developer&#039;s eldorado</description>
	<lastBuildDate>Sat, 22 Jan 2011 02:28:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>GWT MVP: supporting legacy URL tokens</title>
		<link>http://kozelka.net/blog/gwt-ap-mvp-supporting-legacy-url-tokens</link>
		<comments>http://kozelka.net/blog/gwt-ap-mvp-supporting-legacy-url-tokens#comments</comments>
		<pubDate>Fri, 21 Jan 2011 01:13:20 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mvp]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/?p=222</guid>
		<description><![CDATA[Recently I started to migrate a GWT application to MVP, in order to learn it, and also to enjoy the promised advantages. For now I decided to use the MVP framework that comes with GWT 2.1. Migration itself was relatively easy, but the framework dictates how the token is structured &#8211; and it is quite [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I started to migrate a GWT application to MVP, in order to learn it, and also to enjoy the promised advantages.<br />
For  now I decided to use the MVP framework that comes with GWT 2.1. Migration itself was relatively easy, but the framework dictates how the token  is structured &#8211; and it is quite simple:</p>
<p>PLACEPREFIX + “:” + PARAMS</p>
<p>The colon is hardcoded in the AbstractPlaceHistoryMapper class, but my previous implementation uses slash <em>(and a slightly different approach to select the view)</em>.<br />
The application is integrated with few other systems via URLs, and naturally I need to support my original syntax, in addition to the one required by the framework.<br />
The simplest way seems to be, trapping the occurrences of original syntax, and translate it into the new one.<br />
Fortunately, it is quite simple. The class PlaceHistoryMapper (from GWT) works with history strictly via Historian  interface, with a default implementation that uses History api. So, I derived my own historian from that implementation and reimplemented it accordingly:</p>
<h4>MyHistorian.java</h4>
<pre class="brush:java; first-line: 9; highlight: [15,16]">
public class MyHistorian extends PlaceHistoryHandler.DefaultHistorian {
  public String getToken() {
    String token = super.getToken();
    if (token == null) {
      return null;
    }
    if (token.startsWith("oldprefix/")) {
      token = "NewPlacePrefix:" + token.substring(10);
    }
    return token;
  }
}
</pre>
<p>As  you see, the implementation is really simple. In many cases, the  translation logic will be far more complex, but this shows the  idea.<br />
Now  we also need to make GWT use our implementation instead of the default  one. This can be achieved via GWT’s Deferred Binding, because PlaceHistoryHandler creates historians with GWT.create() call.</p>
<h4>MyApp.gwt.xml</h4>
<p>This is a fragment you should add to your .gwt.xml file:</p>
<pre class="brush:xml; first-line: 25; highlight: [26,27]">
...
    &lt;replace-with class="net.kozelka.myapp.client.MyHistorian"&gt;
      &lt;when-type-is class="com.google.gwt.place.shared.PlaceHistoryHandler.DefaultHistorian"/&gt;
    &lt;/replace-with&gt;
...
</pre>
<p>Note that this approach works for me with GWT 2.1.1 &#8211; I did not check any previous versions.<br />
If you have any ideas how to do this in a better way, please share it here.</p>
<h4>Further hints</h4>
<ul>
<li>keep the translation logic in a separate class</li>
<li>to get feedback on bad urls:
<ol>
<li>create also MyDebugHistorian which makes something annoying (like Window.alert) when legacy syntax is detected</li>
<li>bind it in your MyAppDebug.gwt.xml module descriptor, instead of the “silent” implementation</li>
</ol>
</li>
<li>use some logging mechanism &#8211; to record uses of old syntax even in production code</li>
</ul>
<h4>References</h4>
<ul>
<li>[AP-MVP] Activities and Places &#8211; <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html">GWT’s embedded MVP framework</a></li>
<li><a href="http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html">Deferred Binding</a></li>
<li>GWT Logging Framework &#8211; <a href="http://code.google.com/webtoolkit/doc/latest/DevGuideLogging.html">java.util.logging based implementation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/gwt-ap-mvp-supporting-legacy-url-tokens/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu Places menu: weird behavior of “Home” place</title>
		<link>http://kozelka.net/blog/ubuntu-places-menu-weird-behavior-of-home-place</link>
		<comments>http://kozelka.net/blog/ubuntu-places-menu-weird-behavior-of-home-place#comments</comments>
		<pubDate>Wed, 05 Jan 2011 01:45:49 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/?p=206</guid>
		<description><![CDATA[Recently I played with several multimedia tools &#8211; cutting and editing movies, transforming them to diferent codecs etc. &#8211; and during that activity, something was broken in my Ubuntu user account: when I try to open Home folder from the Ubuntu&#8217;s &#8220;Places&#8221; menu, it causes that gnome-mplayer is executed instead of the default nautilus. Here [...]]]></description>
			<content:encoded><![CDATA[<p>
Recently I played with several multimedia tools &#8211; cutting and editing movies, transforming them to diferent codecs etc. &#8211; and during that activity, something was broken in my Ubuntu user account: when I try to open Home folder from the Ubuntu&#8217;s &#8220;Places&#8221; menu, it causes that <strong>gnome-mplayer</strong> is executed instead of the default <strong>nautilus</strong>.
</p>
<p>Here is what I do:</p>
<p>
<a rel="attachment wp-att-263" href="http://kozelka.net/blog/ubuntu-places-menu-weird-behavior-of-home-place/pic1-menu"><img class="size-full wp-image-263" title="I just click on a Nautilus bookmark..." src="http://kozelka.net/blog/wp-content/uploads/2011/01/pic1-menu.png" alt="" width="500" height="200" /></a>
</p>
<p>&#8230; and here is what happens:</p>
<p>
<a rel="attachment wp-att-264" href="http://kozelka.net/blog/ubuntu-places-menu-weird-behavior-of-home-place/pic2-gnome-mplayer"><img class="size-full wp-image-264" title="... but gnome-mplayer starts instead" src="http://kozelka.net/blog/wp-content/uploads/2011/01/pic2-gnome-mplayer.png" alt="" width="700" height="200" /></a>
</p>
<p>
You see ? There is gnome-mplayer scanning the given folder, which makes me believe that gnome-mplayer installed itself somewhere in my user settings instead of nautilus. Yes, it must be user-wide, not system wide &#8211; because other user accounts on the computer do not suffer this way.
</p>
<p><i>Note: thanks to <a href="http://milos.svasek.net" target="_new">Miloš Svašek</a> for helping me to resolve WordPress issues with images.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/ubuntu-places-menu-weird-behavior-of-home-place/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Buildozer 1.0.0-alpha-5 released</title>
		<link>http://kozelka.net/blog/buildozer-1-0-0-alpha-5-released</link>
		<comments>http://kozelka.net/blog/buildozer-1-0-0-alpha-5-released#comments</comments>
		<pubDate>Sun, 23 May 2010 01:05:02 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[buildbox]]></category>
		<category><![CDATA[buildozer]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/?p=164</guid>
		<description><![CDATA[Next version of &#8220;buildozer&#8221; is out. Buildozer is a tool for simplifying transitive builds on modules with SNAPSHOT dependencies. It especially simplifies propagation of code changes from changed module(s) to those depending on them, while skipping builds of unaffected ones. Installation instructions are available here. Project main web is http://buildbox.sf.net/buildozer. Changes since version 1.0.0-alpha-4 New [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://kozelka.net/blog/wp-content/uploads/bulldozer.png"><img class="alignleft size-medium wp-image-170" title="bulldozer" src="http://kozelka.net/blog/wp-content/uploads/bulldozer.png" alt="" /></a>Next version of &#8220;buildozer&#8221; is out.<br />
Buildozer is a tool for simplifying transitive builds on modules with SNAPSHOT dependencies. It especially simplifies propagation of code changes from changed module(s) to those depending on them, while skipping builds of unaffected ones.</p>
<p>Installation instructions are available <a title="Buildozer - Installation" href="http://buildbox.sourceforge.net/buildozer/install.html" target="_blank">here</a>. Project main web is <a href="http://buildbox.sf.net/buildozer">http://buildbox.sf.net/buildozer</a>.</p>
<h4>Changes since version 1.0.0-alpha-4</h4>
<p>New features:</p>
<ul>
<li>FAILED modules are not rebuilt unless changed (or their dependencies changed)</li>
<li>added command &#8220;doall&#8221; pretending that all modules have changed = full rebuild</li>
</ul>
<p>Fixes:</p>
<ul>
<li>stanalone jar installer &#8211; fixed NPE in artifact downloading</li>
<li>return nonzero exit code on failure</li>
</ul>
<p>Improvements:</p>
<ul>
<li>log file and failure indicator stored in subdir of repository&#8217;s installation target</li>
<li>added option &#8211;version, both in standard and in xml format</li>
<li>simplified the way of listing installed artifact of a module (not using special mojo on mvn commandline)</li>
</ul>
<h4>Feedback</h4>
<p>Users can share their experience</p>
<ul>
<li>on <a href="http://groups.google.com/group/buildbox">Buildbox Google Group</a></li>
<li>on the facebook <a href="http://www.facebook.com/#!/group.php?gid=331266931881">Buildozer group</a></li>
</ul>
<p>or contribute any other way &#8211; some hints are <a href="http://buildbox.sourceforge.net/buildozer/contrib.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/buildozer-1-0-0-alpha-5-released/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mc unzip problem on ubuntu karmic</title>
		<link>http://kozelka.net/blog/mc-unzip-problem-on-ubuntu-karmic</link>
		<comments>http://kozelka.net/blog/mc-unzip-problem-on-ubuntu-karmic#comments</comments>
		<pubDate>Wed, 25 Nov 2009 09:54:23 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[midnight-commander]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/?p=143</guid>
		<description><![CDATA[Ubuntu 9.10 (Karmic Koala) has a little issue with Midnight Commander &#8211; it does not browse into zipped files, and shows empty contents instead. After searching the web I found out that the problem can be solved by setting property &#8220;op_has_zipinfo&#8221; to &#8220;1&#8243; in file &#8220;/usr/share/mc/extfs/uzip&#8221;. For the truly lazy people I prepared this little [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu 9.10 (Karmic Koala) has a little issue with Midnight Commander &#8211; it does not browse into zipped files, and shows empty contents instead. After searching the web I found out that the problem can be solved by setting property &#8220;op_has_zipinfo&#8221; to &#8220;1&#8243; in file &#8220;/usr/share/mc/extfs/uzip&#8221;. For the truly lazy people I prepared this little commandline fixing that (no need to open the editor):</p>
<pre>sudo sed '/op_has_zipinfo/{s:0:1:}' /usr/share/mc/extfs/uzip &gt;x &amp;&amp; sudo chmod 755 x &amp;&amp; sudo mv x /usr/share/mc/extfs/uzip</pre>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/mc-unzip-problem-on-ubuntu-karmic/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>How to build a ZIP output artifact in Maven</title>
		<link>http://kozelka.net/blog/how-to-build-a-zip-output-artifact-in-maven</link>
		<comments>http://kozelka.net/blog/how-to-build-a-zip-output-artifact-in-maven#comments</comments>
		<pubDate>Thu, 22 Oct 2009 21:07:20 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/?p=134</guid>
		<description><![CDATA[It&#8217;s quite a common situation that you have a bunch of files, most or all of them committed in svn, and need to make a release of this so that it can be reused with the Maven&#8217;s dependency mechanism. There are several ways how to accomplish that: use maven-assembly-plugin use maven-antrun-plugin to build and build-helper-maven-plugin [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s quite a common situation that you have a bunch of files, most or all of them committed in svn, and need to make a release of this so that it can be reused with the Maven&#8217;s dependency mechanism.</p>
<p>There are several ways how to accomplish that:</p>
<ul>
<li>use <strong>maven-assembly-plugin</strong></li>
<li>use <strong>maven-antrun-plugin</strong> to build and <strong>build-helper-maven-plugin</strong> to attach</li>
<li>create custom plugin that handles both packaging and attaching</li>
</ul>
<p>Each of them has its advantages in some situations, but my favorite is the second option for most cases.</p>
<h3>Real life example &#8211; artifact with various svn output files</h3>
<p>In some of my projects, I need to check that the code works properly with xml output files from Subversion. I could easily put such files among test resources, but the it would be there many times, and I would always have to check if it is &#8220;representative&#8221; enough etc.</p>
<p>So I decided to create a module, which will create the data during its build <em>(see the maven-antrun-plugin)</em>.</p>
<p>These data are packaged into a zip file which is then marked as output artifact with type &#8220;zip&#8221; <em>(see the build-helper-maven-plugin)</em>.</p>
<p>Look at this pom excerpt <em> (complete pom.xml is available <a href="http://buildbox.svn.sourceforge.net/viewvc/buildbox/trunk/testdata/svn-mvn-testdata/pom.xml?view=markup">here</a>):</em></p>
<pre>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;groupId&gt;net.sf.buildbox.testdata&lt;/groupId&gt;
  &lt;artifactId&gt;svn-mvn-testdata&lt;/artifactId&gt;
  &lt;version&gt;1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
...
  &lt;build&gt;
    &lt;outputDirectory&gt;target/output&lt;/outputDirectory&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;<strong>maven-antrun-plugin</strong>&lt;/artifactId&gt;
        &lt;version&gt;1.3&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
... <em>phase=</em>package, <em>goal=</em>run
            &lt;configuration&gt;
              &lt;tasks&gt;
                &lt;mkdir dir="${project.build.outputDirectory}"/&gt;
                &lt;exec executable="svn" failonerror="true" dir="${project.build.outputDirectory}" taskname="svn-checkout"&gt;
...
                &lt;/exec&gt;
...
                <strong>&lt;zip destfile="${project.build.directory}/${project.build.finalName}.zip"&gt;</strong>
...
                &lt;/zip&gt;
              &lt;/tasks&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
        &lt;artifactId&gt;<strong>build-helper-maven-plugin</strong>&lt;/artifactId&gt;
        &lt;version&gt;1.2&lt;/version&gt;
        &lt;executions&gt;
... <em>phase=</em>package, <em>goal=</em>attach-artifact
            &lt;configuration&gt;
              &lt;artifacts&gt;
                &lt;artifact&gt;
                  &lt;file&gt;<strong>${project.build.directory}/${project.build.finalName}.zip</strong>&lt;/file&gt;
                  &lt;type&gt;zip&lt;/type&gt;
                &lt;/artifact&gt;
              &lt;/artifacts&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;</pre>
<p>What are the advantages over other mentioned alternatives ?</p>
<ul>
<li><em>extensibility</em> &#8211; the &#8220;generator&#8221; part is straightforward, so, as long as ant is enough for us it costs just a few lines of ant code</li>
<li><em>compactness</em> &#8211; we could reach similar result with several invocations of exec-maven-plugin for preparing data, plus maven-assembly-plugin to pack and attach it, but that would be far far more verbose and harder to maintain</li>
</ul>
<p>Just for completenes, it&#8217;s good to say when using the other approaches is more relevant:</p>
<ul>
<li><em>custom maven plugin</em> &#8211; when the algorithm for generating data is too complex to be written in ant, or needs other sources that are not reachable from antrun, like dependencies</li>
<li><em>maven-assembly-plugin</em> &#8211; when we need to control file permissions in tgz/gz packages while running the build on windows</li>
</ul>
<p>Do you have experience in this area ? Then please post your comments&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/how-to-build-a-zip-output-artifact-in-maven/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generating temporary files in junit tests</title>
		<link>http://kozelka.net/blog/generating-temporary-files-in-junit-tests</link>
		<comments>http://kozelka.net/blog/generating-temporary-files-in-junit-tests#comments</comments>
		<pubDate>Mon, 06 Jul 2009 00:33:00 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/?p=92</guid>
		<description><![CDATA[It is often useful to create some temporary files inside a unit test. Basically it is not a problem, because junit does not limit you in such thing; you might simply use a &#8220;current&#8221; directory to store such files, and it usually works. However, different frameworks invoking JUnit use different &#8220;current&#8221; directories, which makes it [...]]]></description>
			<content:encoded><![CDATA[<p>It is often useful to create some temporary files inside a unit test. Basically it is not a problem, because junit does not limit you in such thing; you might simply use a &#8220;current&#8221; directory to store such files, and it usually works. However, different frameworks invoking JUnit use different &#8220;current&#8221; directories, which makes it difficult to:</p>
<ul>
<li>locate the temporary files for debugging purposes</li>
<li>remove them between test re-executions</li>
<li>reference static <span style="font-style: italic;">(committed)</span> files using a relative path
</li>
</ul>
<p>I personally always use at least two such frameworks &#8211; Maven and an IDE &#8211; and I would really like to see the data always at the same place, and reference committed files using always the same relative path.<br />
Besides that, I require that any intermediate data in my Maven modules are generated under the &#8220;<span style="font-family:courier new;">target</span>&#8221; subdirectory <span style="font-style: italic;">(or, more precisely, under </span><span style="font-style: italic;font-family:courier new;" >${project.build.directory}</span><span style="font-style: italic;">)</span>, because</p>
<ul>
<li>this gives me the comfort of cleaning them as part of &#8220;<span style="font-family:courier new;">mvn clean test</span>&#8221; command without other manual specification of directories to erase</li>
<li>it does not bloat module directory structure with version-uncontrolled files.</li>
</ul>
<p>To accomplish this, we cannot use the &#8220;current&#8221; directory; instead, we need to compute one that is always the same, and use in later in the unit test.</p>
<p>So it seems to be neccessary to write a method that somehow computes that &#8220;stable&#8221; directory:</p>
<p><span style="font-size:85%;"><span style="font-family:courier new;">public static File computeTestDataRoot()</span></span></p>
<p>How can it be implemented ? The key is that they execute tests from compiled classes stored in a directory, not in a jar file. We can therefore use a resource laying among these tests &#8211; which can even be one of test classes<span style="font-style: italic;"> (there is always at least one, the one for which we need it)</span>, and we use it to locate root of the test classes. In Maven, it is by default &#8220;target/test-classes&#8221;. To extend this nice convention, we will make the method return &#8220;target/test-data&#8221;, a non-existent directory which can be used by tests to generate their stuff.</p>
<pre style="border: thin dotted silver; padding-left: 1em;">
public static File computeTestDataRoot(Class anyTestClass) {
  final String clsUri = anyTestClass.getName().replace('.','/') + ".class";
  final URL url = anyTestClass.getClassLoader().getResource(clsUri);
  final String clsPath = url.getPath();
  final File root = new File(clsPath.substring(0, clsPath.length() - clsUri.length()));
  final File clsFile = new File(root, clsUri);
  return new File(root.getParentFile(), "test-data");
}
</pre>
<p>Note that we need to pass an argument to our method &#8211; the calling test class. It is a little price for getting consistent test data directory &#8211; and probably unavoidable.</p>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/generating-temporary-files-in-junit-tests/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>When is it best to do cleanup in tests ?</title>
		<link>http://kozelka.net/blog/when-is-it-best-to-do-cleanup-in-tests</link>
		<comments>http://kozelka.net/blog/when-is-it-best-to-do-cleanup-in-tests#comments</comments>
		<pubDate>Sat, 04 Jul 2009 13:54:00 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/when-is-it-best-to-do-cleanup-in-tests</guid>
		<description><![CDATA[With &#8220;true&#8221; unit tests, having no requirements on shared external resources, this is not an issue. But in reality, we often need (integration) tests that do need such resources &#8211; database, jms, other servers or just files located somewhere. In my opinion, the cleanup in all unit tests should happen before the test itself. It [...]]]></description>
			<content:encoded><![CDATA[<p>With &#8220;true&#8221; unit tests, having no requirements on shared external resources, this is not an issue.</p>
<p>But in reality, we often need (integration) tests that do need such resources &#8211; database, jms, other servers or just files located somewhere.</p>
<p>In my opinion, the cleanup in all unit tests should happen <span style="font-weight: bold;">before</span> the test itself. It has a simple reason &#8211; whatever wrong happens, next time the test can be executed without need for any annoying manual intervention.
</p>
<p>What are the wrong things that may happen ? Here are some:</p>
<ul>
<li>test fails</li>
<li>    the process is killed &#8211; potentially even related to the test execution</li>
<li>the host computer is turned off
</li>
</ul>
<p>The first one can be handled by the testing framework. JUnit and similar ones provide support for setUp / teardown method that should do the right things before and after each test or testsuite.</p>
<p>While this concept is very good, especially for isolating the initialization and cleanup code from the test logic, it &#8211; by itself &#8211; doesn&#8217;t work at all for the latter scenarios.</p>
<p>So, it is always much safer to assume that we won&#8217;t get the chance to cleanup afterwards.</p>
<p>My preferred techniques to minimize need for manual intervention are:</p>
<ul>
<li>in the setUp part, prepare all resources to the state required by the test</li>
<li>    if it is too complex, at least check if they are in the required state; fail with indicative messages otherwise</li>
<li>do no init/cleanup stuff within the test method itself</li>
<li>do no cleanup in the teardown part &#8211; just to avoid temtation to rely on its &#8220;proper&#8221; function.</li>
</ul>
<p>One little bonus of not doing cleanup at the end is, that we can easily check the final state of affected resources just by running the single test, with no modification or debugger setup needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/when-is-it-best-to-do-cleanup-in-tests/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bbx:1.0.0-alpha-5 released &#8211; BuildoZER, colorado and the others</title>
		<link>http://kozelka.net/blog/bbx1-0-0-alpha-5-released-buildozer-colorado-and-the-others</link>
		<comments>http://kozelka.net/blog/bbx1-0-0-alpha-5-released-buildozer-colorado-and-the-others#comments</comments>
		<pubDate>Fri, 03 Jul 2009 19:19:00 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/bbx1-0-0-alpha-5-released-buildozer-colorado-and-the-others</guid>
		<description><![CDATA[The cross-platform development tool suite &#8220;bbx&#8221;, has been recently released in version 1.0.0-alpha-5. It contains several development-oriented tools, supporting especially Maven builds: BuildoZER (zer) &#8211; a tool to perform transitive builds of Maven modules colorado &#8211; simple log output colorizer (Linux only for now) zcd &#8211; to navigate through directories by module name (artifactId from [...]]]></description>
			<content:encoded><![CDATA[<p>The cross-platform development tool suite &#8220;bbx&#8221;,  has been recently <a href="http://buildbox.sf.net/buildozer">released</a> in version 1.0.0-alpha-5.<br />
It contains several development-oriented tools, supporting especially Maven builds:</p>
<ul>
<li>BuildoZER (<span style="font-weight: bold;">zer</span>) &#8211; a tool to perform transitive builds of Maven modules</li>
<li><span style="font-weight: bold;">colorado</span> &#8211; simple log output colorizer <span style="font-style: italic;">(Linux only for now)</span></li>
<li><span style="font-weight: bold;">zcd</span> &#8211; to navigate through directories by module name (artifactId from pom.xml)</li>
<li><span style="font-weight: bold;">bbx</span> &#8211; an extensible ant frontend with argument parsing, pom-based dependency support and more</li>
</ul>
<p>It is still an alpha-quality release, but the tools are already very handy.</p>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/bbx1-0-0-alpha-5-released-buildozer-colorado-and-the-others/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to force explicit version specification</title>
		<link>http://kozelka.net/blog/how-to-force-explicit-version-specification</link>
		<comments>http://kozelka.net/blog/how-to-force-explicit-version-specification#comments</comments>
		<pubDate>Fri, 30 Jan 2009 16:55:00 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/how-to-force-explicit-version-specification</guid>
		<description><![CDATA[It is often necessary to reproduce older builds. Either because you need to branch it and make a small bugfix, or to perform sanity check of your constantly evolving build infrastructure. Then you often discover that Maven&#8217;s cool feature, to automagically use LATEST version of plugins by default, is not that cool&#8230; new versions may [...]]]></description>
			<content:encoded><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">It is often necessary to reproduce older builds. Either because you need to branch it and make a small bugfix, or to perform sanity check of your constantly evolving build infrastructure.</p>
<p>Then you often discover that Maven&#8217;s cool feature, to automagically use LATEST version of plugins by default, is not that cool&#8230; new versions may be incompatible with your specific usecase, or broken completely, etc etc <i>(I suffered this experience with maven-war-plugin version 2.1-alpha-2 as I reported in </i><a href="http://jira.codehaus.org/browse/MWAR-181">[#MWAR-181]</a><i>)</i>.</p>
<p>Yes, you can work hard and define a corporate pom that presets version of all plugins you use. That&#8217;s good, but who will remember to do that when a new plugin will be added to build ? Most people won&#8217;t.</p>
<p>Fortunately, there is a way to keep you reminded: <b>forbid download of &#8220;<span style="font-family:Courier New;">*metadata.xml</span>&#8221; files</b> and that&#8217;s it. Maven uses this file to determine list of available versions, whenever you use a non-specific version like <span style="font-family:Courier New;">RELEASE</span> or <span style="font-family:Courier New;">LATEST</span>, which is the case of plugin artifacts. Without such metadata, maven fails,saying that it cannot find any version &#8211; so you immediately know that your build would be irreproducible otherwise and that it is time to extend your corporate pom.</p>
<p>On Apache server, you can accomplish that using <span style="font-family:Courier New;">mod_rewrite</span> &#8211; just add something like this to <span style="font-family:Courier New;">httpd.conf</span>:</p>
<pre style="border: thin dotted silver; padding-left: 1em;">
...
RewriteEngine on

# strict repo:
RewriteRule ^/<span style="color: rgb(255, 0, 0);">maven2-strict</span>/.*metadata\.xml$ - [G,L]
RewriteRule ^/<span style="color: rgb(255, 0, 0);">maven2-strict</span>/(.*) http://<u>my.physical.repo:8081</u>/nexus/content/groups/public/$1    [P,L]
...
</pre>
<p>and, of course, use this in your settings.xml:</p>
<pre style="border: thin dotted silver; padding-left: 1em;">
...
 &lt;mirror&gt;
   &lt;id&gt;internalRepository&lt;/id&gt;
   &lt;mirrorOf&gt;*&lt;/mirrorOf&gt;
   &lt;name&gt;inhouse aggregated repo&lt;/name&gt;
   &lt;url&gt;http://<u>my.intranet.server</u>/<span style="color: rgb(255, 0, 0);">maven2-strict&lt;/url&gt;
 &lt;/mirror&gt;
</span>...
</pre>
<hr />
<p>Update:</p>
<p>As Brian Fox from <a href="http://sonatype.com/">Sonatype</a> noted, there are better alternatives to reach reproducibility:</p>
<ul>
<li><a href="http://nexus.sonatype.org/">Nexus</a> users can use directly its own administration interface to setup the redirect</li>
<li>even better is, to use maven-enforcer-plugin with its <a href="http://maven.apache.org/enforcer/enforcer-rules/requirePluginVersions.html">requirePluginVersions</a> rule; it has no impact on using commandline mojos with abbreviations</li>
</ul>
<p>Read comments for more details.
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/how-to-force-explicit-version-specification/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>bash script aware of its location for various types of invocation</title>
		<link>http://kozelka.net/blog/bash-script-aware-of-its-location-for-various-types-of-invocation</link>
		<comments>http://kozelka.net/blog/bash-script-aware-of-its-location-for-various-types-of-invocation#comments</comments>
		<pubDate>Sat, 29 Nov 2008 00:47:00 +0000</pubDate>
		<dc:creator>Petr Kozelka</dc:creator>
				<category><![CDATA[Deldorado]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://kozelka.net/blog/bash-script-aware-of-its-location-for-various-types-of-invocation</guid>
		<description><![CDATA[When writing a bash script launching a tool used directly on commandline, it is often convenient for the user to have various ways of invocation. It is not a problem with trivial scripts, but those who need to access files with known location relative to the script, there are little troubles. First, the script needs [...]]]></description>
			<content:encoded><![CDATA[<p>When writing a bash script launching a tool used directly on commandline, it is often convenient for the user to have various ways of invocation.<br />
It is not a problem with trivial scripts, but those who need to access files with known location relative to the script, there are little troubles.<br />
First, the script needs to determine its own absolute location on filesystem &#8211; because the user can &#8220;stay&#8221; in any directory. The user can also invoke it directly, using relative or absolute path; and finally, user can invoke a symlink pointing to it, again using relative or absolute path.<br />
Following snippet shows how to handle such cases:</p>
<pre style="border: thin dotted silver; padding-left: 1em;">

#!/bin/bash
D=${0%/*}
F=$( find $0 -printf %l )
if [ -z "$F" ]; then
   # it is not symlink
   case "$0" in
   /*) F=$0;;
   *) F=$PWD/$0
   esac
else
   # it is symlink
   case "$F" in
   /*);;
   *) F="$D/$F";;
   esac
fi
# now F=absolute path here
F=${F//\/\.\///}
D="${F%/*}"
# now F contains the script's pathname,
# D contains its containing directory
</pre>
]]></content:encoded>
			<wfw:commentRss>http://kozelka.net/blog/bash-script-aware-of-its-location-for-various-types-of-invocation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

