changeset 347:4a49a0baf30b

Merge branch Eluru-6.5.x
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 11 Jan 2012 13:22:42 +0400
parents 607091bd8ccd (current diff) e8f0eb6d4ca4 (diff)
children fd56b9524834
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BranchesCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangedFilesCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CloneCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommandResultTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java mercurial-tests/src/testng.xml
diffstat 16 files changed, 122 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ArchiveCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -14,7 +14,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.util.FileUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
@@ -46,7 +45,7 @@
     setRevision(cli);
     setDestination(cli);
 
-    ExecResult res = runCommand(cli);
+    CommandResult res = runCommand(cli);
     failIfNotEmptyStdErr(cli, res);
     deleteHgArchival();
   }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -17,7 +17,6 @@
 
 import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.openapi.util.SystemInfo;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.util.StringUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
@@ -97,15 +96,15 @@
     cli.setExePath(myHgPath);
   }
 
-  protected ExecResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
+  protected CommandResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
     return CommandUtil.runCommand(cli, Collections.<String>emptySet());
   }
 
-  protected ExecResult runCommand(@NotNull GeneralCommandLine cli, int executionTimeout) throws VcsException {
+  protected CommandResult runCommand(@NotNull GeneralCommandLine cli, int executionTimeout) throws VcsException {
     return CommandUtil.runCommand(cli, executionTimeout, Collections.<String>emptySet());
   }
 
-  protected void failIfNotEmptyStdErr(@NotNull GeneralCommandLine cli, @NotNull ExecResult res) throws VcsException {
+  protected void failIfNotEmptyStdErr(@NotNull GeneralCommandLine cli, @NotNull CommandResult res) throws VcsException {
     if (!StringUtil.isEmpty(res.getStderr())) {
       CommandUtil.commandFailed(cli.getCommandLineString(), res);
     }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BranchesCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BranchesCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -16,7 +16,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
@@ -44,7 +43,7 @@
   public Map<String, ChangeSet> execute() throws VcsException {
     GeneralCommandLine cli = createCommandLine();
     cli.addParameter("branches");
-    ExecResult res = runCommand(cli);
+    CommandResult res = runCommand(cli);
     String stdout = res.getStdout();
     Map<String, ChangeSet> result = new HashMap<String, ChangeSet>();
     Pattern branchPattern = Pattern.compile("(.*)[\\s]+([0-9]+:[A-Za-z0-9]+).*");
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangedFilesCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangedFilesCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -16,7 +16,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.util.FileUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
@@ -53,7 +52,7 @@
       cli.addParameter(myRevId + ":" + myRevId);
       cli.addParameter("--style=" + styleFile.getAbsolutePath());
 
-      ExecResult res = runCommand(cli);
+      CommandResult res = runCommand(cli);
       return parseFiles(res.getStdout());
     } finally {
       FileUtil.delete(styleFile);
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CloneCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CloneCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -16,7 +16,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
@@ -75,6 +74,6 @@
     cli.addParameter(myRepository);
     cli.addParameter(myWorkingDir.getName());
 
-    ExecResult res = runCommand(cli, 24*3600); // some repositories are quite large, we set timeout to 24 hours
+    runCommand(cli, 24*3600); // some repositories are quite large, we set timeout to 24 hours
   }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResult.java	Wed Jan 11 13:22:42 2012 +0400
@@ -0,0 +1,44 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
+
+import jetbrains.buildServer.ExecResult;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Set;
+
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandUtil.removePrivateData;
+
+/**
+ * Decorator for ExecResult that filters out private data from stdout and strerr.
+ *
+ * @author dmitry.neverov
+ */
+public class CommandResult {
+
+  private final ExecResult myDelegate;
+  private final Set<String> myPrivateData;
+
+  public CommandResult(@NotNull final ExecResult execResult, @NotNull final Set<String> privateData) {
+    myDelegate = execResult;
+    myPrivateData = privateData;
+  }
+
+  @NotNull
+  public String getStdout() {
+    return removePrivateData(myDelegate.getStdout(), myPrivateData);
+  }
+
+  @NotNull
+  public String getStderr() {
+    return removePrivateData(myDelegate.getStderr(), myPrivateData);
+  }
+
+  @Nullable
+  public Throwable getException() {
+    return myDelegate.getException();
+  }
+
+  public int getExitCode() {
+    return myDelegate.getExitCode();
+  }
+}
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Wed Jan 11 13:22:42 2012 +0400
@@ -30,7 +30,7 @@
 public class CommandUtil {
   private static final int DEFAULT_COMMAND_TIMEOUT_SEC = 3600;
 
-  public static void checkCommandFailed(@NotNull String cmdName, @NotNull ExecResult res) throws VcsException {
+  public static void checkCommandFailed(@NotNull String cmdName, @NotNull CommandResult res) throws VcsException {
     if (res.getExitCode() != 0 || res.getException() != null)
       commandFailed(cmdName, res);
     if (res.getStderr().length() > 0) {
@@ -39,7 +39,7 @@
     }
   }
 
-  public static void commandFailed(final String cmdName, final ExecResult res) throws VcsException {
+  public static void commandFailed(final String cmdName, final CommandResult res) throws VcsException {
     final String message = createCommandLogMessage(cmdName, res);
     Loggers.VCS.warn(message);
     if (hasImportantException(res))
@@ -47,7 +47,7 @@
     throw new VcsException(message);
   }
 
-  private static String createCommandLogMessage(final String cmdName, final ExecResult res) {
+  private static String createCommandLogMessage(final String cmdName, final CommandResult res) {
     String stderr = res.getStderr();
     String stdout = res.getStdout();
     String exceptionMessage = getExceptionMessage(res);
@@ -58,7 +58,7 @@
   }
 
   @Nullable
-  private static String getExceptionMessage(ExecResult result) {
+  private static String getExceptionMessage(CommandResult result) {
     Throwable exception = result.getException();
     String message = null;
     if (exception != null) {
@@ -70,7 +70,7 @@
     return message;
   }
 
-  private static boolean hasImportantException(ExecResult result) {
+  private static boolean hasImportantException(CommandResult result) {
     Throwable exception = result.getException();
     if (exception != null) {
       return exception instanceof NullPointerException;
@@ -79,25 +79,33 @@
     }
   }
 
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
+  public static CommandResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
     return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, Collections.<String>emptySet());
   }
 
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, @NotNull Set<String> privateData) throws VcsException {
+  public static CommandResult runCommand(@NotNull GeneralCommandLine cli, @NotNull Set<String> privateData) throws VcsException {
     return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, privateData);
   }
 
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, final int executionTimeout, @NotNull Set<String> privateData) throws VcsException {
+  public static CommandResult runCommand(@NotNull GeneralCommandLine cli, final int executionTimeout, @NotNull Set<String> privateData) throws VcsException {
     return runCommand(cli, executionTimeout, privateData, true);
   }
 
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, @NotNull Set<String> privateData, final boolean checkFailure) throws VcsException {
+  public static CommandResult runCommand(@NotNull GeneralCommandLine cli, @NotNull Set<String> privateData, final boolean checkFailure) throws VcsException {
     return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, privateData, checkFailure);
   }
 
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, final int executionTimeout, @NotNull Set<String> privateData, final boolean checkFailure) throws VcsException {
+  public static CommandResult runCommand(@NotNull GeneralCommandLine cli, final int executionTimeout, @NotNull Set<String> privateData, final boolean checkFailure) throws VcsException {
     final String cmdStr = removePrivateData(cli.getCommandLineString(), privateData);
     Loggers.VCS.debug("Run command: " + cmdStr);
+    CommandResult res = run(cli, executionTimeout, cmdStr,privateData);
+    if (checkFailure)
+      CommandUtil.checkCommandFailed(cmdStr, res);
+    Loggers.VCS.debug("Command " + cmdStr + " output:\n" + res.getStdout());
+    return res;
+  }
+
+  private static CommandResult run(@NotNull final GeneralCommandLine cli, final int executionTimeout, @NotNull final String cmdStr, @NotNull final Set<String> privateData) {
     final long start = System.currentTimeMillis();
     ExecResult res = SimpleCommandLineProcessRunner.runCommand(cli, null, new SimpleCommandLineProcessRunner.RunCommandEventsAdapter() {
       @Override
@@ -110,18 +118,7 @@
         Loggers.VCS.debug("Command " + cmdStr + " took " + duration + "ms");
       }
     });
-
-    removePrivateData(privateData, res);
-
-    if (checkFailure)
-      CommandUtil.checkCommandFailed(cmdStr, res);
-    Loggers.VCS.debug("Command " + cmdStr + " output:\n" + res.getStdout());
-    return res;
-  }
-
-  private static void removePrivateData(final Set<String> privateData, final ExecResult res) {
-    res.setStdout(removePrivateData(res.getStdout(), privateData));
-    res.setStderr(removePrivateData(res.getStderr(), privateData));
+    return new CommandResult(res, privateData);
   }
 
   public static String removePrivateData(final String str, final Set<String> privateData) {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -16,7 +16,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
@@ -63,7 +62,7 @@
       cli.addParameter("--rev");
       cli.addParameter(myRevisionNumber.toString());
     }
-    ExecResult res = runCommand(cli);
+    CommandResult res = runCommand(cli);
     failIfNotEmptyStdErr(cli, res);
     String output = res.getStdout().trim();
     return output.contains(" ") ? output.substring(0, output.indexOf(" ")) : output;
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -17,7 +17,6 @@
 
 import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.openapi.util.JDOMUtil;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -95,7 +94,7 @@
       cli.addParameter(myLimit.toString());
     }
 
-    ExecResult res = runCommand(cli);
+    CommandResult res = runCommand(cli);
     try {
       List<ChangeSet> changes = parseChangeSetsXml(res.getStdout());
       if (myCalculateParents)
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -16,7 +16,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
@@ -43,7 +42,7 @@
       cli.addParameter("-f");
     }
     cli.addParameter(getSettings().getRepositoryUrl());
-    ExecResult res = runCommand(cli);
+    CommandResult res = runCommand(cli);
     failIfNotEmptyStdErr(cli, res);
   }
 }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/StatusCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -16,7 +16,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
@@ -49,7 +48,7 @@
     String to = myToId;
     if (to == null) to = "0";
     cli.addParameter(from + ":" + to);
-    ExecResult res = runCommand(cli);
+    CommandResult res = runCommand(cli);
     return parseFiles(res.getStdout());
   }
 
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -1,7 +1,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
@@ -33,17 +32,17 @@
   }
 
 
