changeset 644:96af0d63f80a

Unify HgRepoFactory on server and agent
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Tue, 17 Sep 2013 14:36:02 +0400
parents 2f6c4b61686a
children 4cf1ab3cd162
files mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentRepoFactory.java mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepoFactory.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RepoFactory.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleanerTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java
diffstat 11 files changed, 72 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentRepoFactory.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentRepoFactory.java	Tue Sep 17 14:36:02 2013 +0400
@@ -2,16 +2,25 @@
 
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandSettingsFactory;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
+import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
 
-public class AgentRepoFactory {
+public class AgentRepoFactory implements HgRepoFactory {
 
   private final CommandSettingsFactory myCommandSettingsFactory;
+  private final HgPathProvider myHgPathProvider;
 
-  public AgentRepoFactory(@NotNull CommandSettingsFactory commandSettingsFactory) {
+  public AgentRepoFactory(@NotNull CommandSettingsFactory commandSettingsFactory,
+                          @NotNull HgPathProvider hgPathProvider) {
     myCommandSettingsFactory = commandSettingsFactory;
+    myHgPathProvider = hgPathProvider;
+  }
+
+  public HgRepo createRepo(@NotNull HgVcsRoot root, @NotNull File workingDir) throws VcsException {
+    return new HgRepo(myCommandSettingsFactory, workingDir, myHgPathProvider.getHgPath(root), root.getAuthSettings());
   }
 
   public HgRepo create(@NotNull File workingDir,
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java	Tue Sep 17 14:36:02 2013 +0400
@@ -30,22 +30,19 @@
 public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules2 {
 
   private final AgentPluginConfig myConfig;
-  private final HgPathProvider myHgPathProvider;
   private final MirrorManager myMirrorManager;
   private final AgentRepoFactory myRepoFactory;
 
   public MercurialAgentSideVcsSupport(@NotNull AgentPluginConfig pluginConfig,
-                                      @NotNull HgPathProvider hgPathProvider,
                                       @NotNull MirrorManager mirrorManager,
                                       @NotNull AgentRepoFactory repoFactory) {
     myConfig = pluginConfig;
-    myHgPathProvider = hgPathProvider;
     myMirrorManager = mirrorManager;
     myRepoFactory = repoFactory;
   }
 
   public IncludeRuleUpdater getUpdater(@NotNull final VcsRoot vcsRoot, @NotNull final CheckoutRules checkoutRules, @NotNull final String toVersion, @NotNull final File checkoutDirectory, @NotNull final AgentRunningBuild build, boolean cleanCheckoutRequested) throws VcsException {
-    return new MercurialIncludeRuleUpdater(myConfig, myMirrorManager, myHgPathProvider, myRepoFactory, vcsRoot, toVersion, build);
+    return new MercurialIncludeRuleUpdater(myConfig, myMirrorManager, myRepoFactory, vcsRoot, toVersion, build);
   }
 
   @NotNull
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java	Tue Sep 17 14:36:02 2013 +0400
@@ -13,7 +13,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
 
@@ -24,12 +23,10 @@
  */
 public class MercurialIncludeRuleUpdater implements IncludeRuleUpdater {
 
-  private final AgentPluginConfig myConfig;
   private final MirrorManager myMirrorManager;
   private final AgentRepoFactory myRepoFactory;
   private final HgVcsRoot myRoot;
   private final AuthSettings myAuthSettings;
-  private final String myHgPath;
   private final String myToVersion;
   private final BuildProgressLogger myLogger;
   private final boolean myUseLocalMirrors;
@@ -38,22 +35,19 @@
 
   public MercurialIncludeRuleUpdater(@NotNull AgentPluginConfig pluginConfig,
                                      @NotNull MirrorManager mirrorManager,
-                                     @NotNull HgPathProvider hgPathProvider,
                                      @NotNull AgentRepoFactory repoFactory,
                                      @NotNull VcsRoot root,
                                      @NotNull String toVersion,
                                      @NotNull AgentRunningBuild build) {
-    myConfig = pluginConfig;
     myMirrorManager = mirrorManager;
     myRepoFactory = repoFactory;
     myRoot = new HgVcsRoot(root);
     myAuthSettings = myRoot.getAuthSettings();
-    myHgPath = hgPathProvider.getHgPath(myRoot);
     myToVersion = toVersion;
     myLogger = build.getBuildLogger();
-    myUseLocalMirrors = myConfig.isUseLocalMirrors(build);
-    myPullTimeout = myConfig.getPullTimeout(build);
-    myUseTraceback = myConfig.runWithTraceback(build);
+    myUseLocalMirrors = pluginConfig.isUseLocalMirrors(build);
+    myPullTimeout = pluginConfig.getPullTimeout(build);
+    myUseTraceback = pluginConfig.runWithTraceback(build);
   }
 
 
@@ -76,7 +70,7 @@
 
   private void updateLocalMirror(@NotNull String repositoryUrl, @NotNull String revision) throws VcsException, IOException {
     File mirrorDir = myMirrorManager.getMirrorDir(repositoryUrl);
-    HgRepo mirrorRepo = myRepoFactory.create(mirrorDir, myHgPath, myAuthSettings);
+    HgRepo mirrorRepo = myRepoFactory.createRepo(myRoot, mirrorDir);
     if (!mirrorRepo.isValidRepository()) {
       delete(mirrorDir);
       myLogger.message("Clone repository " + myAuthSettings.getRepositoryUrlWithHiddenPassword(repositoryUrl) + " into local mirror " + mirrorRepo.path());
@@ -105,7 +99,7 @@
 
   private void updateRepository(@NotNull File workingDir) throws VcsException, IOException {
     String repositoryUrl = getDefaultPullUrl(myRoot, myUseLocalMirrors);
-    HgRepo repo = myRepoFactory.create(workingDir, myHgPath, myAuthSettings);
+    HgRepo repo = myRepoFactory.createRepo(myRoot, workingDir);
     myLogger.message("Update repository " + workingDir.getAbsolutePath());
     if (repo.isEmpty()) {//can do clone only in empty dir
       myLogger.message("Start cloning from " + (myUseLocalMirrors ? "local mirror " : "") + myAuthSettings.getRepositoryUrlWithHiddenPassword(repositoryUrl));
@@ -140,7 +134,7 @@
 
 
   private void updateWorkingDir(@NotNull File workingDir, @NotNull String toVersion, @NotNull String repositoryUrl) throws VcsException, IOException {
-    HgRepo repo = myRepoFactory.create(workingDir, myHgPath, myAuthSettings);
+    HgRepo repo = myRepoFactory.createRepo(myRoot, workingDir);
     updateSubrepositories(repo, toVersion, repositoryUrl);
     doUpdateWorkingDir(repo, toVersion);
   }
@@ -161,7 +155,7 @@
         myLogger.message("The url of subrepoConfig was changed between revisions " + workingDirRevision + " and " + toVersion + " , delete the subrepoConfig");
         delete(subrepoConfigDir(repo, subrepoConfig));
       }
-      HgRepo subrepository = myRepoFactory.create(subrepoConfigDir(repo, subrepoConfig), myHgPath, myAuthSettings);
+      HgRepo subrepository = myRepoFactory.createRepo(myRoot, subrepoConfigDir(repo, subrepoConfig));
       String subrepoUrl;
       try {
         subrepoUrl = subrepoConfig.resolveUrl(parentRepositoryUrl);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepoFactory.java	Tue Sep 17 14:36:02 2013 +0400
@@ -0,0 +1,13 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
+import jetbrains.buildServer.vcs.VcsException;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+
+public interface HgRepoFactory {
+
+  HgRepo createRepo(@NotNull HgVcsRoot root, @NotNull File workingDir) throws VcsException;
+
+}
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RepoFactory.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RepoFactory.java	Tue Sep 17 14:36:02 2013 +0400
@@ -2,6 +2,7 @@
 
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings;
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandSettingsFactory;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
 import jetbrains.buildServer.util.FileUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
@@ -15,19 +16,23 @@
 /**
  * @author dmitry.neverov
  */
-public class RepoFactory {
+public class RepoFactory implements HgRepoFactory {
 
   protected final ServerPluginConfig myConfig;
   protected final CommandSettingsFactory myCommandSettingsFactory;
+  protected final HgPathProvider myHgPathProvider;
 
   protected final MercurialLogTemplate myLogTemplate = new MercurialLogTemplate("/buildServerResources/log.template", "hg.log.template");
   protected final MercurialLogTemplate myLogNoFilesTemplate = new MercurialLogTemplate("/buildServerResources/log.no.files.template", "hg.short.log.template");
   protected final MercurialLogTemplate myDagTemplate = new MercurialLogTemplate("/buildServerResources/dag.template", "hg.dag.template");
   protected final MercurialLogTemplate myFastLogTemplate = new MercurialLogTemplate("/buildServerResources/fastlog.template", "hg.fastlog.template");
 
-  public RepoFactory(@NotNull ServerPluginConfig config, @NotNull CommandSettingsFactory commandSettingsFactory) throws IOException {
+  public RepoFactory(@NotNull ServerPluginConfig config,
+                     @NotNull CommandSettingsFactory commandSettingsFactory,
+                     @NotNull HgPathProvider hgPathProvider) throws IOException {
     myConfig = config;
     myCommandSettingsFactory = commandSettingsFactory;
+    myHgPathProvider = hgPathProvider;
   }
 
   @NotNull
@@ -41,6 +46,10 @@
                     myFastLogTemplate.getTemplate());
   }
 
+  public HgRepo createRepo(@NotNull HgVcsRoot root, @NotNull File workingDir) throws VcsException {
+    return create(workingDir, myHgPathProvider.getHgPath(root), root.getAuthSettings());
+  }
+
   public void dispose() {
     myLogTemplate.dispose();
     myLogNoFilesTemplate.dispose();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleanerTest.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleanerTest.java	Tue Sep 17 14:36:02 2013 +0400
@@ -45,10 +45,9 @@
     }});
 
     AgentPluginConfigImpl pluginConfig = new AgentPluginConfigImpl(agentConfig);
-    AgentHgPathProvider hgPathProvider = new AgentHgPathProvider(agentConfig);
     myMirrorManager = new MirrorManagerImpl(pluginConfig);
-    AgentRepoFactory repoFactory = new AgentRepoFactory(new TestCommandSettingsFactory());
-    myVcsSupport = new MercurialAgentSideVcsSupport(pluginConfig, hgPathProvider, myMirrorManager, repoFactory);
+    AgentRepoFactory repoFactory = new AgentRepoFactory(new TestCommandSettingsFactory(), new AgentHgPathProvider(agentConfig));
+    myVcsSupport = new MercurialAgentSideVcsSupport(pluginConfig, myMirrorManager, repoFactory);
     myCleaner = new AgentMirrorCleaner(myMirrorManager);
     myLogger = myContext.mock(BuildProgressLogger.class);
     myContext.checking(new Expectations() {{
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java	Tue Sep 17 14:36:02 2013 +0400
@@ -74,9 +74,8 @@
 
     final AgentPluginConfigImpl pluginConfig = new AgentPluginConfigImpl(agentConfig);
     myVcsSupport = new MercurialAgentSideVcsSupport(pluginConfig,
-            new AgentHgPathProvider(agentConfig),
             new MirrorManagerImpl(pluginConfig),
-            new AgentRepoFactory(new TestCommandSettingsFactory()));
+            new AgentRepoFactory(new TestCommandSettingsFactory(), new AgentHgPathProvider(agentConfig)));
 
     myLogger = myContext.mock(BuildProgressLogger.class);
     myContext.checking(new Expectations() {{
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java	Tue Sep 17 14:36:02 2013 +0400
@@ -66,9 +66,8 @@
     final AgentPluginConfigImpl pluginConfig = new AgentPluginConfigImpl(agentConfig);
     myMirrorManager = new MirrorManagerImpl(pluginConfig);
     myVcsSupport = new MercurialAgentSideVcsSupport(pluginConfig,
-            new AgentHgPathProvider(agentConfig),
             myMirrorManager,
-            new AgentRepoFactory(new TestCommandSettingsFactory()));
+            new AgentRepoFactory(new TestCommandSettingsFactory(), new AgentHgPathProvider(agentConfig)));
 
     myLogger = myContext.mock(BuildProgressLogger.class);
     myContext.checking(new Expectations() {{
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java	Tue Sep 17 14:36:02 2013 +0400
@@ -21,6 +21,7 @@
   private List<MercurialServerExtension> myExtensions = new ArrayList<MercurialServerExtension>();
   private HgVcsRootFactory myHgRootFactory;
   private RepoFactory myRepoFactory;
+  private ServerHgPathProvider myHgPathProvider;
 
   public static MercurialSupportBuilder mercurialSupport() {
     return new MercurialSupportBuilder();
@@ -33,15 +34,16 @@
     EventDispatcher<ServerListener> dispatcher = EventDispatcher.create(ServerListener.class);
     myHgRootFactory = new HgVcsRootFactory(myConfig);
     MirrorManagerImpl mirrorManager = new MirrorManagerImpl(myConfig);
-    ServerHgPathProvider hgPathProvider = new ServerHgPathProvider(myConfig);
-    RepoFactory repoFactory = myRepoFactory != null ? myRepoFactory : new RepoFactory(myConfig, new TestCommandSettingsFactory());
-    HgTestConnectionSupport testConnection = new HgTestConnectionSupport(myHgRootFactory, repoFactory, mirrorManager, hgPathProvider);
+    myHgPathProvider = new ServerHgPathProvider(myConfig);
+    if (myRepoFactory == null)
+      myRepoFactory = new RepoFactory(myConfig, new TestCommandSettingsFactory(), myHgPathProvider);
+    HgTestConnectionSupport testConnection = new HgTestConnectionSupport(myHgRootFactory, myRepoFactory, mirrorManager, myHgPathProvider);
     final ResetCacheRegister resetCacheManager = myContext.mock(ResetCacheRegister.class);
     myContext.checking(new Expectations() {{
       allowing(resetCacheManager).registerHandler(with(any(ResetCacheHandler.class)));
     }});
-    MercurialVcsSupport vcs = new MercurialVcsSupport(dispatcher, resetCacheManager, myConfig, hgPathProvider,
-            repoFactory, mirrorManager, myHgRootFactory, testConnection, new SubrepoCheckoutRulesProviderImpl());
+    MercurialVcsSupport vcs = new MercurialVcsSupport(dispatcher, resetCacheManager, myConfig, myHgPathProvider,
+            myRepoFactory, mirrorManager, myHgRootFactory, testConnection, new SubrepoCheckoutRulesProviderImpl());
     vcs.addExtensions(myExtensions);
     return vcs;
   }
@@ -60,4 +62,12 @@
   public HgVcsRootFactory getHgRootFactory() {
     return myHgRootFactory;
   }
+
+  public HgRepoFactory getHgRepoFactory() {
+    return myRepoFactory;
+  }
+
+  public ServerHgPathProvider getHgPathProvider() {
+    return myHgPathProvider;
+  }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue Sep 17 14:36:02 2013 +0400
@@ -50,6 +50,7 @@
   private MercurialVcsSupport myVcs;
   private String myRep2Path = new File("mercurial-tests/testData/rep2").getAbsolutePath();
   private ServerPluginConfig myPluginConfig;
+  private HgPathProvider myHgPathProvider;
 
   @BeforeMethod
   protected void setUp() throws Exception {
@@ -57,7 +58,9 @@
     myPluginConfig = new ServerPluginConfigBuilder()
             .cachesDir(myTempFiles.createTempDir())
             .build();
-    myVcs = mercurialSupport().withConfig(myPluginConfig).build();
+    MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(myPluginConfig);
+    myVcs = mercurialBuilder.build();
+    myHgPathProvider = mercurialBuilder.getHgPathProvider();
   }
 
   protected String getTestDataPath() {
@@ -548,7 +551,7 @@
     if (!SystemInfo.isUnix)
       return;
 
-    RepoFactory repoFactory = new RepoFactory(myPluginConfig, new TestCommandSettingsFactory());
+    RepoFactory repoFactory = new RepoFactory(myPluginConfig, new TestCommandSettingsFactory(), myHgPathProvider);
 
     //create a file on the server
     File dirOnTheServer = myTempFiles.createTempDir();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java	Mon Sep 16 21:51:32 2013 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java	Tue Sep 17 14:36:02 2013 +0400
@@ -32,6 +32,7 @@
   private File myRemoteRepo2;
   private File myRemoteRepo3;
   private File myRepoNoSubs;
+  private HgPathProvider myHgPathProvider;
 
   @BeforeMethod
   public void setUp() throws Exception {
@@ -49,7 +50,9 @@
     copyRepository(new File("mercurial-tests/testData/subrepos/r2"), myRemoteRepo2);
     copyRepository(new File("mercurial-tests/testData/subrepos/r3"), myRemoteRepo3);
     copyRepository(new File("mercurial-tests/testData/rep1"), myRepoNoSubs);
-    myVcs = mercurialSupport().withConfig(pluginConfig).build();
+    MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(pluginConfig);
+    myVcs = mercurialBuilder.build();
+    myHgPathProvider = mercurialBuilder.getHgPathProvider();
   }
 
 
@@ -211,7 +214,7 @@
             .build();
 
     final AtomicInteger catCallCounter = new AtomicInteger(0);
-    RepoFactory repoFactory = new RepoFactory(pluginConfig, new TestCommandSettingsFactory()) {
+    RepoFactory repoFactory = new RepoFactory(pluginConfig, new TestCommandSettingsFactory(), myHgPathProvider) {
       @NotNull
       @Override
       public ServerHgRepo create(@NotNull File workingDir, @NotNull String hgPath, @NotNull AuthSettings authSettings) throws VcsException {