Mercurial > hg > mercurial
changeset 827:194c8f8d6e4c
add helper to enable bundled plugins for Mercurial
author | eugene.petrenko@jetbrains.com |
---|---|
date | Fri, 30 May 2014 17:23:17 +0200 |
parents | 6f76b2e5afdc |
children | 8d02c7b1f812 |
files | mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java |
diffstat | 3 files changed, 34 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java Fri May 30 17:21:12 2014 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java Fri May 30 17:23:17 2014 +0200 @@ -83,6 +83,12 @@ throw new VcsException("Not yet implemented"); } + protected void setupExtensionsFromResource(@NotNull final MercurialCommandLine cli, + @NotNull final File tempDir, + @NotNull final String commandPy) throws VcsException{ + CommandUtil.setupExtensionsFromResource(cli, tempDir, commandPy); + } + @NotNull protected Set<String> getPrivateData() { return emptySet();
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Fri May 30 17:21:12 2014 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java Fri May 30 17:23:17 2014 +0200 @@ -19,17 +19,41 @@ import jetbrains.buildServer.LineAwareByteArrayOutputStream; import jetbrains.buildServer.SimpleCommandLineProcessRunner; import jetbrains.buildServer.log.Loggers; +import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.vcs.VcsException; import org.jetbrains.annotations.NotNull; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.nio.charset.Charset; import java.util.Set; public class CommandUtil { + @NotNull + private static File extractCommandPy(@NotNull final File root, @NotNull final String commandPy) throws VcsException { + try { + final File py = new File(root, commandPy); + FileUtil.copyResource(CommandUtil.class, "/python/" + commandPy, py); + + if (py.length() < 100) throw new IOException("Failed to unpack command resource"); + return py; + } catch (IOException e) { + throw new VcsException("Failed to extract .py file: " + e.getMessage(), e); + } + } + + public static void setupExtensionsFromResource(@NotNull final MercurialCommandLine cli, + @NotNull final File tempDir, + @NotNull final String commandPy) throws VcsException { + final File file = extractCommandPy(tempDir, commandPy); + final String extName = commandPy.replaceAll("[^a-zA-Z]+", ""); + cli.addParameters("--config", "extensions." + extName + "=" + file); + } + + @NotNull public static CommandResult runCommand(@NotNull MercurialCommandLine cli, @NotNull CommandSettings settings) throws VcsException { final String command = removePrivateData(cli.getCommandLineString(), settings.getPrivateData()); logRunCommand(cli, command, settings);
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java Fri May 30 17:21:12 2014 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java Fri May 30 17:23:17 2014 +0200 @@ -56,20 +56,6 @@ } } - @NotNull - private File extractCommandPy(@NotNull final File root) throws VcsException { - try { - final File py = new File(root, "load-substates-command.py"); - - FileUtil.copyResource(getClass(), "/python/load-substates-command.py", py); - - if (py.length() < 100) throw new IOException("Failed to unpack command resource"); - return py; - } catch (IOException e) { - throw new VcsException("Failed to extract .py file: " + e.getMessage(), e); - } - } - public void call(@NotNull final Callback consumer) throws VcsException { final HgVersion hgVersion = myRepo.version().call(); if (!hgVersion.isEqualsOrGreaterThan(REQUIRED_VERSION)) { @@ -79,9 +65,7 @@ final File root = createTmpDir(); try { - final File py = extractCommandPy(root); - - callImpl(root, py, consumer); + callImpl(root, consumer); } finally { FileUtil.delete(root); } @@ -104,12 +88,12 @@ } private void callImpl(@NotNull final File root, - @NotNull final File commandPy, @NotNull final Callback consumer) throws VcsException { final MercurialCommandLine cli = createCommandLine(); cli.addParameter("--debug"); - cli.addParameter("--config"); - cli.addParameter("extensions.logextcj=" + commandPy); + + setupExtensionsFromResource(cli, root, "load-substates-command.py"); + cli.addParameter("load-substates"); cli.addParameter(new File(root, "result").getPath());