# HG changeset patch
# User Pavel.Sher
# Date 1217450207 -14400
# Node ID 0052d368c90c2a5236d5f5ff28abee64025d9349
# Parent ad0aae0003bbbb581539f64a8657fb04f1fc3200
initial working version of agent side checkout + some tests
diff -r ad0aae0003bb -r 0052d368c90c mercurial-agent/src/META-INF/build-agent-plugin-mercurial.xml
--- /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 @@
+
+
+
+
+
+
diff -r ad0aae0003bb -r 0052d368c90c mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java
--- 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()))) {
diff -r ad0aae0003bb -r 0052d368c90c mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateCommand.java
--- 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);
}
}
diff -r ad0aae0003bb -r 0052d368c90c mercurial-server/src/META-INF/build-server-plugin-mercurial.xml
--- 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 @@
-
+
diff -r ad0aae0003bb -r 0052d368c90c mercurial-tests/mercurial-tests.iml
--- 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 @@
+
diff -r ad0aae0003bb -r 0052d368c90c mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutTest.java
--- /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";
+ }
+}
diff -r ad0aae0003bb -r 0052d368c90c mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java
--- /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;
+ }
+}
diff -r ad0aae0003bb -r 0052d368c90c mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java
--- 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;
- }
}
diff -r ad0aae0003bb -r 0052d368c90c mercurial-tests/src/testng.xml
--- 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 @@
+
diff -r ad0aae0003bb -r 0052d368c90c mercurial.xml
--- 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 @@
+
@@ -412,6 +413,8 @@
+
+
@@ -432,7 +435,7 @@
-
+