Mercurial > hg > mercurial
changeset 978:38e96101a6ef Indore-2017.2.x
TW-50054 disable custom clone path by default
author | Dmitry Neverov <dmitry.neverov@gmail.com> |
---|---|
date | Wed, 24 Jan 2018 11:34:45 +0100 |
parents | 38adef4f1b8f |
children | 2b1bd4bca6ad |
files | mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java mercurial-server/resources/buildServerResources/mercurialSettings.jsp mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialTestCase.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java |
diffstat | 7 files changed, 64 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
--- 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 @@ } </script> <c:set var="subreposGloballyDisabled" value="<%= !TeamCityProperties.getBooleanOrTrue(Constants.GLOBAL_DETECT_SUBREPO_CHANGES) %>"/> -<c:set var="showCustomClonePath" value="<%= TeamCityProperties.getBooleanOrTrue(Constants.CUSTOM_CLONE_PATH_ENABLED) && +<c:set var="showCustomClonePath" value="<%= TeamCityProperties.getBoolean(Constants.CUSTOM_CLONE_PATH_ENABLED) && (TeamCityProperties.getBoolean(Constants.SHOW_CUSTOM_CLONE_PATH) || !StringUtil.isEmpty(propertiesBean.getProperties().get(Constants.SERVER_CLONE_PATH_PROP))) %>"/> <table class="runnerFormTable">
--- 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<String> 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(); + } }
--- 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<String> 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(); + } }
--- 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()
--- 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) {
--- 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();