changeset 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
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java mercurial-server/resources/buildServerResources/mercurialSettings.jsp
diffstat 3 files changed, 52 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Fri Sep 05 01:15:29 2008 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Sat Sep 06 17:46:28 2008 +0400
@@ -15,9 +15,12 @@
  */
 package jetbrains.buildServer.buildTriggers.vcs.mercurial;
 
+import jetbrains.buildServer.vcs.VcsRoot;
+
 public interface Constants {
   String VCS_NAME = "mercurial";
   String REPOSITORY_PROP = "repositoryPath";
   String HG_COMMAND_PATH_PROP = "hgCommandPath";
-  String PUSH_URL = "pushUrl";
+  String USERNAME = "username";
+  String PASSWORD = VcsRoot.SECURE_PROPERTY_PREFIX + "password";
 }
--- 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) {
--- a/mercurial-server/resources/buildServerResources/mercurialSettings.jsp	Fri Sep 05 01:15:29 2008 +0400
+++ b/mercurial-server/resources/buildServerResources/mercurialSettings.jsp	Sat Sep 06 17:46:28 2008 +0400
@@ -3,7 +3,7 @@
 <jsp:useBean id="propertiesBean" scope="request" type="jetbrains.buildServer.controllers.BasePropertiesBean"/>
 <table class="runnerFormTable">
 
-  <l:settingsGroup title="Mercurial Settings">
+  <l:settingsGroup title="General Settings">
   <tr>
     <th><label for="hgCommandPath">HG command path: <l:star/></label></th>
     <td><props:textProperty name="hgCommandPath" className="longField" />
@@ -15,5 +15,18 @@
       <span class="error" id="error_repositoryPath"></span></td>
   </tr>
   </l:settingsGroup>
+  <l:settingsGroup title="Authorization settings">
+  <tr>
+    <td colspan="2">You may require to provide authorization settings if you need to tag / label sources in the remote repository.</td>
+  </tr>
+  <tr>
+    <th><label for="username">User name:</label></th>
+    <td><props:textProperty name="username"/></td>
+  </tr>
+  <tr>
+    <th><label for="secure:password">Password:</label></th>
+    <td><props:passwordProperty name="secure:password"/></td>
+  </tr>
+  </l:settingsGroup>
   
 </table>