Tuesday, February 23, 2010

Google Code as Maven Repository

In this post I will explain how to set up a Google code project as a maven repository.

I like Maven. The fact that I can checkout some code and let Maven figure out all the dependencies is wonderful. I know that there are developers out there who will criticize Maven. But in my opinion, a lot of the critique is not really justified.

I also like Google code project hosting. It is very easy to start a project on Google code and have a mature environment for software development.

When I was looking around for a way to publicize my own artefacts I came across the idea of using project hosting on Google code as a maven repository. Because It took me a while to get everything up and running, I will outline the steps I had to take.

As a precondition, I assume a you have a Google code project where you can submit to and a working maven project.

  1. Add the Java.net maven repository.

    We will be using a plugin which is found on the java.net maven repository.
    
      
        maven2-repository.dev.java.net
        Java.net Repository for Maven
        http://download.java.net/maven/2/
      
    
    

  2. Add the wagon-svn plugin

    We are going to use the wagon-svn plugin which will do all the heavy lifting for us. Make sure to use the latest version.
    
    
        
          org.jvnet.wagon-svn
          wagon-svn
          1.9
        
      
    
    

  3. Come up with a naming scheme.

    We are going to create repositories in the svn tree. I propose the following convention. Create a maven directory at the top of the svn tree. This directory will contain a repo directory and a snapshot-repo.

    This can be configured in the following way.
      
        
          minimal-examples-repository
          Maven Repository for minimal-examples
          svn:https://minimal-examples.googlecode.com/svn/maven/repo
        
        
          minimal-examples-snapshot-repository
          Maven Repository for minimal-examples (snapshot)
          svn:https://minimal-examples.googlecode.com/svn/maven/snapshot-repo
          false
        
      
    

Now we are all set to start deploying! By running the command maven deploy, the svn-wagon plugin will deploy the artifacts to the repository. The first time you will have to accept the certificate that the Google code project return.
Furthermore, you will have to authenticate yourself with your username and password which are known to the Google code project. You can take up this information in your ~/.m2/settings.xml, so you do not have to enter this information all the time.


  
    minimal-examples-repository
    my_username
    my_password
  
  
    minimal-examples-snapshot-repository
    my_username
    my_password
  

This wraps up the set up for using a Google code project as a Maven repository.

Friday, February 5, 2010

Observation on Binary Trees

In this post I will proof the following observation:

Let \(T\) be a binary tree, \(I\) the number of internal nodes and \(L\) the number of leaves in \(T\) then

\[
L = I + 1
\]

We will proof this fact by observing the following. Every binary tree can be "grown" by replacing leaves with trivial binary tree.
A minimal criminal C
Assume to the contrary that not every binary tree can be grown by replacing leaves with trivial binary trees. Then there must exist a smallest binary tree which can not be grown in such a way. Call it \(C\).
Notice that both subtrees of \(C\) are smaller binary trees. Because \(C\) was the smallest tree which could not be grown, both subtrees can be grown.
But the following description grows \(C\).

  1. Take trivial binary tree
  2. On the left leaf use the description for the left subtree of \(C\)
  3. On the right leaf use the description for the right subtree of \(C\)

This contradicts the fact that \(C\) was the smallest such tree. We are forced to drop the assumption that there exist a binary tree which could not be grown. Therefore all binary trees can be grown.

Now for the trivial binary tree is is clear that

\[
L = I + 1
\]

And when a leaf is grown both \(L\) and \(I\) go up by 1, maintaining the equality. From the above observations one can conclude that the equations hold for all binary trees.