-  protected ExecResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
+  protected CommandResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
     return CommandUtil.runCommand(cli, getPrivateData());
   }
 
 
-  protected ExecResult runCommand(@NotNull GeneralCommandLine cli, int executionTimeout) throws VcsException {
+  protected CommandResult runCommand(@NotNull GeneralCommandLine cli, int executionTimeout) throws VcsException {
     return CommandUtil.runCommand(cli, executionTimeout, getPrivateData());
   }
 
 
-  protected ExecResult runCommand(@NotNull GeneralCommandLine cli, boolean checkFailure) throws VcsException {
+  protected CommandResult runCommand(@NotNull GeneralCommandLine cli, boolean checkFailure) throws VcsException {
     return CommandUtil.runCommand(cli, getPrivateData(), checkFailure);
   }
 }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java	Wed Jan 11 13:22:42 2012 +0400
@@ -1,7 +1,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgVersion;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
@@ -27,7 +26,7 @@
     GeneralCommandLine cli = createCommandLine();
     cli.addParameter("version");
     cli.addParameter("--quiet");
-    ExecResult result = runCommand(cli);
+    CommandResult result = runCommand(cli);
     return HgVersion.parse(result.getStdout());
   }
 
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Wed Jan 11 13:22:42 2012 +0400
@@ -16,7 +16,7 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandResult;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandUtil;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.Settings;
 import jetbrains.buildServer.vcs.*;
