changeset 137:43dd4142b0f5 Eluru-6.0.x

Merge changes since september
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 22 Dec 2010 11:39:14 +0300
parents 1902915c4c91 (current diff) ea7972ed3ab7 (diff)
children 43db29903d63
files mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial.ipr mercurial.properties
diffstat 13 files changed, 166 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/build.xml	Thu Dec 02 14:43:27 2010 +0300
+++ b/build.xml	Wed Dec 22 11:39:14 2010 +0300
@@ -6,6 +6,17 @@
 
   <property name="plugin.name" value="mercurial"/>
 
+  <property name="build.number" value=""/>
+  <tstamp>
+    <format property="timestamp" pattern="yyyyMMddhhmmss"/>
+  </tstamp>
+  <property name="snapshot.build.number" value="SNAPSHOT-${timestamp}"/>
+  <property name="build.vcs.number" value=""/>
+
+  <condition property="plugin.version" value="${snapshot.build.number}" else="${build.number}">
+    <matches pattern="snapshot-.*" string="${build.number}" casesensitive="false"/>
+  </condition>
+
   <import file="teamcity-common.xml"/>
 
   <target name="package" depends="define.version">
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Wed Dec 22 11:39:14 2010 +0300
@@ -22,6 +22,7 @@
   String REPOSITORY_PROP = "repositoryPath";
   String BRANCH_NAME_PROP = "branchName";
   String HG_COMMAND_PATH_PROP = "hgCommandPath";
+  String HG_PATH_ENV = "TEAMCITY_HG_PATH";
   String SERVER_CLONE_PATH_PROP = "serverClonePath";
   String USERNAME = "username";
   String PASSWORD = VcsRoot.SECURE_PROPERTY_PREFIX + "password";
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Wed Dec 22 11:39:14 2010 +0300
@@ -61,6 +61,8 @@
     GeneralCommandLine cli = createCommandLine();
     cli.addParameter("log");
     cli.addParameter("-v");
+    cli.addParameter("--style");
+    cli.addParameter("default");
     cli.addParameter("-b");
     cli.addParameter(getSettings().getBranchName());
     cli.addParameter("-r");
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java	Wed Dec 22 11:39:14 2010 +0300
@@ -17,12 +17,17 @@
 
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.Constants;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.PathUtil;
+import jetbrains.buildServer.log.Loggers;
 import jetbrains.buildServer.util.Hash;
 import jetbrains.buildServer.util.StringUtil;
 import jetbrains.buildServer.vcs.VcsRoot;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -92,9 +97,9 @@
 
   private final static Set<String> AUTH_PROTOS = new HashSet<String>();
   static {
-    AUTH_PROTOS.add("http://");
-    AUTH_PROTOS.add("https://");
-    AUTH_PROTOS.add("ssh://");
+    AUTH_PROTOS.add("http");
+    AUTH_PROTOS.add("https");
+    AUTH_PROTOS.add("ssh");
   }
 
   /**
@@ -102,45 +107,77 @@
    * @return URL to use for push command
    */
   public String getRepositoryUrl() {
-    if (containsCredentials(myRepository)) return myRepository;
-
-    for (String proto: AUTH_PROTOS) {
-      if (myRepository.startsWith(proto)) {
-        String repoUrl = myRepository.substring(proto.length());
-        int endIdx = repoUrl.indexOf('@');
-        int slashIdx = repoUrl.indexOf('/');
-        if (endIdx != -1 && slashIdx > endIdx) {
-          repoUrl = repoUrl.substring(endIdx+1);
-        }
-
-        String cre = "";
-        if (!StringUtil.isEmpty(myUsername)) {
-          cre += myUsername;
-          if (!StringUtil.isEmpty(myPassword)) {
-            cre += ":" + myPassword;
-          }
-          cre += "@";
-        }
-
-        return proto + cre + repoUrl;
+    if (isRequireCredentials()) {
+      if (containsCredentials(myRepository)) return myRepository;
+      try {
+        return createURLWithCredentials(myRepository);
+      } catch (MalformedURLException e) {
+        Loggers.VCS.warn("Error while parsing url " + myRepository, e);
       }
+      return myRepository;
+    } else {
+      return myRepository;
     }
-
-    return myRepository;
   }
 
   private boolean containsCredentials(final String repository) {
-    for (String proto: AUTH_PROTOS) {
-      if (repository.startsWith(proto)) {
-        String withoutProto = repository.substring(proto.length());
-        int comma = withoutProto.indexOf(':');
-        int at = withoutProto.indexOf('@');
-        if (at != -1 && comma != -1 && at > comma) return true;
+    try {
+      URL url = new URL(repository);
+      String userInfo = url.getUserInfo();
+      return userInfo != null && userInfo.contains(":");
+    } catch (MalformedURLException e) {
+      return false;
+    }
+  }
+
+  private String createURLWithCredentials(final String originalUrl) throws MalformedURLException {
+    String userInfo = createUserInfo();
+    if (!"".equals(userInfo)) {
+      URL url = new URL(originalUrl);
+      return url.getProtocol() + "://"
+              + userInfo + "@"
+              + url.getHost()
+              + (url.getPort() != -1 ? ":" + url.getPort() : "")
+              + url.getFile()
+              + (url.getRef() != null ? url.getRef() : "");
+    } else {
+      return originalUrl;
+    }
+  }
+
+  private boolean isRequireCredentials() {
+    for (String scheme : AUTH_PROTOS) {
+      if (myRepository.startsWith(scheme + ":")) {
+        return true;
       }
     }
     return false;
   }
 
+  private String createUserInfo() {
+    String userInfo = "";
+    if (!StringUtil.isEmpty(myUsername)) {
+      userInfo += myUsername;
+      if (!StringUtil.isEmpty(myPassword)) {
+        userInfo += ":" + myPassword;
+      }
+    }
+    return getEscapedUserInfo(userInfo);
+  }
+
+  private static String getEscapedUserInfo(String userInfo) {
+    try {
+      URI uri = new URI("http", userInfo, "somewhere.com", 80, "", "", "");
+      String escapedURI = uri.toASCIIString();
+      int from = "http://".length();
+      int to = escapedURI.indexOf("somewhere.com") - 1;
+      return escapedURI.substring(from, to);
+    } catch (URISyntaxException e) {
+      assert false;
+    }
+    return userInfo;
+  }
+
   public void setHgCommandPath(@NotNull final String hgCommandPath) {
     myHgCommandPath = hgCommandPath;
   }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Wed Dec 22 11:39:14 2010 +0300
@@ -158,7 +158,7 @@
         Loggers.VCS.warn("Unable to obtain content of the file: " + filePath);
       }
     } finally {
-      FileUtil.delete(parentDir);
+      deleteTmpDir(parentDir);
     }
     return new byte[0];
   }
@@ -312,7 +312,14 @@
         }
       }
     } finally {
-      FileUtil.delete(parentDir);
+      deleteTmpDir(parentDir);
+    }
+  }
+
+  private void deleteTmpDir(File parentDir) {
+    boolean dirDeleted = FileUtil.delete(parentDir);
+    if (!dirDeleted) {
+      Loggers.VCS.warn("Can not delete directory \"" + parentDir.getAbsolutePath() + "\"");
     }
   }
 
