# HG changeset patch # User Dmitry Neverov # Date 1516790085 -3600 # Node ID 38e96101a6efaf09639d3f93e7b752ae76df7840 # Parent 38adef4f1b8f3fe398223fbd24d4ef07567e3418 TW-50054 disable custom clone path by default diff -r 38adef4f1b8f -r 38e96101a6ef mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Mon Jan 22 11:40:45 2018 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Wed Jan 24 11:34:45 2018 +0100 @@ -197,7 +197,7 @@ } private String readCustomClonePath() { - if (TeamCityProperties.getBooleanOrTrue(Constants.CUSTOM_CLONE_PATH_ENABLED)) + if (TeamCityProperties.getBoolean(Constants.CUSTOM_CLONE_PATH_ENABLED)) return getProperty(Constants.SERVER_CLONE_PATH_PROP); return null; } diff -r 38adef4f1b8f -r 38e96101a6ef mercurial-server/resources/buildServerResources/mercurialSettings.jsp --- a/mercurial-server/resources/buildServerResources/mercurialSettings.jsp Mon Jan 22 11:40:45 2018 +0100 +++ b/mercurial-server/resources/buildServerResources/mercurialSettings.jsp Wed Jan 24 11:34:45 2018 +0100 @@ -28,7 +28,7 @@ } - diff -r 38adef4f1b8f -r 38e96101a6ef mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java Mon Jan 22 11:40:45 2018 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java Wed Jan 24 11:34:45 2018 +0100 @@ -15,12 +15,18 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial; +import jetbrains.buildServer.serverSide.BasePropertiesModel; +import jetbrains.buildServer.serverSide.TeamCityProperties; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import jetbrains.buildServer.vcs.patches.PatchTestCase; import org.jetbrains.annotations.NotNull; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; import java.io.File; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; @@ -29,6 +35,21 @@ * Date: 31.07.2008 */ public abstract class BaseMercurialPatchTestCase extends PatchTestCase { + private Set myPropertiesToClean; + + @BeforeMethod + protected void setUp() throws Exception { + super.setUp(); + new TeamCityProperties() {{ setModel(new BasePropertiesModel() {});}}; + myPropertiesToClean = new HashSet<>(); + } + + @AfterMethod + public void tearDown() { + cleanInternalProperties(); + myTempFiles.cleanup(); + } + protected VcsRootImpl createVcsRoot(@NotNull String repPath) throws IOException { File repository = copyRepository(myTempFiles, repPath); return new VcsRootBuilder().withUrl(repository.getAbsolutePath()).build(); @@ -42,4 +63,16 @@ protected String simpleRepo() { return new File("mercurial-tests/testData/rep1").getAbsolutePath(); } + + protected void setInternalProperty(@NotNull String propKey, @NotNull String value) { + System.setProperty(propKey, value); + myPropertiesToClean.add(propKey); + } + + private void cleanInternalProperties() { + for (String prop : myPropertiesToClean) { + System.getProperties().remove(prop); + } + myPropertiesToClean.clear(); + } } diff -r 38adef4f1b8f -r 38e96101a6ef mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java Mon Jan 22 11:40:45 2018 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java Wed Jan 24 11:34:45 2018 +0100 @@ -25,20 +25,25 @@ import java.io.File; import java.io.IOException; +import java.util.HashSet; +import java.util.Set; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; public class BaseMercurialTestCase { protected TempFiles myTempFiles; + private Set myPropertiesToClean; @BeforeMethod public void setUp() throws Exception { new TeamCityProperties() {{ setModel(new BasePropertiesModel() {});}}; myTempFiles = new TempFiles(); + myPropertiesToClean = new HashSet<>(); } @AfterMethod public void tearDown() { + cleanInternalProperties(); myTempFiles.cleanup(); } @@ -49,4 +54,16 @@ copyRepository(new File(testRepoPath), result); return result; } + + protected void setInternalProperty(@NotNull String propKey, @NotNull String value) { + System.setProperty(propKey, value); + myPropertiesToClean.add(propKey); + } + + private void cleanInternalProperties() { + for (String prop : myPropertiesToClean) { + System.getProperties().remove(prop); + } + myPropertiesToClean.clear(); + } } diff -r 38adef4f1b8f -r 38e96101a6ef mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Mon Jan 22 11:40:45 2018 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Wed Jan 24 11:34:45 2018 +0100 @@ -35,6 +35,7 @@ @TestFor(issues = "TW-25057") public void vcs_root_custom_clone_dir_should_not_contain_password() throws Exception { + setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true"); TempFiles tmp = new TempFiles(); String urlWithoutPath = "http://only.host/"; String password = "pwd"; @@ -52,6 +53,7 @@ @TestFor(issues = "TW-32540") public void custom_clone_dir_should_contain_only_valid_characters() throws Exception { + setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true"); TempFiles tmp = new TempFiles(); String urlWithoutPath = "http://acme:8000/"; VcsRoot root = vcsRoot() diff -r 38adef4f1b8f -r 38e96101a6ef mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java Mon Jan 22 11:40:45 2018 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java Wed Jan 24 11:34:45 2018 +0100 @@ -16,29 +16,23 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; -import jetbrains.buildServer.serverSide.BasePropertiesModel; -import jetbrains.buildServer.serverSide.TeamCityProperties; import jetbrains.buildServer.util.TestFor; import jetbrains.buildServer.vcs.VcsRoot; import jetbrains.buildServer.vcs.impl.VcsRootImpl; -import junit.framework.TestCase; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.File; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertEquals; /** * @author Pavel.Sher */ @Test -public class HgVcsRootTest extends TestCase { - - @BeforeMethod - public void setUp() throws Exception { - new TeamCityProperties() {{ setModel(new BasePropertiesModel() {});}}; - } +public class HgVcsRootTest extends BaseMercurialTestCase { public void test_url_without_credentials() { VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path"); @@ -117,19 +111,15 @@ assertEquals("ssh://user:pwd@ourserver.com/mercurialrepo/", root.getRepositoryUrlWithCredentials()); } - @TestFor(issues = "TW-36401") + @TestFor(issues = {"TW-36401", "TW-50054"}) public void test_disabling_custom_clone_dirs() throws Exception { File cloneDir = new File(""); VcsRoot root = vcsRoot().withCloneRepositoryTo(cloneDir).withUrl("http://some.org/repo").build(); HgVcsRoot hgRoot1 = new HgVcsRoot(root); - assertEquals(cloneDir.getAbsolutePath(), hgRoot1.getCustomClonePath()); - try { - System.setProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "false"); - HgVcsRoot hgRoot2 = new HgVcsRoot(root); - assertNull(hgRoot2.getCustomClonePath()); - } finally { - System.getProperties().remove(Constants.CUSTOM_CLONE_PATH_ENABLED); - } + assertNull(hgRoot1.getCustomClonePath()); + setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true"); + HgVcsRoot hgRoot2 = new HgVcsRoot(root); + assertEquals(cloneDir.getAbsolutePath(), hgRoot2.getCustomClonePath()); } private VcsRootImpl createVcsRoot(String url) { diff -r 38adef4f1b8f -r 38e96101a6ef mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Mon Jan 22 11:40:45 2018 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Wed Jan 24 11:34:45 2018 +0100 @@ -534,6 +534,7 @@ } public void build_patch_using_custom_clone_path() throws IOException, VcsException { + setInternalProperty(Constants.CUSTOM_CLONE_PATH_ENABLED, "true"); setName("cleanPatch1"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); File cloneDir = myTempFiles.createTempDir();