<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE feed PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:jne="http://www.jnegre.org/2011/site">

	<title>Jérôme Nègre's piece of web</title>
	<icon>http://www.jnegre.org/favicon.ico</icon>
	<link href="http://www.jnegre.org/"/>
	<link rel="self" type="application/atom+xml" href="http://www.jnegre.org/news/atom.xml"/>

	<updated>2012-23-01T19:47:37CET</updated>
	<author>
		<name>Jérôme Nègre</name>
	</author>
	<id>http://www.jnegre.org/</id>

	<entry><title>Deploying to a maven repository via SCP with Gradle</title><link href="http://www.jnegre.org/news/2011/12/23/deploy_to_maven_repository_via_scp_with_gradle.html"/><id>http://www.jnegre.org/news/2011/12/23/deploy_to_maven_repository_via_scp_with_gradle.html</id><updated>2011-12-23T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		Deploying your artifacts to a remote Maven repository with Gradle is possible, but the
		<a href="http://gradle.org/current/docs/userguide/maven_plugin.html">official documentation</a> is rather thin
		at the time of this writing. Worse, it tells you to use a version of wagon-ssh that ignores the provided
		password and prompt for it at the command line (use <code>gradle -i</code> to see its message). 
	</p><p>
		So, without further ado, here is a build.gradle that uploads its artifact via scp with a password.
		It has been tested with Gradle 1.0-milestone-6.
	</p><pre class="source-code"><code>
apply plugin: 'java'
apply plugin: 'maven'

configurations {
    deployerJars
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    //the one and only version that works
    deployerJars 'org.apache.maven.wagon:wagon-ssh:1.0-alpha-3'
}

