用于 Java 的 Mercurial API? [英] Mercurial API for Java?

查看:16
本文介绍了用于 Java 的 Mercurial API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个简单的 API 可以从 Java 访问 Mercurial 存储库?

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

有适用于 Netbeans 和 Eclipse 的插件,但与 Subversion 对应的插件不同,它们不使用通用的低级库,而是自带包装器来调用 Mercurial 二进制文件.调用二进制文件是可以的(目前),但在独立应用程序中使用这些插件似乎非常困难(在它们构建的 IDE 之外).

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).

还有 HgKit,但那是非常前 alpha.

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

推荐答案

一个新选项是 JavaHg,它为您提供高级 Java API.单元测试举一个很好的例子来说明它是如何编程的(从 JavaHg 0.1 开始):

A new option is JavaHg, which gives you a high-level Java API. The unit tests give a good example of how it is to program with it (as of JavaHg 0.1):

public void commitTest() throws IOException {
    Repository repo = getTestRepository();
    writeFile("x", "abc");

    CommitCommand commit = CommitCommand.on(repo);
    StatusCommand status = StatusCommand.on(repo);

    List<StatusLine> statusLines = status.lines();
    Assert.assertEquals(1, statusLines.size());
    Assert.assertEquals(StatusLine.Type.UNKNOWN, statusLines.get(0).getType());

    AddCommand.on(repo).execute();
    statusLines = status.lines();
    Assert.assertEquals(1, statusLines.size());
    Assert.assertEquals(StatusLine.Type.ADDED, statusLines.get(0).getType());

    commit.message("Add a file").user("Martin Geisler");
    Changeset cset = commit.execute();
    Assert.assertEquals("Martin Geisler", cset.getUser());
    statusLines = status.lines();
    Assert.assertEquals(0, statusLines.size());
}

它与 1.9 及更高版本中存在的 Mercurial 命令服务器交互.这意味着会有一个持续的 Mercurial 进程接受多个命令,因此您避免启动开销通常与启动 Mercurial 相关联.我们预计它将在即将发布的 MercurialEclipse 版本中使用.(我是 JavaHg 的作者之一.)

It interacts with the Mercurial command server present in version 1.9 and later. This means that there will be a persistent Mercurial process around that accepts multiple commands and so you avoid the startup overhead normally associated with launching Mercurial. We expect that it will be used in a coming version of MercurialEclipse. (I'm one of the authors of JavaHg.)

这篇关于用于 Java 的 Mercurial API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