Sunday, February 06, 2011

Subversion links using svn:externals

Recently, I got to play with a really cool feature in subversion. The problem was that 2 components of the same project decided to follow a slightly different project layout, the UI portion decided to go ahead with the default eclipse web project layout while the backend services decided to use maven modules. And, one necessary module was to map the service outputs to the VO's understood by the UI. Since, the UI code was not using maven I decided to introduce a module for the UI VO's to be added as a dependency for the bridge module and was looking around to do it such that any changes in the UI component was also reflected in the service component. After a bit of googling I found the perfect solution using svn:externals. Here is how my svn repo was laid out
/tags
/branches
/trunk/my-project-war
/trunk/my-project-war/src
/trunk/my-project-war/WebContent
/trunk/my-project-war/...
/trunk/my-project-services
/trunk/my-project-services/pom.xml
/trunk/my-project-services/core
/trunk/my-project-services/core/pom.xml
/trunk/my-project-services/...
Here is an abridged version of how I configured it.
$ svn co http://.../trunk/my-project-services services-proj
$ cd services-proj
$ mvn archetype:generate -DgroupId=com... -DartifactId=ui -Dversion=1.0 -Dpackaging=jar -Dpackage=com...
$ cd ui
$ # clean up the default archetype files and create create the parent directories
$ # down to penultimate package level eg. for com.mycompany.project.vo
$ mkdir -p src/main/java/com/mycompany/project
$ # add the ui directory to subversion and do a preliminary commit
$ # drop down to the created directory
$ cd src/main/java/com/mycompany/project
$ # setup svn:externals
$ svn propset svn:externals 'vo ^/trunk/my-project-war/src/com/mycompany/project/vo' .
$ svn commit -m "setting up link to ui project" .
$ svn up
$ # all done :)
Whenever you update or check status of your working copy the linked directory will be displayed with an X
$ cd services-proj/ui/
$ svn st
X services-proj/ui/com/mycompany/project/vo

No comments: