Mercurial > hg > mercurial
diff mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java @ 45:4059fcc5473e
ask for credentials on mercurial settings page
author | Pavel.Sher |
---|---|
date | Sat, 06 Sep 2008 17:46:28 +0400 |
parents | 1490e2981799 |
children | 13d5f0f56e70 |
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Fri Sep 05 01:15:29 2008 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java Sat Sep 06 17:46:28 2008 +0400 @@ -17,13 +17,15 @@ import jetbrains.buildServer.buildTriggers.vcs.mercurial.Constants; import jetbrains.buildServer.buildTriggers.vcs.mercurial.PathUtil; -import jetbrains.buildServer.vcs.VcsRoot; +import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.Hash; -import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.StringUtil; +import jetbrains.buildServer.vcs.VcsRoot; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.util.Set; +import java.util.HashSet; /** * Represents Mercurial repository settings @@ -33,13 +35,16 @@ private String myHgCommandPath; private File myWorkingDir; private File myWorkFolderParentDir; - private String myPushUrl; + private String myUsername; + private String myPassword; public Settings(@NotNull File workFolderParentDir, @NotNull VcsRoot vcsRoot) { myWorkFolderParentDir = workFolderParentDir; setRepository(vcsRoot.getProperty(Constants.REPOSITORY_PROP)); setHgCommandPath(vcsRoot.getProperty(Constants.HG_COMMAND_PATH_PROP)); - myPushUrl = vcsRoot.getProperty(Constants.PUSH_URL); + + myUsername = vcsRoot.getProperty(Constants.USERNAME); + myPassword = vcsRoot.getProperty(Constants.PASSWORD); } public Settings() { @@ -67,12 +72,34 @@ return myHgCommandPath; } + private final static Set<String> AUTH_PROTOS = new HashSet<String>(); + static { + AUTH_PROTOS.add("http://"); + AUTH_PROTOS.add("https://"); + AUTH_PROTOS.add("ssh://"); + } + /** - * Returns URL to use for push command if it was specified or repository path otherwise - * @return URL to use for push command if it was specified or repository path otherwise + * Returns URL to use for push command + * @return URL to use for push command */ public String getPushUrl() { - return StringUtil.isEmpty(myPushUrl) ? getRepository() : myPushUrl; + String cre = ""; + if (!StringUtil.isEmpty(myUsername)) { + cre += myUsername; + if (!StringUtil.isEmpty(myPassword)) { + cre += ":" + myPassword; + } + cre += "@"; + } + + for (String proto: AUTH_PROTOS) { + if (myRepository.startsWith(proto)) { + return proto + cre + myRepository.substring(proto.length()); + } + } + + return myRepository; } public void setHgCommandPath(@NotNull final String hgCommandPath) {