uploadArchives {
    repositories.mavenDeployer {
        configuration = configurations.deployerJars
        uniqueVersion = false
        String username = 'me'
        String password = 'secret'
        repository(url: 'scp://repos.mycompany.com/releases') {
            authentication(userName: username, password: password)
        }
        snapshotRepository(url: 'scp://repos.mycompany.com/snapshots') {
            authentication(userName: username, password: password)
        }
    }
}

	</code></pre><p>	
		Of course, in a real world scenario, it would be wiser to get the username and password from your
		gradle.properties or any other non-public file. 
	</p></div></content></entry><entry><title>Book review: "Building and Testing with Gradle"</title><link href="http://www.jnegre.org/news/2011/09/21/book_review_building_and_testing_with_gradle.html"/><id>http://www.jnegre.org/news/2011/09/21/book_review_building_and_testing_with_gradle.html</id><updated>2011-09-21T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		Gradle is a very flexible and powerful build tool, allowing an extremely concise build file for conventional
		projects and letting you do whatever crazy thing your project requires using a Groovy DSL.
		I've been following its development for the last two years, and I introduced it to replace a legacy Ant based
		build system at my work about a year ago.
	</p><img style="float:left; margin-right:5px;" width="250" height="328" alt="Cover" src="2011/09/21/building_testing_gradle_cover.png"/><p>	
		As far as I know, <i>Building and Testing with Gradle</i>, written by Tim Berglund and Matthew McCullough
		and published by O'Reilly, is the first book published on this topic.
	</p><p>	
		The first chapter will guide you through the installation process and the use of the Gradle from the command line.
		I'm not sure someone willing to use Gradle needs that kind of information.
		It will also show you the shorter build file possible for a Java project, containing only 18 non-whitespace characters:
		compare this with Maven...
	</p><p>	
		The second chapter is were the serious stuff begins.
		It presents the basic unit of Gradle build files: tasks.
		The two lifecycle phases, configuration and execution, are explained.
		You'll also learn how to use their rich API and how to simply write your own tasks.
		If you're used to the complexity of Maven, be prepared for a shock as this is dead simple and way conciser.
	</p><p>	
		The third chapter shows how Gradle can leverage your existing Ant files and custom tasks.
		This particularity of Gradle allows a step-by-step migration from Ant.
	</p><p>	
		The fourth chapter compares Maven and Gradle.
		Gradle takes the best ideas from Maven (and others): convention over configuration, consistently named artifacts
		and a solid dependency management with the same central repositories.
		It drops what makes Maven so painful to use: tons of XML, a rigid lifecycle and more generally its lack of flexibility.
	</p><p>	
		The fifth chapter is about testing. The integration of JUnit, TestNG, Spock, Geb and EasyB will be rapidly shown.
	</p><p>	
		The sixth and last chapter is focused on multiproject (or multimodule) builds.
		Once again, the tremendous flexibility of Gradle makes it bend to your needs rather than imposing its standards on you.
	</p><p>	
		This is a short book with fewer than a hundred pages, read in a couple of hours, and full of code samples.
		It is an introduction to Gradle, not a complete  reference guide: it will show you the power and the simplicity of Gradle,
		and - I hope - will convince you to give Gradle a try.
	</p></div></content></entry><entry><title>Using the Brother HL-2250DN laser printer on Ubuntu Linux</title><link href="http://www.jnegre.org/news/2011/07/31/brother_HL_2250DN_ubuntu_linux.html"/><id>http://www.jnegre.org/news/2011/07/31/brother_HL_2250DN_ubuntu_linux.html</id><updated>2011-07-31T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		The Brother HL-2250DN is a laser printer with both a USB and an Ethernet interface.
		It understands PCL6, so I knew I could use it with my Ubuntu 10.10 box without too much troubles.
	</p><p>
		Here's how to configure your computer to enjoy the Ethernet interface.
		One doesn't buy a network printer to use USB, right?
	</p><p>
		First, one need to get the IP address of the printer. You could get it from your router, or you
		may just ask the printer. To print the settings of your printer, do the following:
	</p><ol>
			<li>Switch on the printer;</li>
			<li>Wait till the printer is ready;</li>
			<li>Press "Go" three times in less than 2 seconds.</li>
		</ol><p>
		The IP address will be on the third page.
	</p><p>
		Now, on your Ubuntu box:
	</p><ol>
			<li>Go to System / Administration / Printing;</li>
			<li>Click on the "Add" button;</li>
			<li>Select "LPD/LPR Host or Printer" on the left;</li>
			<li>On the right, enter the printer's IP address;</li>
			<li>The name of the queue is "PCL_P1";</li>
			<li>When asked for a driver, pick "Generic PCL 6/PCL XL Printer - CUPS+Gutenprint v5.2.6 Simplified".</li>
		</ol><p>
		And voilà!
	</p></div></content></entry><entry><title>Beware of javax.xml.xpath</title><link href="http://www.jnegre.org/news/2011/06/26/beware_of_javax_xml_xpath.html"/><id>http://www.jnegre.org/news/2011/06/26/beware_of_javax_xml_xpath.html</id><updated>2011-06-26T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		I had to parse in Java an rather big XML document that was looking something like that:
	</p><pre class="source-code"><code>&lt;root&gt;
	&lt;child1&gt;
		&lt;a&gt;I need this element&lt;/a&gt;
		&lt;b&gt;but not this one&lt;/b&gt;
		&lt;c&gt;this one is also irrelevant&lt;/c&gt;
	&lt;/child1&gt;
	&lt;child2&gt;
		&lt;a&gt;&lt;/a&gt;
		&lt;b&gt;&lt;/b&gt;
		&lt;c&gt;&lt;/c&gt;
	&lt;/child2&gt;
	&lt;!-- and so on to fill more than 4 Mo --&gt;
&lt;/root&gt;</code></pre><p>
		There are hundreds of first level child nodes, but each one only has a few children.
	</p><p>
		Given any child node, I had to get one of its own children by its name. I had two options:
	</p><ul>
		<li>iterate over the list of children, and check each one to see if it's the one I am looking for (5 lines of code);</li>
		<li>or be lazy and use a very simple XPath expression (1 line of code).</li>
	</ul><p>
		Being lazy, and since the context nodes were having only a few child nodes, I decided to go with XPath.
		I knew there would be some overhead, but it shouldn't be very big, right?
	</p><p>
		Wrong.
	</p><p>
		My code wasn't doing anything fancy, but it took 40 seconds to complete.
		Being curious about the overhead introduced by XPath, I replaced it by a bunch of node.getChildNodes().
		The total time dropped to 0.1 second.
	</p><p>
		I wrote a small benchmark to illustrate this problem.
		It boils down to these two methods:
	</p><pre class="source-code"><code>/**
 * Returns the direct child of parent with the given name using XPath
 */
private static Node getChildXPath(Node parent, String name) throws Exception {
	return (Node)xpath.evaluate(name, parent, XPathConstants.NODE);
}

/**
 * Returns the direct child of parent with the given name using getChildNodes()
 */