@@ -236,7 +236,7 @@
     cli.setExePath(vcsRoot.getProperty(Constants.HG_COMMAND_PATH_PROP));
     cli.setWorkDirectory(vcsRoot.getProperty(Constants.REPOSITORY_PROP));
     cli.addParameter("tags");
-    ExecResult res = CommandUtil.runCommand(cli);
+    CommandResult res = CommandUtil.runCommand(cli);
     assertTrue(res.getStdout().contains("new_tag"));
     assertTrue(res.getStdout().contains("1:1d446e82d356"));
   }
@@ -253,7 +253,7 @@
     cli.setExePath(vcsRoot.getProperty(Constants.HG_COMMAND_PATH_PROP));
     cli.setWorkDirectory(vcsRoot.getProperty(Constants.REPOSITORY_PROP));
     cli.addParameter("tags");
-    ExecResult res = CommandUtil.runCommand(cli);
+    CommandResult res = CommandUtil.runCommand(cli);
     assertTrue(res.getStdout().contains("branch_tag"));
     assertTrue(res.getStdout().contains("7:376dcf05cd2a"));
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandResultTest.java	Wed Jan 11 13:22:42 2012 +0400
@@ -0,0 +1,40 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
+
+import jetbrains.buildServer.ExecResult;
+import jetbrains.buildServer.StreamGobbler;
+import org.jetbrains.annotations.NotNull;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.util.Collections;
+
+import static org.testng.AssertJUnit.assertFalse;
+
+/**
+ * @author dmitry.neverov
+ */
+@Test
+public class CommandResultTest {
+
+  public void output_should_not_contain_private_data() {
+    String password = "pass";
+    ExecResult result = createExecResult(password, password);
+    CommandResult commandResult = new CommandResult(result, Collections.singleton(password));
+    assertFalse(commandResult.getStdout().contains(password));
+    assertFalse(commandResult.getStderr().contains(password));
+  }
+
+  private ExecResult createExecResult(@NotNull final String output, @NotNull final String error) {
+    ExecResult result = new ExecResult();
+    result.setOutputGobbler(createStringGobbler(output));
+    result.setErrorGobbler(createStringGobbler(error));
+    return result;
+  }
+
+  private StreamGobbler createStringGobbler(@NotNull final String str) {
+    StreamGobbler gobbler = new StreamGobbler(new ByteArrayInputStream(str.getBytes()));
+    gobbler.start();
+    return gobbler;
+  }
+
+}
--- a/mercurial-tests/src/testng.xml	Tue Jan 10 13:08:37 2012 +0400
+++ b/mercurial-tests/src/testng.xml	Wed Jan 11 13:22:42 2012 +0400
@@ -8,6 +8,7 @@
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.command.StatusCommandTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.command.PushCommandTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.command.IdentifyCommandTest"/>
+      <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandResultTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialVcsSupportTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.AgentSideCheckoutTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.AgentSideCheckoutWithSubreposTest"/>