changeset 382:01f8d8c216b2

Merge branch remote-run/hg-detect-logging
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 15 Feb 2012 16:31:31 +0400
parents 44a16c27bed6 (diff) aaa105d2294d (current diff)
children 852bea9949a8
files
diffstat 4 files changed, 20 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java	Wed Feb 15 11:38:23 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java	Wed Feb 15 16:31:31 2012 +0400
@@ -16,7 +16,6 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import com.intellij.execution.configurations.GeneralCommandLine;
-import com.intellij.openapi.util.SystemInfo;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
@@ -51,37 +50,11 @@
 
   protected GeneralCommandLine createCL() {
     GeneralCommandLine cl = new MercurialCommandLine(getPrivateData());
-    setupExecutable(cl);
+    cl.setExePath(myHgPath);
     return cl;
   }
 
   protected Set<String> getPrivateData() {
     return emptySet();
   }
-
-  /**
-   * Since mercurial 1.7 on Windows the only file inside '<mercurial_install_dir>/bin' is 'hg.cmd'
-   * which run hg.exe placed in the parent dir. GeneralCommandLine will not find hg.cmd, in the
-   * case when $PATH contains <mercurial_install_dir>/bin and doesn't contain <mercurial_install_dir>
-   * and hg executable is set to 'hg'. To fix it - run hg using windows shell which expand
-   * hg to hg.cmd correctly.
-   * @param cli command line in which to setup hg executable
-   */
-  private void setupExecutable(GeneralCommandLine cli) {
-    if (SystemInfo.isWindows && myHgPath.equals("hg")) {
-      setupCmd(cli);
-    } else {
-      setupHg(cli);
-    }
-  }
-
-  private void setupCmd(GeneralCommandLine cli) {
-    cli.setExePath("cmd");
-    cli.addParameter("/c");
-    cli.addParameter("hg");
-  }
-
-  private void setupHg(GeneralCommandLine cli) {
-    cli.setExePath(myHgPath);
-  }
 }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Wed Feb 15 11:38:23 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Wed Feb 15 16:31:31 2012 +0400
@@ -25,6 +25,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -74,6 +75,8 @@
 
   public List<ChangeSet> execute() throws VcsException {
     GeneralCommandLine cli = createCommandLine();
+    cli.setCharset(Charset.forName("UTF-8"));
+    cli.addParameters("--encoding", "UTF-8");
     cli.addParameter("log");
     cli.addParameter("-v");
     cli.addParameter("--style=" + myTemplate.getAbsolutePath());
@@ -95,17 +98,17 @@
     }
 
     CommandResult res = runCommand(cli);
+    String output = res.getStdout();
     try {
-      List<ChangeSet> changes = parseChangeSetsXml(res.getStdout());
+      List<ChangeSet> changes = parseChangeSetsXml(output);
       if (myCalculateParents)
         assignTrivialParents(changes);
       return changes;
     } catch (Exception e) {
-      throw new VcsException("Error while parsing log output:\n" + res.getStdout(), e);
+      throw new VcsException("Error while parsing log output:\n" + output, e);
     }
   }
 
-
   private List<ChangeSet> parseChangeSetsXml(@NotNull final String xml) throws JDOMException, IOException, ParseException {
     if ("".equals(xml))
       return Collections.emptyList();
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialCommandLine.java	Wed Feb 15 11:38:23 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialCommandLine.java	Wed Feb 15 16:31:31 2012 +0400
@@ -4,12 +4,14 @@
 import jetbrains.buildServer.util.StringUtil;
 import org.jetbrains.annotations.NotNull;
 
+import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.Set;
 
 public class MercurialCommandLine extends GeneralCommandLine {
 
   private final Set<String> myPrivateData;
+  private Charset myCharset;
 
   public MercurialCommandLine() {
     this(Collections.<String>emptySet());
@@ -31,6 +33,16 @@
     super.addParameter(escaped);
   }
 
+  @Override
+  public void setCharset(@NotNull Charset charset) {
+    myCharset = charset;
+  }
+
+  @Override
+  public Charset getCharset() {
+    return myCharset != null ? myCharset : super.getCharset();
+  }
+
   private String escape(String s) {
     return StringUtil.escapeQuotesIfWindows(s);
   }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommandFactoryImpl.java	Wed Feb 15 11:38:23 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommandFactoryImpl.java	Wed Feb 15 16:31:31 2012 +0400
@@ -57,9 +57,7 @@
 
   private File createLogTemplate(@NotNull final File templateFileDir) throws IOException {
     File template = new File(templateFileDir, LOG_TEMPLATE_NAME);
-    if (!template.exists()) {
-      FileUtil.copyResource(CommandFactoryImpl.class, "/buildServerResources/log.template", template);
-    }
+    FileUtil.copyResource(CommandFactoryImpl.class, "/buildServerResources/log.template", template);
     return template;
   }