As I wanted to share an Eclipse based project I’m working on with the open source community I decided to use Google Code and a distributed version control system (DVCS) for the first time. I did not find much material on how to do this with Eclipse so I decided to document the process as it may be of some use to someone.
One of the reasons I wanted to use a DVCS is that it will allow me to set up continuous building on my workstation without having to commit changes to the central repository. (More about that later). Google Code currently only offers the Mercurial DVCS so that’s what I’ll be using.
First I had to set up Mercurial in Eclipse. I installed the Mercurial client from http://javaforge.com/project/HGE. I then opened preferences and chose Team > Mercurial. Entered my Mercurial Username as “Torkild U. Resheim email@example.com” and specified the paths to the binaries. This last step is absolutely required.
Then it was time to check out the repository that Google Code created when the project was initialized. So I selected Import > Mercurial > Clone Existing Mercurial Repository. In the dialog I entered the URL of the repository; https://buildmonitor.googlecode.com/hg/ and my Google code user name and password. Note that this password is not the same as the one used to log into other Google services. It can be found in the Google Code web page at Profile > Settings. This process created a new project in my workspace named buildmonitor.
For the repository I wanted three folders containing plug-ins, features and various build scripts. This particular layout was chosen because it makes life with PDE build easier. Now, the Mercurial client will not allow me to do this directly so I had to do some tricks.
First I opened a shell and entered the new project folder.
Next I specified a proper user name that will be used when changes are committed. This is done by adding the name to the settings file. If you replicate the process and take a look at the file you will notice that the credentials are already stored there. In plain text mind you!
echo -e '[ui]nusername = Torkild U. Resheim <firstname.lastname@example.org>n' >> .hg/hgrc
I then created folders for holding the source code. As mentioned I wanted both a plugins and a features folder as the Eclipse PDE build scripts expect this layout.
echo 'Directory for holding Eclipse plug-ins.' > plugins/readme.txt
echo 'Directory for holding Eclipse features.' > features/readme.txt
echo 'Directory for build and release scripts.' > releng/readme.txt
hg add plugins/readme.txt
hg add features/reame.txt
hg add releng/readme.txt
hg commit -m "Basic folder layout."
The last command committed my changes to the main repository.
I no longer needed the buildmonitor project per se, so I simply deleted it from Eclipse, taking care not to remove the actual folder from the file system.
Now what I really wanted to do was to place my existing source code inside the new folders in the new repository. Something similar to what you can do with Subversion by adjusting the URL when committing. However I could not find a good way of doing so using the Team > Share command as this would create a new repository.
I found that I could simply select each project individually then execute Refactor > Move and specify the new location to be inside the newly created plugins (or features) folder. Then (again individually) select Team > Share Project… > Mercurial and accept the defaults to add the project to the repository. For new projects I just need to make sure I place them inside the repository file structure.
Now everything was ready to commit and push. The next step will be to set up continuos building, then maybe migrate to Eclipse Labs.
A few useful links
- Intland Software: Google Code and Mercurial Tutorial for Eclipse Users
- Ekkes-Corner: Git+Mercurial
- Intellectual Cramps: Local Continuous Integration With Hudson And Git