# HG changeset patch # User Dmitry Neverov # Date 1379414162 -14400 # Node ID 96af0d63f80a9fe219e33c3b8b5ccf48fb9c865c # Parent 2f6c4b61686aefcd70803832fcec6efac17fbf3b Unify HgRepoFactory on server and agent diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentRepoFactory.java --- 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, diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java --- 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 diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java --- 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); diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepoFactory.java --- /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; + +} diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RepoFactory.java --- 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(); diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentMirrorCleanerTest.java --- 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() {{ diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java --- 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() {{ diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSubreposTest.java --- 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() {{ diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialSupportBuilder.java --- 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 myExtensions = new ArrayList(); private HgVcsRootFactory myHgRootFactory; private RepoFactory myRepoFactory; + private ServerHgPathProvider myHgPathProvider; public static MercurialSupportBuilder mercurialSupport() { return new MercurialSupportBuilder(); @@ -33,15 +34,16 @@ EventDispatcher 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; + } } diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java --- 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(); diff -r 2f6c4b61686a -r 96af0d63f80a mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SubrepoChangesTest.java --- 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 {