Mercurial > hg > mercurial
changeset 934:3db6c332fc3b
TW-43138 Implement auto checkout
Agent-side checkout it used when hg client is found on agent and checkout rules are supported
author | Dmitry.Treskunov@UNIT-412.Labs.IntelliJ.Net |
---|---|
date | Tue, 10 Nov 2015 21:27:07 +0300 |
parents | 5c28db706378 |
children | eb3e0285ae52 12ea02234103 |
files | mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java |
diffstat | 3 files changed, 42 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Wed Sep 16 19:56:28 2015 +0200 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Tue Nov 10 21:27:07 2015 +0300 @@ -16,17 +16,12 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.agent.AgentRunningBuild; -import jetbrains.buildServer.agent.vcs.AgentVcsSupport; -import jetbrains.buildServer.agent.vcs.IncludeRuleUpdater; -import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules2; -import jetbrains.buildServer.agent.vcs.UpdatePolicy; +import jetbrains.buildServer.agent.vcs.*; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.CheckoutInfo; import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.MercurialExtension; import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.MercurialExtensionManager; -import jetbrains.buildServer.vcs.CheckoutRules; -import jetbrains.buildServer.vcs.VcsException; -import jetbrains.buildServer.vcs.VcsRoot; +import jetbrains.buildServer.vcs.*; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -59,6 +54,25 @@ return updater; } + @NotNull + @Override + public AgentCheckoutAbility canCheckout(@NotNull VcsRootEntry vcsRoot, @NotNull AgentRunningBuild build) { + CheckoutInfo info = new CheckoutInfo(myRepoFactory, new HgVcsRoot(vcsRoot.getVcsRoot()), vcsRoot.getCheckoutRules()); + try { + info.getTempDirRepo().version().call(); + } catch (VcsException e) { + return AgentCheckoutAbility.noVcsClientOnAgent(e.getMessage()); + } + + try { + for (IncludeRule rule : vcsRoot.getCheckoutRules().getRootIncludeRules()) { + MercurialIncludeRuleUpdater.checkRuleIsValid(rule); + } + return AgentCheckoutAbility.canCheckout(); + } catch (VcsException e) { + return AgentCheckoutAbility.canNotCheckout(e.getMessage()); + } + } private void registerExtensions(@NotNull VcsRoot root, @NotNull CheckoutRules checkoutRules, @NotNull MercurialIncludeRuleUpdater updater) { CheckoutInfo info = new CheckoutInfo(myRepoFactory, new HgVcsRoot(root), checkoutRules);
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Wed Sep 16 19:56:28 2015 +0200 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Tue Nov 10 21:27:07 2015 +0300 @@ -269,7 +269,7 @@ } - private void checkRuleIsValid(IncludeRule includeRule) throws VcsException { + public static void checkRuleIsValid(IncludeRule includeRule) throws VcsException { if (includeRule.getTo() != null && includeRule.getTo().length() > 0) { if (!".".equals(includeRule.getFrom()) && includeRule.getFrom().length() != 0) throw new VcsException("Invalid include rule: " + includeRule.toString() + ", Mercurial plugin supports mapping of the form: +:.=>dir only.");
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Wed Sep 16 19:56:28 2015 +0200 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Tue Nov 10 21:27:07 2015 +0300 @@ -19,6 +19,7 @@ import jetbrains.buildServer.agent.BuildAgentConfiguration; import jetbrains.buildServer.agent.BuildProgressLogger; import jetbrains.buildServer.agent.FlowLogger; +import jetbrains.buildServer.agent.vcs.AgentCheckoutAbility; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandSettingsForRootImpl; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandlineViaFileWrapperWeaver; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ExtensionsWeaver; @@ -26,10 +27,7 @@ import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.MercurialExtensionManager; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.TestFor; -import jetbrains.buildServer.vcs.CheckoutRules; -import jetbrains.buildServer.vcs.IncludeRule; -import jetbrains.buildServer.vcs.VcsException; -import jetbrains.buildServer.vcs.VcsRoot; +import jetbrains.buildServer.vcs.*; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import org.jetbrains.annotations.NotNull; import org.jmock.Expectations; @@ -45,6 +43,8 @@ import java.util.concurrent.*; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.text.StringContains.containsString; /** * @author Pavel.Sher @@ -103,6 +103,21 @@ testUpdate(root, "b06a290a363b", "cleanPatch1/after", new IncludeRule(".", ".", null)); } + public void auto_checkout_when_hg_client_not_found() throws Exception { + VcsRootImpl root = new VcsRootBuilder().withUrl(copyRepository(myTempFiles, simpleRepo()).getAbsolutePath()).withHgPath("invalid_hg_path").build(); + + AgentCheckoutAbility agentCheckoutAbility = myVcsSupport.canCheckout(new VcsRootEntry(root, CheckoutRules.DEFAULT), myContext.mock(AgentRunningBuild.class, "build" + myBuildCounter++)); + + assertThat(agentCheckoutAbility.getCanNotCheckoutReason(), containsString(AgentCheckoutAbility.NO_VCS_CLIENT)); + } + + public void auto_checkout_when_unsupported_include_rule_is_used() throws Exception { + VcsRootImpl root = createVcsRoot(simpleRepo()); + + AgentCheckoutAbility agentCheckoutAbility = myVcsSupport.canCheckout(new VcsRootEntry(root, new CheckoutRules("+:subdir=>subdir2")), myContext.mock(AgentRunningBuild.class, "build" + myBuildCounter++)); + + assertThat(agentCheckoutAbility.getCanNotCheckoutReason(), containsString("Invalid include rule: subdir=>subdir2")); + } public void checkout_on_agent() throws IOException, VcsException { testUpdate(createVcsRoot(simpleRepo()), "4:b06a290a363b", "cleanPatch1/after", new IncludeRule(".", ".", null)); @@ -154,6 +169,7 @@ allowing(build).getBuildLogger(); will(returnValue(myLogger)); allowing(build).getSharedConfigParameters(); will(returnValue(sharedConfigParameters)); }}); + assertNull(myVcsSupport.canCheckout(new VcsRootEntry(vcsRoot, new CheckoutRules("")), build).getCanNotCheckoutReason()); myVcsSupport.getUpdater(vcsRoot, new CheckoutRules(""), version, myWorkDir, build, false).process(includeRule, actualWorkDir); File hgDir = new File(actualWorkDir, ".hg");