适用于 Java 的 Mercurial API?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/380321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mercurial API for Java?
提问by Thilo
Is there a plain API to access Mercurial repositories from Java?
是否有一个简单的 API 可以从 Java 访问 Mercurial 存储库?
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).
有适用于 Netbeans 和 Eclipse 的插件,但与它们的 Subversion 对应物不同,它们不使用通用的低级库,而是自带包装器来调用 Mercurial 二进制文件。调用二进制文件是可以的(目前),但在独立应用程序中使用这些插件似乎非常困难(在它们构建的 IDE 之外)。
There is also HgKit, but that is very pre-alpha.
还有 HgKit,但那是非常前 alpha 的。
回答by Martin Geisler
A new option is JavaHg, which gives you a high-level Java API. The unit testsgive a good example of how it is to program with it (as of JavaHg 0.1):
一个新选项是JavaHg,它为您提供高级 Java API。所述单元测试得到的它是如何与它编程(如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());
}
It interacts with the Mercurial command serverpresent 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 overheadnormally 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.)
它与1.9 及更高版本中的Mercurial 命令服务器交互。这意味着会有一个持久的 Mercurial 进程接受多个命令,因此您可以避免通常与启动 Mercurial 相关的启动开销。我们预计它将在即将发布的 MercurialEclipse 版本中使用。(我是 JavaHg 的作者之一。)
回答by Mykel Alvis
回答by Keltia
回答by andri
The Maven SCM pluginseems 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).
在Maven的SCM插件似乎有水银供应商提供。但是,我不知道该提供程序在您的情况下有多适用(即它与 Maven 架构的关联程度和/或它如何与 hg 交互)。