@@ -603,9 +610,9 @@
   private String fixTagName(final String label) {
     // according to Mercurial documentation http://hgbook.red-bean.com/hgbookch8.html#x12-1570008
     // tag name must not contain:
-    // Colon (ASCII 58, :)
-    // Carriage return (ASCII 13, \r)
-    // Newline (ASCII 10, \n)
+    // Colon (ASCII 58, �:�)
+    // Carriage return (ASCII 13, �\r�)
+    // Newline (ASCII 10, �\n�)
     // all these characters will be replaced with _ (underscore)
     return label.replace(':', '_').replace('\r', '_').replace('\n', '_');
   }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java	Wed Dec 22 11:39:14 2010 +0300
@@ -52,7 +52,7 @@
 
   protected VcsRootImpl createVcsRoot(@NotNull String repPath) throws IOException {
     VcsRootImpl vcsRoot = new VcsRootImpl(1, Constants.VCS_NAME);
-    vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, new File("mercurial-tests/testData/bin/hg.exe").getAbsolutePath());
+    vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, new File(Util.getHgPath()).getAbsolutePath());
     File repository = LocalRepositoryUtil.prepareRepository(repPath);
     vcsRoot.addProperty(Constants.REPOSITORY_PROP, repository.getAbsolutePath());
     return vcsRoot;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Wed Dec 22 11:39:14 2010 +0300
@@ -39,6 +39,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Locale;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java	Wed Dec 22 11:39:14 2010 +0300
@@ -51,12 +51,48 @@
     assertEquals("http://user:pwd@host.com/path@", settings.getRepositoryUrl());
   }
 
+  public void test_url_with_at_in_username() {
+    VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path", "my.name@gmail.com", "1234");
+    Settings settings = new Settings(new File("."), vcsRoot);
+    assertEquals("http://my.name%40gmail.com:1234@host.com/path", settings.getRepositoryUrl());
+  }
+
+  /** TW-13768 */
+  public void test_underscore_in_host() {
+		VcsRootImpl vcsRoot = createVcsRoot("http://Klekovkin.SDK_GARANT:8000/", "my.name@gmail.com", "1234");
+		Settings settings = new Settings(new File("."), vcsRoot);
+		assertEquals("http://my.name%40gmail.com:1234@Klekovkin.SDK_GARANT:8000/", settings.getRepositoryUrl());
+	}
+
+  /** TW-13768 */
+  public void test_underscore_in_host_with_credentials_in_url() {
+    VcsRootImpl vcsRoot = createVcsRoot("http://me:mypass@Klekovkin.SDK_GARANT:8000/");
+		Settings settings = new Settings(new File("."), vcsRoot);
+		assertEquals("http://me:mypass@Klekovkin.SDK_GARANT:8000/", settings.getRepositoryUrl());
+  }
+
+  public void test_windows_path() throws Exception {
+    VcsRootImpl vcsRoot = createVcsRoot("c:\\windows\\path");
+    Settings settings = new Settings(new File("."), vcsRoot);
+    assertEquals("c:\\windows\\path", settings.getRepositoryUrl());
+  }
+
+  public void test_file_scheme_has_no_credentials() {
+    VcsRootImpl vcsRoot = createVcsRoot("file:///path/to/repo", "my.name@gmail.com", "1234");
+    Settings settings = new Settings(new File("."), vcsRoot);
+    assertEquals("file:///path/to/repo", settings.getRepositoryUrl());
+  }
+
   private VcsRootImpl createVcsRoot(String url) {
+    return createVcsRoot(url, "user", "pwd");
+  }
+
+  private VcsRootImpl createVcsRoot(String url, String userName, String password) {
     VcsRootImpl vcsRoot = new VcsRootImpl(1, Constants.VCS_NAME);
     vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, "hg.exe");
     vcsRoot.addProperty(Constants.REPOSITORY_PROP, url);
