views:

2420

answers:

3

Is there a plain API to access Mercurial repositories from Java?

There are plugins for Netbeans and Eclipse, but unlike their Subversion counterparts, they do not use a common lower-level library but bring their own wrappers to call out to the Mercurial binary. Calling the binary would be okay (for now), but it seems very difficult to use those plugins in standalone applications (outside of the IDE they were built for).

There is also HgKit, but that is very pre-alpha.

+3  A: 

Have you looked at Jython? As far as I can see here, it should help using the python mercurial modules from within a Java environment, just like JRuby does for Ruby.

Keltia
apparently, Jython cannot run Mercurial just yet, partly because of the sections of Mercurial that are written in C.
Thilo
Mercurial has back-ported most C modules to Python. I think they're almost, if not completely, done with that.
Marcus Lindblom
We are done, you can now use a --pure flag to setup.py in order to use the modules found under mercurial/pure. But note that this comes with a large speed penalty (I don't know how Jython fares, though).
Martin Geisler
+8  A: 

Such a library doesn't exist. MPM, author of Mercurial, takes the position that interfacing with the command line is the preferred mode of interop for non-Python applications and is extremely careful when it comes to maintaining backwards compatibility on the command line for that reason. Some of the disk-access code is native C, so you could theoretically do a JNI wrapper, but you'd still be missing key logic. Jython (as Oliver recommended) or invoking the command line app is the way to go.

Ry4an
I was just hoping that there is a Java library to wrap invoking the command line app (setting up the environment and parameters, as well as parsing the output)
Thilo
ditto here, any comments anyone?
Jason S
To my knowledge there isn't one.
Ry4an
I believe the latest mercurial has a build option to skip the native python methods and go pure python so jython may be an option
basszero
+2  A: 

The Maven SCM plugin seems to have a Mercurial provider available. However, I don't know how applicable that provider is in your case (ie how deeply it is tied to Maven architecture and/or how it interfaces with hg).

andri
That does look promising. It uses Maven interfaces, of course, but I guess/hope that those can be used outside of Maven as well, at least easier than the graphical plugins I mentioned in the question. As for interfacing with hg, it calls the command-line program (which is fine).
Thilo