changeset 432:4a76645fe087 Faradi-7.0.x

TW-21516 hg version detection should not depend on locale settings
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Tue, 15 May 2012 10:21:05 +0400
parents 83aff5760c25
children 2617dcc70c15 6c43663744d9
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java
diffstat 4 files changed, 44 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java	Fri Apr 27 07:15:04 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java	Tue May 15 10:21:05 2012 +0400
@@ -79,6 +79,10 @@
     return new ArchiveCommand(myHgPath, myWorkingDir, myAuthSettings);
   }
 
+  public VersionCommand version() {
+    return new VersionCommand(myHgPath, myWorkingDir);
+  }
+
   public String path() {
     return myWorkingDir.getAbsolutePath();
   }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java	Fri Apr 27 07:15:04 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VersionCommand.java	Tue May 15 10:21:05 2012 +0400
@@ -7,6 +7,8 @@
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author dmitry.neverov
@@ -27,8 +29,20 @@
     GeneralCommandLine cli = createCommandLine();
     cli.addParameter("version");
     cli.addParameter("--quiet");
+    setDefaultLocale(cli);
     CommandResult result = CommandUtil.runCommand(cli);
     return HgVersion.parse(result.getStdout());
   }
 
+
+  private void setDefaultLocale(GeneralCommandLine commandLine) {
+    Map<String, String> env = commandLine.getEnvParams();
+    if (env == null)
+      env = new HashMap<String, String>();
+    env.put("LANG", "en_US");
+    env.put("LANGUAGE", "en_US");
+    env.put("LC_MESSAGE", "en_US");
+    commandLine.setEnvParams(env);
+  }
+
 }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java	Fri Apr 27 07:15:04 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java	Tue May 15 10:21:05 2012 +0400
@@ -53,7 +53,6 @@
   }
 
   private HgVersion getHgVersion() throws VcsException {
-    VersionCommand versionCommand = new VersionCommand(myHgPath, myWorkingDir);
-    return versionCommand.call();
+    return version().call();
   }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Fri Apr 27 07:15:04 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue May 15 10:21:05 2012 +0400
@@ -16,9 +16,7 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-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.buildTriggers.vcs.mercurial.command.*;
 import jetbrains.buildServer.vcs.*;
 import jetbrains.buildServer.vcs.impl.VcsRootImpl;
 import jetbrains.buildServer.vcs.patches.PatchBuilderImpl;
@@ -511,6 +509,30 @@
   }
 
 
+  public void hg_version_should_not_depend_on_locale() throws IOException, VcsException {
+    HgRepo repo = new HgRepo(new File(simpleRepo()), Util.getHgPath(), new AuthSettings(null, null));
+    HgVersion defaultLocaleVersion = repo.version().call();
+
+    VersionCommand russianLocalVersion = new VersionCommand(Util.getHgPath(), new File(simpleRepo())) {
+      @Override
+      protected GeneralCommandLine createCommandLine() {
+        GeneralCommandLine commandLine = super.createCommandLine();
+        Map<String, String> env = commandLine.getEnvParams();
+        if (env == null)
+          env = new HashMap<String, String>();
+        env.put("LANG", "ru_RU");
+        env.put("LANGUAGE", "ru_RU");
+        env.put("LC_MESSAGE", "ru_RU");
+        commandLine.setEnvParams(env);
+        return commandLine;
+      }
+    };
+
+    HgVersion russianLocaleVersion = russianLocalVersion.call();
+    assertEquals(russianLocaleVersion, defaultLocaleVersion);
+  }
+
+
   private void assertFiles(final List<String> expectedFiles, final ModificationData modificationData) {
     Set<String> actualFiles = new HashSet<String>();
     for (VcsChange vc: modificationData.getChanges()) {