# HG changeset patch # User Pavel.Sher # Date 1248858774 -14400 # Node ID 8a9c3aa7e11567e0772075321655a8c6146fea55 # Parent 4c15e7de1f9d1304cf5e719754cf308fcc6363a6 support include rules of the form .=> for checkout on agent diff -r 4c15e7de1f9d -r 8a9c3aa7e115 mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java --- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Thu Jul 23 17:08:43 2009 +0400 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Wed Jul 29 13:12:54 2009 +0400 @@ -30,11 +30,14 @@ public class MercurialAgentSideVcsSupport implements CheckoutOnAgentVcsSupport { public void updateSources(@NotNull final BuildProgressLogger logger, @NotNull final File workingDir, @NotNull final VcsRoot vcsRoot, @NotNull final String version, final IncludeRule includeRule) throws VcsException { if (includeRule.getTo() != null && includeRule.getTo().length() > 0) { - throw new VcsException("Include rule with mapping is not supported: " + includeRule.toString()); + 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."); + } } - Settings settings = new Settings(workingDir, vcsRoot); - settings.setWorkingDir(workingDir); + File actualWorkingDir = getWorkingDir(workingDir, includeRule); + Settings settings = new Settings(actualWorkingDir, vcsRoot); + settings.setWorkingDir(actualWorkingDir); if (settings.hasCopyOfRepository()) { // execute pull command logger.message("Repository in working directory found, start pulling changes"); @@ -45,21 +48,26 @@ // execute clone command logger.message("No repository in working directory found, start cloning repository to temporary folder"); File parentDir = cloneRepository(settings); - logger.message("Repository successfly cloned to: " + parentDir.getAbsolutePath()); - logger.message("Moving repository to working directory: " + workingDir.getAbsolutePath()); - if (!moveDir(parentDir, workingDir)) { - File hgDir = new File(workingDir, ".hg"); + logger.message("Repository successfully cloned to: " + parentDir.getAbsolutePath()); + logger.message("Moving repository to working directory: " + actualWorkingDir.getAbsolutePath()); + if (!moveDir(parentDir, actualWorkingDir)) { + File hgDir = new File(actualWorkingDir, ".hg"); if (hgDir.isDirectory()) { FileUtil.delete(hgDir); } - throw new VcsException("Failed to move directory content: " + parentDir.getAbsolutePath() + " to: " + workingDir.getAbsolutePath()); + throw new VcsException("Failed to move directory content: " + parentDir.getAbsolutePath() + " to: " + actualWorkingDir.getAbsolutePath()); } - logger.message("Repository successfully moved to working directory: " + workingDir.getAbsolutePath()); + logger.message("Repository successfully moved to working directory: " + actualWorkingDir.getAbsolutePath()); } updateWorkingDir(settings, version, logger); } + private File getWorkingDir(final File workingDir, final IncludeRule includeRule) { + if (includeRule.getTo().length() == 0) return workingDir; + return new File(workingDir, includeRule.getTo()).getAbsoluteFile(); + } + private void updateWorkingDir(final Settings settings, final String version, final BuildProgressLogger logger) throws VcsException { logger.message("Updating working directory from the local repository copy"); UpdateCommand uc = new UpdateCommand(settings); diff -r 4c15e7de1f9d -r 8a9c3aa7e115 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Thu Jul 23 17:08:43 2009 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Wed Jul 29 13:12:54 2009 +0400 @@ -34,53 +34,59 @@ } public void checkout_on_agent() throws IOException, VcsException { - VcsRoot vcsRoot = createVcsRoot(); - myVcsSupport.updateSources((BuildProgressLogger) myProgressLoggerMock.proxy(), myWorkDir, vcsRoot, "4:b06a290a363b", new IncludeRule(".", ".", null)); - File hgDir = new File(myWorkDir, ".hg"); + testUpdate(createVcsRoot(), "4:b06a290a363b", "cleanPatch1/after", new IncludeRule(".", ".", null)); + } + + public void checkout_on_agent_include_rule_with_mapping() throws IOException, VcsException { + testUpdate(createVcsRoot(), "4:b06a290a363b", "cleanPatch1/after", new IncludeRule("+:.", "subdir", null)); + } + + private void testUpdate(final VcsRoot vcsRoot, String version, String expected, final IncludeRule includeRule) throws VcsException, IOException { + File workDir = doUpdate(vcsRoot, version, includeRule); + + checkWorkingDir(expected, workDir); + } + + private void checkWorkingDir(final String expected, final File workDir) throws IOException { + FileUtil.delete(new File(workDir, ".hg")); + checkDirectoriesAreEqual(new File(getTestDataPath(), expected), workDir); + } + + private File doUpdate(final VcsRoot vcsRoot, final String version, final IncludeRule includeRule) throws VcsException { + myVcsSupport.updateSources((BuildProgressLogger) myProgressLoggerMock.proxy(), myWorkDir, vcsRoot, version, includeRule); + + File actualWorkDir = new File(myWorkDir, includeRule.getTo()); + File hgDir = new File(actualWorkDir, ".hg"); assertTrue(hgDir.isDirectory()); - - FileUtil.delete(hgDir); - - checkDirectoriesAreEqual(new File(getTestDataPath(), "cleanPatch1/after"), myWorkDir); + return actualWorkDir; } public void checkout_on_agent_from_branch() throws IOException, VcsException { - VcsRoot vcsRoot = createVcsRoot("test_branch"); - myVcsSupport.updateSources((BuildProgressLogger) myProgressLoggerMock.proxy(), myWorkDir, vcsRoot, "7:376dcf05cd2a", new IncludeRule(".", ".", null)); - File hgDir = new File(myWorkDir, ".hg"); - assertTrue(hgDir.isDirectory()); - - FileUtil.delete(hgDir); - - checkDirectoriesAreEqual(new File(getTestDataPath(), "patch3/after"), myWorkDir); + testUpdate(createVcsRoot("test_branch"), "7:376dcf05cd2a", "patch3/after", new IncludeRule(".", ".", null)); } public void update_on_agent() throws IOException, VcsException { - BuildProgressLogger logger = (BuildProgressLogger) myProgressLoggerMock.proxy(); - VcsRoot vcsRoot = createVcsRoot(); - myVcsSupport.updateSources(logger, myWorkDir, vcsRoot, "3:9522278aa38d", new IncludeRule(".", ".", null)); - File hgDir = new File(myWorkDir, ".hg"); - assertTrue(hgDir.isDirectory()); + doUpdate(vcsRoot, "3:9522278aa38d", new IncludeRule(".", ".", null)); + File workDir = doUpdate(vcsRoot, "4:b06a290a363b", new IncludeRule(".", ".", null)); + + checkWorkingDir("patch1/after", workDir); + } - myVcsSupport.updateSources(logger, myWorkDir, vcsRoot, "4:b06a290a363b", new IncludeRule(".", ".", null)); - FileUtil.delete(hgDir); + public void update_on_agent_with_include_rule() throws IOException, VcsException { + VcsRoot vcsRoot = createVcsRoot(); + doUpdate(vcsRoot, "3:9522278aa38d", new IncludeRule(".", "subdir", null)); + File workDir = doUpdate(vcsRoot, "4:b06a290a363b", new IncludeRule(".", "subdir", null)); - checkDirectoriesAreEqual(new File(getTestDataPath(), "patch1/after"), myWorkDir); + checkWorkingDir("patch1/after", workDir); } public void update_on_agent_from_branch() throws IOException, VcsException { - BuildProgressLogger logger = (BuildProgressLogger) myProgressLoggerMock.proxy(); + VcsRoot vcsRoot = createVcsRoot("test_branch"); + doUpdate(vcsRoot, "7:376dcf05cd2a", new IncludeRule(".", ".", null)); + File workDir = doUpdate(vcsRoot, "8:04c3ae4c6312", new IncludeRule(".", ".", null)); - VcsRoot vcsRoot = createVcsRoot("test_branch"); - myVcsSupport.updateSources(logger, myWorkDir, vcsRoot, "7:376dcf05cd2a", new IncludeRule(".", ".", null)); - File hgDir = new File(myWorkDir, ".hg"); - assertTrue(hgDir.isDirectory()); - - myVcsSupport.updateSources(logger, myWorkDir, vcsRoot, "8:04c3ae4c6312", new IncludeRule(".", ".", null)); - FileUtil.delete(hgDir); - - checkDirectoriesAreEqual(new File(getTestDataPath(), "patch4/after"), myWorkDir); + checkWorkingDir("patch4/after", workDir); } protected String getTestDataPath() {