-    vcsRoot.addProperty(Constants.USERNAME, "user");
-    vcsRoot.addProperty(Constants.PASSWORD, "pwd");
+    vcsRoot.addProperty(Constants.USERNAME, userName);
+    vcsRoot.addProperty(Constants.PASSWORD, password);
     return vcsRoot;
   }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java	Wed Dec 22 11:39:14 2010 +0300
@@ -0,0 +1,21 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import java.io.IOException;
+
+/**
+ * @author dmitry.neverov
+ */
+public final class Util {
+
+  private Util() {}
+
+  public static String getHgPath() throws IOException {
+    String providedHg = System.getenv(Constants.HG_PATH_ENV);
+    if (providedHg != null) {
+      return providedHg;
+    } else {
+      return "mercurial-tests/testData/bin/hg.exe";
+    }
+  }
+
+}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTestCase.java	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommandTestCase.java	Wed Dec 22 11:39:14 2010 +0300
@@ -17,8 +17,9 @@
 
 import jetbrains.buildServer.BaseTestCase;
 import jetbrains.buildServer.TempFiles;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.Constants;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.LocalRepositoryUtil;
-import jetbrains.buildServer.buildTriggers.vcs.mercurial.Constants;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.Util;
 import jetbrains.buildServer.vcs.VcsException;
 import jetbrains.buildServer.vcs.VcsRoot;
 import jetbrains.buildServer.vcs.impl.VcsRootImpl;
@@ -26,8 +27,8 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Map;
-import java.util.HashMap;
 
 public class BaseCommandTestCase extends BaseTestCase {
   private String myRepository;
@@ -58,7 +59,7 @@
       vcsRootProps.put(Constants.REPOSITORY_PROP, repository.getAbsolutePath());
     }
 
-    vcsRootProps.put(Constants.HG_COMMAND_PATH_PROP, "mercurial-tests/testData/bin/hg.exe");
+    vcsRootProps.put(Constants.HG_COMMAND_PATH_PROP, Util.getHgPath());
     if (myUsername != null) {
       vcsRootProps.put(Constants.USERNAME, myUsername);
     }
--- a/mercurial-tests/src/testng.xml	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial-tests/src/testng.xml	Wed Dec 22 11:39:14 2010 +0300
@@ -7,6 +7,7 @@
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.command.PushCommandTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialVcsSupportTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.AgentSideCheckoutTest"/>
+      <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.SettingsTest"/>
     </classes>
   </test>
 </suite>
--- a/mercurial.ipr	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial.ipr	Wed Dec 22 11:39:14 2010 +0300
@@ -297,6 +297,9 @@
       <module fileurl="file://$PROJECT_DIR$/mercurial-tests/mercurial-tests.iml" filepath="$PROJECT_DIR$/mercurial-tests/mercurial-tests.iml" />
     </modules>
   </component>
+  <component name="ProjectResources">
+    <default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
+  </component>
   <component name="ProjectRootConfigurable.UI">
     <option name="proportions">
       <SplitterProportionsDataImpl />
@@ -352,7 +355,7 @@
     <option name="SHOW_FILE_HISTORY_AS_TREE" value="true" />
   </component>
   <component name="VcsDirectoryMappings">
-    <mapping directory="" vcs="Mercurial" />
+    <mapping directory="" vcs="hg4idea" />
   </component>
   <component name="WebServicesPlugin" addRequiredLibraries="true" />
   <component name="com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable" proportions="" version="1">
--- a/mercurial.properties	Thu Dec 02 14:43:27 2010 +0300
+++ b/mercurial.properties	Wed Dec 22 11:39:14 2010 +0300
@@ -1,5 +1,5 @@
 path.variable.ant_home=C\:/Tools/apache-ant-1.7.1
 path.variable.maven_repository=C\:/Documents and Settings/pavel.sher/.m2/repository
-path.variable.teamcitydistribution=C\:/TeamCity
+path.variable.teamcitydistribution=/home/nd/sandbox/TeamCity-Eluru
 path.variable.user_home_grails=C\:/Documents and Settings/pavel.sher/.grails
 path.variable.user_home_griffon=C\:/Documents and Settings/pavel.sher/.griffon
\ No newline at end of file