Mercurial > hg > mercurial
changeset 773:bb37c581f463
use same way to run every command
author | eugene.petrenko@jetbrains.com |
---|---|
date | Tue, 25 Feb 2014 12:51:24 +0100 |
parents | 270e28fe1895 |
children | ce67edf7bae9 |
files | mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java |
diffstat | 4 files changed, 32 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java Tue Feb 25 12:37:10 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java Tue Feb 25 12:51:24 2014 +0100 @@ -32,9 +32,9 @@ private final String myHgPath; private final File myWorkDirectory; - public BaseCommand(@NotNull CommandSettings commandSettings, + public BaseCommand(@NotNull final CommandSettings commandSettings, @NotNull final String hgPath, - @NotNull File workingDir) { + @NotNull final File workingDir) { myCommandSettings = commandSettings; myHgPath = hgPath; myWorkDirectory = workingDir; @@ -52,15 +52,26 @@ } protected MercurialCommandLine createCL() { - MercurialCommandLine cl = new MercurialCommandLine(getPrivateData()); + final MercurialCommandLine cl = new MercurialCommandLine(getPrivateData()); cl.setExePath(myHgPath); cl.setEnvParams(myCommandSettings.getHgEnv()); cl.setPassParentEnvs(true); + + //include global arguments if any + cl.addParameters(myCommandSettings.getGlobalArguments()); + return cl; } - protected CommandResult runCommand(@NotNull MercurialCommandLine cli) throws VcsException { - return CommandUtil.runCommand(cli, myCommandSettings); + @NotNull + protected final CommandResult runCommand(@NotNull MercurialCommandLine cli) throws VcsException { + return runCommand(cli, myCommandSettings); + } + + @NotNull + protected final CommandResult runCommand(@NotNull final MercurialCommandLine cli, + @NotNull final CommandSettings commandSettings) throws VcsException { + return CommandUtil.runCommand(cli, commandSettings.setPrivateData(getPrivateData())); } protected Set<String> getPrivateData() {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java Tue Feb 25 12:37:10 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandSettings.java Tue Feb 25 12:51:24 2014 +0100 @@ -18,10 +18,7 @@ import org.jetbrains.annotations.NotNull; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; /** * @author dmitry.neverov @@ -29,41 +26,37 @@ public class CommandSettings { private int myTimeout = 3600; - private Set<String> myPrivateData = new HashSet<String>(); + private final Set<String> myPrivateData = new HashSet<String>(); private boolean myCheckForFailure = true; private boolean myFailWhenStderrNotEmpty = false; private String myLogLevel = "debug"; private Map<String, String> myHgEnv = new HashMap<String, String>(); private int myLogOutputLimit = -1; private int myExceptionOutputLimit = 5000; - - public CommandSettings() { - - } - - public CommandSettings(int timeout, - @NotNull Set<String> privateData, - boolean checkForFailure, - boolean failWhenStderrNotEmpty, - @NotNull String logLevel) { - myTimeout = timeout; - myPrivateData = privateData; - myCheckForFailure = checkForFailure; - myFailWhenStderrNotEmpty = failWhenStderrNotEmpty; - myLogLevel = logLevel; - } + private List<String> myGlobalArguments = new ArrayList<String>(0); public CommandSettings setTimeout(int timeout) { myTimeout = timeout; return this; } + @NotNull + public List<String> getGlobalArguments() { + return myGlobalArguments; + } + + @NotNull + public CommandSettings withGlobalArguments(@NotNull String... argz) { + myGlobalArguments.addAll(Arrays.asList(argz)); + return this; + } + public int getTimeout() { return myTimeout; } public CommandSettings setPrivateData(@NotNull Set<String> privateData) { - myPrivateData = privateData; + myPrivateData.addAll(privateData); return this; }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java Tue Feb 25 12:37:10 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java Tue Feb 25 12:51:24 2014 +0100 @@ -16,7 +16,6 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; -import jetbrains.buildServer.vcs.VcsException; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -38,12 +37,6 @@ myAuthSettings = authSettings; } - - protected CommandResult runCommand(@NotNull MercurialCommandLine cli, @NotNull CommandSettings s) throws VcsException { - s.setPrivateData(getPrivateData()); - return CommandUtil.runCommand(cli, s); - } - protected Set<String> getPrivateData() { String password = myAuthSettings.getPassword(); return password != null ? Collections.singleton(password) : Collections.<String>emptySet();
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java Tue Feb 25 12:37:10 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java Tue Feb 25 12:51:24 2014 +0100 @@ -43,7 +43,7 @@ cli.addParameter("version"); cli.addParameter("--quiet"); setDefaultLocale(cli); - CommandResult result = CommandUtil.runCommand(cli, myCommandSettings); + CommandResult result = runCommand(cli, myCommandSettings); return HgVersion.parse(result.getStdout()); }