changeset 16:7aa397165fa0

identify command added, test connection now uses identify command
author Pavel.Sher
date Wed, 16 Jul 2008 01:26:07 +0400
parents 3539151629aa
children 21b5b1c5dd74
files mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java
diffstat 4 files changed, 58 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue Jul 15 22:12:17 2008 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Wed Jul 16 01:26:07 2008 +0400
@@ -127,6 +127,19 @@
     assertEquals("modified\r\nbbb", new String(content));
   }
 
+  public void testTestConnection() throws IOException, VcsException {
+    VcsRootImpl vcsRoot = createVcsRoot();
+
+    System.out.println(myVcs.testConnection(vcsRoot));
+
+    vcsRoot.addProperty(Constants.REPOSITORY_PROP, "/some/non/existent/path");
+    try {
+      myVcs.testConnection(vcsRoot);
+      fail("Exception expected");
+    } catch (VcsException e) {
+    }
+  }
+
   private Object normalizePath(final String path) {
     return path.replace(File.separatorChar, '/');
   }
--- a/mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Tue Jul 15 22:12:17 2008 +0400
+++ b/mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Wed Jul 16 01:26:07 2008 +0400
@@ -171,12 +171,17 @@
   }
 
   public boolean isTestConnectionSupported() {
-    return false;
+    return true;
   }
 
   @Nullable
   public String testConnection(final VcsRoot vcsRoot) throws VcsException {
-    return null;
+    Settings settings = new Settings(myServerPaths, vcsRoot);
+    IdentifyCommand id = new IdentifyCommand(settings);
+    StringBuilder res = new StringBuilder();
+    res.append("hg identify " + settings.getRepository());
+    res.append('\n').append(id.execute());
+    return res.toString();
   }
 
   @Nullable
--- a/mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Tue Jul 15 22:12:17 2008 +0400
+++ b/mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Wed Jul 16 01:26:07 2008 +0400
@@ -4,6 +4,7 @@
 import jetbrains.buildServer.ExecResult;
 import jetbrains.buildServer.SimpleCommandLineProcessRunner;
 import jetbrains.buildServer.log.Loggers;
+import jetbrains.buildServer.util.StringUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
@@ -15,7 +16,13 @@
   }
 
   public static void commandFailed(final String cmdName, final ExecResult res) throws VcsException {
-    final String message = "'" + cmdName + "' command failed.\nerr: " + res.getStderr() + "\nout: " + res.getStdout() + "\nexception: " + res.getException().toString();
+    Throwable exception = res.getException();
+    String stderr = res.getStderr();
+    String stdout = res.getStdout();
+    final String message = "'" + cmdName + "' command failed.\n" +
+            (!StringUtil.isEmpty(stderr) ? "stderr: " + stderr + "\n" : "") +
+            (!StringUtil.isEmpty(stdout) ? "stdout: " + stdout + "\n" : "") +
+            (exception != null ? "exception: " + exception.getLocalizedMessage() : "");
     Loggers.VCS.warn(message);
     throw new VcsException(message);
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java	Wed Jul 16 01:26:07 2008 +0400
@@ -0,0 +1,30 @@
+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;
+
+/**
+ * @author Pavel.Sher
+ *         Date: 16.07.2008
+ */
+public class IdentifyCommand {
+  private Settings mySettings;
+
+  public IdentifyCommand(@NotNull final Settings settings) {
+    mySettings = settings;
+  }
+
+  public String execute() throws VcsException {
+    GeneralCommandLine cli = new GeneralCommandLine();
+    cli.setExePath(mySettings.getHgCommandPath());
+    cli.addParameter("identify");
+    cli.addParameter(mySettings.getRepository());
+    ExecResult res = CommandUtil.runCommand(cli);
+    if (res.getStderr().length() > 0) {
+      CommandUtil.commandFailed(cli.getCommandLineString(), res);
+    }
+    return res.getStdout();
+  }
+}