Mercurial > hg > mercurial
changeset 331:e5b15dc36e63
TW-18835: provide URLStreamProtocolHandler in order to parse ssh URLs correctly
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Thu, 03 Nov 2011 10:06:29 +0300 |
parents | dd55596a5753 |
children | 692d253c78cf |
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 19:08:33 2011 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Thu Nov 03 10:06:29 2011 +0300 @@ -25,10 +25,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; @@ -138,7 +136,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) { @@ -149,7 +147,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() @@ -218,4 +216,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 19:08:33 2011 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java Thu Nov 03 10:06:29 2011 +0300 @@ -116,6 +116,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 = createSettings(vcsRoot); + assertEquals("ssh://user:pwd@ourserver.com/mercurialrepo/", settings.getRepositoryUrl()); + } + private VcsRootImpl createVcsRoot(String url) { return createVcsRoot(url, "user", "pwd"); }