changeset 332:d0edd172943f Eluru-6.5.x

TW-18835: provide URLStreamProtocolHandler in order to parse ssh URLs correctly
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 03 Nov 2011 10:28:00 +0300
parents ef091b782acc
children 01648f900892
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java
diffstat 2 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java	Fri Oct 28 17:55:04 2011 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java	Thu Nov 03 10:28:00 2011 +0300
@@ -24,10 +24,8 @@
 import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
+import java.io.IOException;
+import java.net.*;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -128,7 +126,7 @@
 
   private boolean containsCredentials(final String repository) {
     try {
-      URL url = new URL(repository);
+      URL url = new URL(null, repository, new FakeStreamHandler());
       String userInfo = url.getUserInfo();
       return userInfo != null && userInfo.contains(":");
     } catch (MalformedURLException e) {
@@ -139,7 +137,7 @@
   private String createURLWithCredentials(final String originalUrl) throws MalformedURLException {
     String userInfo = createUserInfo();
     if (!"".equals(userInfo)) {
-      URL url = new URL(originalUrl);
+      URL url = new URL(null, originalUrl, new FakeStreamHandler());
       return url.getProtocol() + "://"
               + userInfo + "@"
               + url.getHost()
@@ -208,4 +206,11 @@
     // need better way to check that repository copy is ok
     return dir.isDirectory() && new File(dir, ".hg").isDirectory();
   }
+
+  private class FakeStreamHandler extends URLStreamHandler {
+     @Override
+     protected URLConnection openConnection(URL u) throws IOException {
+       throw new UnsupportedOperationException();
+     }
+  }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java	Fri Oct 28 17:55:04 2011 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java	Thu Nov 03 10:28:00 2011 +0300
@@ -114,6 +114,13 @@
 		assertEquals("http://user:m%26n@some.org/path", settings.getRepositoryUrl());
   }
 
+  //TW-18835
+  public void test_ssh() {
+    VcsRootImpl vcsRoot = createVcsRoot("ssh://ourserver.com/mercurialrepo/", "user", "pwd");
+    Settings settings = new Settings(vcsRoot);
+    assertEquals("ssh://user:pwd@ourserver.com/mercurialrepo/", settings.getRepositoryUrl());
+  }
+
   private VcsRootImpl createVcsRoot(String url) {
     return createVcsRoot(url, "user", "pwd");
   }