changeset 371:24d926f22e85

TW-16045 allow specify username for tags
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 08 Feb 2012 16:45:14 +0400
parents 64cb622b3e89
children 2869f49b9211
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialCommandLine.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/TagCommand.java mercurial-server/resources/buildServerResources/mercurialSettings.jsp mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java
diffstat 8 files changed, 61 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java	Wed Feb 08 16:45:14 2012 +0400
@@ -27,4 +27,5 @@
   String USERNAME = "username";
   String PASSWORD = VcsRoot.SECURE_PROPERTY_PREFIX + "password";
   String UNCOMPRESSED_TRANSFER = "uncompressedTransfer";
+  String USER_FOR_TAG = "tagUsername";
 }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialCommandLine.java	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/MercurialCommandLine.java	Wed Feb 08 16:45:14 2012 +0400
@@ -4,12 +4,17 @@
 import jetbrains.buildServer.util.StringUtil;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.Collections;
 import java.util.Set;
 
 public class MercurialCommandLine extends GeneralCommandLine {
 
   private final Set<String> myPrivateData;
 
+  public MercurialCommandLine() {
+    this(Collections.<String>emptySet());
+  }
+
   public MercurialCommandLine(@NotNull Set<String> privateData) {
     myPrivateData = privateData;
   }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/Settings.java	Wed Feb 08 16:45:14 2012 +0400
@@ -45,6 +45,7 @@
   private boolean myUncompressedTransfer = false;
   private static final String DEFAULT_BRANCH_NAME = "default";
   private String myCustomClonePath;
+  private final String myUserForTag;
 
   public Settings(@NotNull final HgPathProvider hgPathProvider, @NotNull final VcsRoot vcsRoot) {
     myHgPathProvider = hgPathProvider;
@@ -55,6 +56,7 @@
     myUsername = vcsRoot.getProperty(Constants.USERNAME);
     myPassword = vcsRoot.getProperty(Constants.PASSWORD);
     myUncompressedTransfer = "true".equals(vcsRoot.getProperty(Constants.UNCOMPRESSED_TRANSFER));
+    myUserForTag = vcsRoot.getProperty(Constants.USER_FOR_TAG);
   }
 
   public String getCustomClonePath() {
@@ -109,6 +111,11 @@
     return myPassword;
   }
 
+  @Nullable
+  public String getUserForTag() {
+    return myUserForTag;
+  }
+
   private final static Set<String> AUTH_PROTOS = new HashSet<String>();
   static {
     AUTH_PROTOS.add("http");
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/TagCommand.java	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/TagCommand.java	Wed Feb 08 16:45:14 2012 +0400
@@ -24,6 +24,7 @@
 public class TagCommand extends VcsRootCommand {
   private String myTag;
   private String myRevId;
+  private String myUsername;
 
   public TagCommand(@NotNull Settings settings, @NotNull File workingDir) {
     super(settings, workingDir);
@@ -37,12 +38,22 @@
     myRevId = revId;
   }
 
+  public void setUser(@NotNull final String username) {
+    myUsername = username;
+  }
+
   public void execute() throws VcsException {
     GeneralCommandLine cli = createCommandLine();
     cli.addParameter("tag");
+    setUser(cli);
     cli.addParameter("-r");
     cli.addParameter(myRevId);
     cli.addParameter(myTag);
     runCommand(cli);
   }
+
+  private void setUser(GeneralCommandLine cli) {
+    if (myUsername != null)
+      cli.addParameters("--user", myUsername);
+  }
 }
--- a/mercurial-server/resources/buildServerResources/mercurialSettings.jsp	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-server/resources/buildServerResources/mercurialSettings.jsp	Wed Feb 08 16:45:14 2012 +0400
@@ -32,6 +32,10 @@
     </td>
   </tr>
   <tr>
+    <th><label for="tagUsername">Username for tags: </label></th>
+    <td><props:textProperty name="tagUsername"/></td>
+  </tr>
+  <tr>
     <th><label for="uncompressedTransfer">Use uncompressed transfer: </label></th>
     <td><props:checkboxProperty name="uncompressedTransfer"/>
       <div class="smallNote" style="margin: 0;">Uncompressed transfer is faster for repositories in the LAN.</div>
@@ -40,9 +44,6 @@
   </l:settingsGroup>
   <l:settingsGroup title="Authorization settings">
   <tr>
-    <td colspan="2">Authorization settings can be required 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>
@@ -51,5 +52,5 @@
     <td><props:passwordProperty name="secure:password"/></td>
   </tr>
   </l:settingsGroup>
-  
+
 </table>
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Wed Feb 08 16:45:14 2012 +0400
@@ -716,6 +716,9 @@
       TagCommand tc = new TagCommand(settings, workingDir);
       tc.setRevId(new ChangeSet(version).getId());
       tc.setTag(fixedTagname);
+      String user = settings.getUserForTag();
+      if (user != null)
+        tc.setUser(user);
       tc.execute();
 
       PushCommand pc = new PushCommand(settings, workingDir);
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Wed Feb 08 16:45:14 2012 +0400
@@ -36,6 +36,7 @@
 
 import static com.intellij.openapi.util.io.FileUtil.copyDir;
 import static com.intellij.openapi.util.io.FileUtil.moveDirWithContent;
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot;
 
 @Test
 public class MercurialVcsSupportTest extends BaseMercurialTestCase {
@@ -259,6 +260,21 @@
   }
 
 
+  public void test_tag_with_specified_username() throws IOException, VcsException {
+    final String customUserForTag = "John Doe <john@some.org>";
+    File repository = LocalRepositoryUtil.prepareRepository(simpleRepo());
+    VcsRoot root = vcsRoot().withUrl(repository.getAbsolutePath()).withUserForTag(customUserForTag).build();
+    cleanRepositoryAfterTest(simpleRepo());
+
+    myVcs.label("tag_by_specified_user", "10:9c6a6b4aede0", root, CheckoutRules.DEFAULT);
+
+    String currentVersion = myVcs.getCurrentVersion(root);
+    List<ModificationData> changes = myVcs.collectChanges(root, "10:9c6a6b4aede0", currentVersion, CheckoutRules.DEFAULT);
+    assertEquals(changes.size(), 1);
+    assertEquals(changes.get(0).getUserName(), customUserForTag);
+  }
+
+
   public void labeling_should_not_populate_files_in_local_mirror() throws Exception {
     VcsRootImpl root = createVcsRoot(simpleRepo());
     cleanRepositoryAfterTest(simpleRepo());
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java	Wed Feb 08 11:32:49 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java	Wed Feb 08 16:45:14 2012 +0400
@@ -19,6 +19,11 @@
   private String myBranch;
   private long myRootId = 1L;
   private String myHgPath;
+  private String myUserForTag;
+
+  public static VcsRootBuilder vcsRoot() {
+    return new VcsRootBuilder();
+  }
 
   public VcsRootImpl build() throws IOException {
     VcsRootImpl vcsRoot = new VcsRootImpl(myRootId, Constants.VCS_NAME);
@@ -27,6 +32,7 @@
     vcsRoot.addProperty(Constants.USERNAME, myUsername);
     vcsRoot.addProperty(Constants.PASSWORD, myPassword);
     vcsRoot.addProperty(Constants.BRANCH_NAME_PROP, myBranch);
+    vcsRoot.addProperty(Constants.USER_FOR_TAG, myUserForTag);
     return vcsRoot;
   }
 
@@ -42,6 +48,7 @@
       allowing(root).getProperty(with(Constants.USERNAME)); will(returnValue(myUsername));
       allowing(root).getProperty(with(Constants.PASSWORD)); will(returnValue(myPassword));
       allowing(root).getProperty(with(Constants.UNCOMPRESSED_TRANSFER)); will(returnValue(null));
+      allowing(root).getProperty(with(Constants.USER_FOR_TAG)); will(returnValue(myUserForTag));
     }});
     return root;
   }
@@ -81,4 +88,10 @@
     myHgPath = hgPath;
     return this;
   }
+
+
+  public VcsRootBuilder withUserForTag(String username) {
+    myUserForTag = username;
+    return this;
+  }
 }