# HG changeset patch # User eugene.petrenko@jetbrains.com # Date 1393331928 -3600 # Node ID dd3a471a1188cfc1e44a0b44c703dc5588596ad2 # Parent ce67edf7bae96df34897b3c290a586a7218f2933 test added diff -r ce67edf7bae9 -r dd3a471a1188 mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Feb 25 13:11:18 2014 +0100 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Feb 25 13:38:48 2014 +0100 @@ -123,7 +123,7 @@ @NotNull public byte[] getContent(@NotNull final String filePath, @NotNull final VcsRoot vcsRoot, @NotNull final String version) throws VcsException { ChangeSet cset = new ChangeSet(version); - HgVcsRoot root = myHgVcsRootFactory.createHgRoot(vcsRoot); + HgVcsRoot root = getHgRoot(vcsRoot); syncRepository(root, cset); HgRepo repo = createRepo(root); File parentDir = repo.cat().files(filePath).atRevision(cset).call(); @@ -138,6 +138,11 @@ } @NotNull + public HgVcsRoot getHgRoot(@NotNull final VcsRoot vcsRoot) throws VcsException { + return myHgVcsRootFactory.createHgRoot(vcsRoot); + } + + @NotNull public String getName() { return Constants.VCS_NAME; } @@ -174,11 +179,12 @@ } @NotNull - public String describeVcsRoot(final VcsRoot vcsRoot) { + public String describeVcsRoot(@NotNull final VcsRoot vcsRoot) { return "mercurial: " + vcsRoot.getProperty(Constants.REPOSITORY_PROP); } @Override + @NotNull public TestConnectionSupport getTestConnectionSupport() { return myTestConnection; } @@ -490,7 +496,7 @@ } public void syncRepository(@NotNull final VcsRoot root) throws VcsException { - syncRepository(myHgVcsRootFactory.createHgRoot(root)); + syncRepository(getHgRoot(root)); } public void syncRepository(@NotNull final HgVcsRoot root) throws VcsException { @@ -556,7 +562,7 @@ } public void buildPatch(@NotNull VcsRoot root, @Nullable String fromVersion, @NotNull String toVersion, @NotNull PatchBuilder builder, @NotNull CheckoutRules checkoutRules) throws IOException, VcsException { - HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); + HgVcsRoot hgRoot = getHgRoot(root); buildPatch(hgRoot, fromVersion, toVersion, builder, checkoutRules); } @@ -599,11 +605,12 @@ return myConfig.allowSourceCaching(); } + @NotNull public String label(@NotNull String label, @NotNull String version, @NotNull VcsRoot root, @NotNull CheckoutRules checkoutRules) throws VcsException { File tmpDir = null; try { tmpDir = createLabelingTmpDir(); - HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); + HgVcsRoot hgRoot = getHgRoot(root); hgRoot.setCustomWorkingDir(tmpDir); syncRepository(hgRoot); HgRepo repo = createRepo(hgRoot); diff -r ce67edf7bae9 -r dd3a471a1188 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ExtensionsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ExtensionsTest.java Tue Feb 25 13:38:48 2014 +0100 @@ -0,0 +1,76 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jetbrains.buildServer.buildTriggers.vcs.mercurial; + +import jetbrains.buildServer.vcs.VcsException; +import jetbrains.buildServer.vcs.VcsRoot; +import junit.framework.Assert; +import org.jetbrains.annotations.NotNull; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.IOException; + +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.ServerPluginConfigBuilder.serverPluginConfig; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; + +/** + * Created 25.02.14 13:17 + * + * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) + */ +@RequiredHgVersion(min = "2.0.0") +public class ExtensionsTest extends BaseMercurialTestCase { + + @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") + public void test_no_extension(HgVersion _) throws IOException, VcsException { + String extension = "HGExtensionThatDoesNotExits"; + + try { + runWithExtensions(extension); + Assert.fail(); + } catch (VcsException e) { + Assert.assertTrue(e.getMessage().contains(extension)); + } + } + + @Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") + public void test_extension(HgVersion _) throws IOException, VcsException { + runWithExtensions("mq", "largefiles"); + } + + private void runWithExtensions(@NotNull String... extensions) throws IOException, VcsException { + ServerPluginConfig config = serverPluginConfig() + .cachesDir(myTempFiles.createTempDir()) + .hgPath(Util.getHgPath()) + .build(); + + final File myRemoteRepository = myTempFiles.createTempDir(); + Util.copyRepository(new File("mercurial-tests/testData/rep2"), myRemoteRepository); + + + final MercurialSupportBuilder hgBuilder = mercurialSupport().withConfig(config); + final MercurialVcsSupport vcs = hgBuilder.build(); + final VcsRoot root = vcsRoot().withUrl(myRemoteRepository.getAbsolutePath()).withBranch("default").withExtensions(extensions).build(); + + vcs.getCollectChangesPolicy().getCurrentState(root); + vcs.getTestConnectionSupport().testConnection(root); + } + + +} diff -r ce67edf7bae9 -r dd3a471a1188 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Tue Feb 25 13:11:18 2014 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Tue Feb 25 13:38:48 2014 +0100 @@ -16,6 +16,7 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; +import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.vcs.SVcsRoot; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import org.jetbrains.annotations.NotNull; @@ -30,6 +31,7 @@ */ public class VcsRootBuilder { + private String myExtensions; private String myRepository; private String myUsername; private String myPassword; @@ -60,6 +62,7 @@ vcsRoot.addProperty(Constants.DETECT_SUBREPO_CHANGES, String.valueOf(myDetectSubrepoChanges)); vcsRoot.addProperty(Constants.INCLUDE_SUBREPOS_IN_PATCH, String.valueOf(myIncludeSubreposInPatch)); vcsRoot.addProperty(Constants.USE_ARCHIVE_FOR_PATCH, String.valueOf(myUseArchiveForPatch)); + vcsRoot.addProperty(Constants.HG_EXTENSIONS, myExtensions); if (myCloneRepositoryTo != null) vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, String.valueOf(myCloneRepositoryTo.getAbsolutePath())); vcsRoot.addProperty(Constants.USE_TAGS_AS_BRANCHES, String.valueOf(myTagsAsBranches)); @@ -82,6 +85,7 @@ allowing(root).getProperty(with(Constants.USER_FOR_TAG)); will(returnValue(myUserForTag)); allowing(root).getProperty(with(Constants.DETECT_SUBREPO_CHANGES)); will(returnValue(String.valueOf(myDetectSubrepoChanges))); allowing(root).getProperty(with(Constants.USE_TAGS_AS_BRANCHES)); will(returnValue(String.valueOf(myTagsAsBranches))); + allowing(root).getProperty(with(Constants.HG_EXTENSIONS)); will(returnValue(myExtensions)); }}); if (myCloneRepositoryTo != null) { context.checking(new Expectations() {{ @@ -97,6 +101,12 @@ return this; } + @NotNull + public VcsRootBuilder withExtensions(@NotNull String... extensions) { + myExtensions = StringUtil.join(extensions, "\n"); + return this; + } + public VcsRootBuilder withLocalRepository(@NotNull final File repo) { return withUrl(repo.getPath()).withCloneRepositoryTo(repo.getParentFile());