Mercurial > hg > mercurial
changeset 34:0052d368c90c
initial working version of agent side checkout + some tests
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-agent/src/META-INF/build-agent-plugin-mercurial.xml Thu Jul 31 00:36:47 2008 +0400 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> + +<beans default-autowire="constructor"> + <bean id="mercurialAgent" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialAgentSideVcsSupport" /> +</beans>
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Thu Jul 24 20:40:58 2008 +0400 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java Thu Jul 31 00:36:47 2008 +0400 @@ -29,7 +29,7 @@ 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) { + if (includeRule.getTo() != null && includeRule.getTo().length() > 0) { throw new VcsException("Include rule with mapping is not supported: " + includeRule.toString()); } @@ -44,7 +44,7 @@ } else { // execute clone command logger.message("No repository in working directory found, start cloning repository to temporary folder"); - File parentDir = cloneRepository(settings, version); + 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)) { @@ -56,18 +56,25 @@ } logger.message("Repository successfully moved to working directory: " + workingDir.getAbsolutePath()); - - logger.message("Updating working directory from the local repository copy"); - UpdateCommand uc = new UpdateCommand(settings); - uc.execute(); - logger.message("Working directory updated successfully"); } + updateWorkingDir(settings, version, logger); } - private File cloneRepository(final Settings settings, final String version) throws VcsException { - File tempDir = null; + 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); + ChangeSet cs = new ChangeSet(version); + uc.setToId(cs.getId()); + uc.execute(); + logger.message("Working directory updated successfully"); + } + + private File cloneRepository(final Settings settings) throws VcsException { + File tempDir; try { - tempDir = new File(FileUtil.createTempDirectory("hg", "clone"), "hg"); + File parent = FileUtil.createTempDirectory("hg", "clone"); + parent.deleteOnExit(); + tempDir = new File(parent, "hg"); } catch (IOException e) { throw new VcsException("Failed to create temp directory: " + e.getLocalizedMessage()); } @@ -75,9 +82,6 @@ CloneCommand cc = new CloneCommand(settings); cc.setDestDir(tempDir.getAbsolutePath()); - ChangeSet cs = new ChangeSet(version); - cc.setToId(cs.getId()); - cc.setUpdateWorkingDir(false); cc.execute(); return tempDir; @@ -99,7 +103,9 @@ if (files != null) { for (File file: files) { if (file.isFile()) { - if (!file.renameTo(new File(newDir, file.getName()))) { + File destFile = new File(newDir, file.getName()); + destFile.getParentFile().mkdirs(); + if (!file.renameTo(destFile)) { moveSuccessful = false; } } else if (!moveDir(file, new File(newDir, file.getName()))) {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateCommand.java Thu Jul 24 20:40:58 2008 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateCommand.java Thu Jul 31 00:36:47 2008 +0400 @@ -21,17 +21,26 @@ public class UpdateCommand { private Settings mySettings; + private String myToId; public UpdateCommand(@NotNull final Settings settings) { mySettings = settings; } + public void setToId(final String toId) { + myToId = toId; + } + public void execute() throws VcsException { GeneralCommandLine cli = new GeneralCommandLine(); cli.setExePath(mySettings.getHgCommandPath()); cli.setWorkDirectory(mySettings.getWorkingDir().getAbsolutePath()); cli.addParameter("update"); cli.addParameter("-C"); + if (myToId != null) { + cli.addParameter("-r"); + cli.addParameter(myToId); + } CommandUtil.runCommand(cli); } }
--- a/mercurial-server/src/META-INF/build-server-plugin-mercurial.xml Thu Jul 24 20:40:58 2008 +0400 +++ b/mercurial-server/src/META-INF/build-server-plugin-mercurial.xml Thu Jul 31 00:36:47 2008 +0400 @@ -2,6 +2,6 @@ <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="constructor"> - <bean id="mercurial" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialVcsSupport" /> + <bean id="mercurialServer" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialVcsSupport" /> <bean id="mercurialTeamCity31" class="jetbrains.buildServer.buildTriggers.vcs.mercurial.OldTeamCityVersionSupport" /> </beans>
--- a/mercurial-tests/mercurial-tests.iml Thu Jul 24 20:40:58 2008 +0400 +++ b/mercurial-tests/mercurial-tests.iml Thu Jul 31 00:36:47 2008 +0400 @@ -15,6 +15,7 @@ <orderEntry type="library" name="JMock" level="project" /> <orderEntry type="library" name="TeamCityAPI-common" level="project" /> <orderEntry type="module" module-name="mercurial-common" /> + <orderEntry type="module" module-name="mercurial-agent" /> <orderEntryProperties /> </component> </module>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java Thu Jul 31 00:36:47 2008 +0400 @@ -0,0 +1,67 @@ +package jetbrains.buildServer.buildTriggers.vcs.mercurial; + +import jetbrains.buildServer.agent.BuildProgressLogger; +import jetbrains.buildServer.util.FileUtil; +import jetbrains.buildServer.vcs.IncludeRule; +import jetbrains.buildServer.vcs.VcsException; +import jetbrains.buildServer.vcs.VcsRoot; +import org.jmock.Mock; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; + +/** + * @author Pavel.Sher + * Date: 30.07.2008 + */ +@Test +public class AgentSideCheckoutTest extends BaseMercurialTestCase { + private MercurialAgentSideVcsSupport myVcsSupport; + private Mock myProgressLoggerMock; + private File myWorkDir; + + @Override + @BeforeMethod + protected void setUp() throws Exception { + super.setUp(); + + myVcsSupport = new MercurialAgentSideVcsSupport(); + myProgressLoggerMock = new Mock(BuildProgressLogger.class); + myWorkDir = myTempFiles.createTempDir(); + } + + public void checkout_on_agent() throws IOException, VcsException { + myProgressLoggerMock.stubs().method("message"); + + VcsRoot vcsRoot = createVcsRoot(); + myVcsSupport.updateSources((BuildProgressLogger) myProgressLoggerMock.proxy(), myWorkDir, vcsRoot, "4:b06a290a363b", new IncludeRule(".", ".", null)); + File hgDir = new File(myWorkDir, ".hg"); + assertTrue(hgDir.isDirectory()); + + FileUtil.delete(hgDir); + + checkDirectoriesAreEqual(new File(getTestDataPath(), "cleanPatch1/after"), myWorkDir); + } + + public void update_on_agent() throws IOException, VcsException { + myProgressLoggerMock.stubs().method("message"); + + 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()); + + myVcsSupport.updateSources(logger, myWorkDir, vcsRoot, "4:b06a290a363b", new IncludeRule(".", ".", null)); + FileUtil.delete(hgDir); + + checkDirectoriesAreEqual(new File(getTestDataPath(), "patch1/after"), myWorkDir); + } + + protected String getTestDataPath() { + return "mercurial-tests/testData"; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java Thu Jul 31 00:36:47 2008 +0400 @@ -0,0 +1,44 @@ +package jetbrains.buildServer.buildTriggers.vcs.mercurial; + +import jetbrains.buildServer.MockSupport; +import jetbrains.buildServer.TempFiles; +import jetbrains.buildServer.vcs.impl.VcsRootImpl; +import jetbrains.buildServer.vcs.patches.PatchTestCase; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; + +import java.io.File; +import java.io.IOException; + +/** + * @author Pavel.Sher + * Date: 31.07.2008 + */ +public abstract class BaseMercurialTestCase extends PatchTestCase { + protected TempFiles myTempFiles; + protected MockSupport myMockSupport; + + @Override + @BeforeMethod + protected void setUp() throws Exception { + super.setUp(); + + myMockSupport = new MockSupport(); + myMockSupport.setUpMocks(); + myTempFiles = new TempFiles(); + } + + @AfterMethod + protected void tearDown() throws Exception { + myMockSupport.tearDownMocks(); + myTempFiles.cleanup(); + } + + protected VcsRootImpl createVcsRoot() throws IOException { + VcsRootImpl vcsRoot = new VcsRootImpl(1, Constants.VCS_NAME); + vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, new File("mercurial-tests/testData/bin/hg.exe").getAbsolutePath()); + File repository = LocalRepositoryUtil.prepareRepository(new File("mercurial-tests/testData/rep1").getAbsolutePath()); + vcsRoot.addProperty(Constants.REPOSITORY_PROP, repository.getAbsolutePath()); + return vcsRoot; + } +}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Thu Jul 24 20:40:58 2008 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Thu Jul 31 00:36:47 2008 +0400 @@ -15,17 +15,12 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial; -import jetbrains.buildServer.MockSupport; -import jetbrains.buildServer.TempFiles; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.ServerPaths; -import jetbrains.buildServer.util.SimpleExecutor; import jetbrains.buildServer.vcs.*; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import jetbrains.buildServer.vcs.patches.PatchBuilderImpl; -import jetbrains.buildServer.vcs.patches.PatchTestCase; import org.jmock.Mock; -import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -37,16 +32,12 @@ import java.util.concurrent.ScheduledExecutorService; @Test -public class MercurialVcsSupportTest extends PatchTestCase { +public class MercurialVcsSupportTest extends BaseMercurialTestCase { private MercurialVcsSupport myVcs; - private TempFiles myTempFiles; - private MockSupport myMockSupport; @BeforeMethod protected void setUp() throws Exception { super.setUp(); - myMockSupport = new MockSupport(); - myMockSupport.setUpMocks(); Mock vcsManagerMock = new Mock(VcsManager.class); vcsManagerMock.stubs().method("registerVcsSupport"); @@ -54,19 +45,12 @@ ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); serverMock.stubs().method("getExecutor").will(myMockSupport.returnValue(executor)); - myTempFiles = new TempFiles(); File systemDir = myTempFiles.createTempDir(); ServerPaths sp = new ServerPaths(systemDir.getAbsolutePath(), systemDir.getAbsolutePath()); assertTrue(new File(sp.getCachesDir()).mkdirs()); myVcs = new MercurialVcsSupport((VcsManager)vcsManagerMock.proxy(), sp, (SBuildServer)serverMock.proxy()); } - @AfterMethod - protected void tearDown() throws Exception { - myMockSupport.tearDownMocks(); - myTempFiles.cleanup(); - } - protected String getTestDataPath() { return "mercurial-tests/testData"; } @@ -171,12 +155,4 @@ private Object normalizePath(final String path) { return path.replace(File.separatorChar, '/'); } - - private VcsRootImpl createVcsRoot() throws IOException { - VcsRootImpl vcsRoot = new VcsRootImpl(1, myVcs.getName()); - vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, new File("mercurial-tests/testData/bin/hg.exe").getAbsolutePath()); - File repository = LocalRepositoryUtil.prepareRepository(new File("mercurial-tests/testData/rep1").getAbsolutePath()); - vcsRoot.addProperty(Constants.REPOSITORY_PROP, repository.getAbsolutePath()); - return vcsRoot; - } }
--- a/mercurial-tests/src/testng.xml Thu Jul 24 20:40:58 2008 +0400 +++ b/mercurial-tests/src/testng.xml Thu Jul 31 00:36:47 2008 +0400 @@ -5,6 +5,7 @@ <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.command.LogCommandTest"/> <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.command.StatusCommandTest"/> <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialVcsSupportTest"/> + <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.AgentSideCheckoutTest"/> </classes> </test> </suite>
--- a/mercurial.xml Thu Jul 24 20:40:58 2008 +0400 +++ b/mercurial.xml Thu Jul 31 00:36:47 2008 +0400 @@ -396,6 +396,7 @@ <path refid="library.testng.classpath"/> <path refid="library.jmock.classpath"/> <pathelement location="${mercurial-common.output.dir}"/> + <pathelement location="${mercurial-agent.output.dir}"/> </path> <path id="mercurial-tests.runtime.module.classpath"> @@ -412,6 +413,8 @@ <path refid="library.junit.classpath"/> <path refid="library.testng.classpath"/> <path refid="library.jmock.classpath"/> + <pathelement location="${mercurial-agent.output.dir}"/> + <path refid="library.teamcityapi-agent.classpath"/> </path> @@ -432,7 +435,7 @@ <target name="compile.module.mercurial-tests" depends="compile.module.mercurial-tests.production,compile.module.mercurial-tests.tests" description="Compile module mercurial-tests"/> - <target name="compile.module.mercurial-tests.production" depends="compile.module.mercurial-server,compile.module.mercurial-common" description="Compile module mercurial-tests; production classes"> + <target name="compile.module.mercurial-tests.production" depends="compile.module.mercurial-server,compile.module.mercurial-common,compile.module.mercurial-agent" description="Compile module mercurial-tests; production classes"> <mkdir dir="${mercurial-tests.output.dir}"/> <javac destdir="${mercurial-tests.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true"> <compilerarg line="${compiler.args.mercurial-tests}"/>