private static Node getChildDom(Node parent, String name) throws Exception {
	NodeList list = parent.getChildNodes();
	for(int i=0; i&lt;list.getLength(); i++) {
		Node child = list.item(i);
		if(child.getNodeType() == Node.ELEMENT_NODE &amp;&amp; name.equals(child.getNodeName())) {
			return child;
		}
	}
	return null;
}</code></pre><p>
		The full code is available on <a href="https://gist.github.com/1046969">github</a>.
	</p><p>
		On my linux box with OpenJDK 1.6.0_20, I got the following results:
	</p><pre class="source-code">Children were found using DOM in 2 ms
Children were found using XPath in 4016 ms</pre><p>
		Lesson learned: javax.xml.xpath is slow as hell, even for very simple expressions.
	</p></div></content></entry><entry><title>Stylo Plume 0.2.0</title><link href="http://www.jnegre.org/news/2011/06/19/styloplume_0_2_0.html"/><id>http://www.jnegre.org/news/2011/06/19/styloplume_0_2_0.html</id><updated>2011-06-19T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		This web site is still built with XSL using my good old Eclipse plugin 
		<a href="../styloplume/index.html">Stylo Plume</a>. Everything was OK for the past years, but
		a few weeks ago I wanted to redesign the news section on the home page, to add individual links to each announcement.
		I wanted something a bit like a blog, but without comments and fully in static html (no server-side PHP/Java/whatever).
	</p><p>
		In order to do so, I needed to add a new functionality to <a href="../styloplume/index.html">Stylo Plume</a>,
		namely to enhance the dir:// protocol to be able to list sub-directories recursively.
		So 8 years after the last release, I searched in a bunch of old hard drives to recover my
		ancient CVS server and put the code in Mercurial.
		A public repository is now available on <a href="https://bitbucket.org/jnegre/styloplume">Bitbucket</a>.
	</p><p>
		Release 0.2.0 is out today, it includes the modification to the dir:// protocol and the replacement of Xalan by the
		XML stack included in the JVM.  
	</p><p>
		Oh, and there's even an <a href="../news/atom.xml">Atom feed</a> for the news, now!
	</p></div></content></entry><entry><title>Playing (again) with JavaScript</title><link href="http://www.jnegre.org/news/2010/09/05/playing_again_with_javascript.html"/><id>http://www.jnegre.org/news/2010/09/05/playing_again_with_javascript.html</id><updated>2010-09-05T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		More fun with modern JavaScript: here's another page to
		<a href="../projects/html5/gallerymaker/gallerymaker.html">generate a
		small photo gallery</a>.
	</p></div></content></entry><entry><title>Playing with JavaScript</title><link href="http://www.jnegre.org/news/2010/08/24/playing_with_javascript.html"/><id>http://www.jnegre.org/news/2010/08/24/playing_with_javascript.html</id><updated>2010-08-24T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		I'm playing with HTML5 and modern JavaScript: here's a small page to
		<a href="../projects/html5/dataify/dataify.html">generate a data url
		from a local file</a>.
	</p></div></content></entry><entry><title>Twitter Integration</title><link href="http://www.jnegre.org/news/2010/08/03/twitter_integration.html"/><id>http://www.jnegre.org/news/2010/08/03/twitter_integration.html</id><updated>2010-08-03T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		*looks on the right* Eh, what's that twitter thingy everybody's talking about?
	</p></div></content></entry><entry><title>New Theme</title><link href="http://www.jnegre.org/news/2008/12/04/new_theme.html"/><id>http://www.jnegre.org/news/2008/12/04/new_theme.html</id><updated>2008-12-04T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		New CSS theme, at last!
	</p></div></content></entry><entry><title>I'm Back!</title><link href="http://www.jnegre.org/news/2008/03/08/i_am_back.html"/><id>http://www.jnegre.org/news/2008/03/08/i_am_back.html</id><updated>2008-03-08T00:00:00Z</updated><content type="xhtml" xml:lang="en" xml:base="http://www.jnegre.org/news/"><div xmlns="http://www.w3.org/1999/xhtml"><p>
		That was a loooooooong time, blame World of Warcraft... And I really need to change the look
		of these pages, they look so web 1.0 ;)
	</p><p>
		Anyway, I'm working on an HTTP debugging proxy called <a href="../projects/redpill/index.html">RedPill</a>
		and entirely done in Java6. It monitors the traffic between your browser and the Internet, and can
		modify it. RedPill has a plugin mechanism, but sadly the GUI to configure it is not done yet.
	</p></div></content></entry>

</feed>
