# HG changeset patch # User Pavel.Sher # Date 1227715947 -10800 # Node ID b328c6b6526dd043f0a9bb6f079da36b80d68b72 # Parent 59add01ab524d512237e4c4bed163bdf491dceaf TW-5636: Mercurial plugin can easilly hit Windows MAX_PATH limitations diff -r 59add01ab524 -r b328c6b6526d build.xml --- a/build.xml Sun Oct 26 17:08:25 2008 +0300 +++ b/build.xml Wed Nov 26 19:12:27 2008 +0300 @@ -10,16 +10,35 @@ - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -27,6 +46,8 @@ + + diff -r 59add01ab524 -r b328c6b6526d mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java Sun Oct 26 17:08:25 2008 +0300 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java Wed Nov 26 19:12:27 2008 +0300 @@ -22,6 +22,7 @@ String REPOSITORY_PROP = "repositoryPath"; String BRANCH_NAME_PROP = "branchName"; String HG_COMMAND_PATH_PROP = "hgCommandPath"; + String SERVER_CLONE_PATH_PROP = "serverClonePath"; String USERNAME = "username"; String PASSWORD = VcsRoot.SECURE_PROPERTY_PREFIX + "password"; } diff -r 59add01ab524 -r b328c6b6526d mercurial-server/resources/buildServerResources/mercurialSettings.jsp --- a/mercurial-server/resources/buildServerResources/mercurialSettings.jsp Sun Oct 26 17:08:25 2008 +0300 +++ b/mercurial-server/resources/buildServerResources/mercurialSettings.jsp Wed Nov 26 19:12:27 2008 +0300 @@ -25,10 +25,16 @@ + + + +
Provide path to a parent directory on TeamCity server where a cloned repository should be created (applicable to "Automatically on server" checkout mode only). Leave blank to use default path.
+ + - You may require to provide authorization settings if you need to tag / label sources in the remote repository. + Authorization settings can be required if you need to tag / label sources in the remote repository. diff -r 59add01ab524 -r b328c6b6526d mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Sun Oct 26 17:08:25 2008 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Wed Nov 26 19:12:27 2008 +0300 @@ -26,6 +26,7 @@ import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.ServerPaths; import jetbrains.buildServer.util.FileUtil; +import jetbrains.buildServer.util.StringUtil; import jetbrains.buildServer.vcs.*; import jetbrains.buildServer.vcs.patches.PatchBuilder; import org.jetbrains.annotations.NotNull; @@ -69,7 +70,7 @@ removeOldWorkFolders(); } }, 0, OLD_WORK_DIRS_CLEANUP_PERIOD, TimeUnit.SECONDS); - myDefaultWorkFolderParent = new File(paths.getCachesDir()); + myDefaultWorkFolderParent = new File(paths.getCachesDir(), "mercurial"); } public List collectBuildChanges(final VcsRoot root, @@ -197,6 +198,9 @@ if (isEmpty(properties.get(Constants.REPOSITORY_PROP))) { result.add(new InvalidProperty(Constants.REPOSITORY_PROP, "Repository must be specified")); } + if (isEmpty(properties.get(Constants.SERVER_CLONE_PATH_PROP))) { + properties.put(Constants.SERVER_CLONE_PATH_PROP, myDefaultWorkFolderParent.getAbsolutePath()); + } return result; } }; @@ -250,7 +254,10 @@ @Nullable public Map getDefaultVcsProperties() { - return Collections.singletonMap(Constants.HG_COMMAND_PATH_PROP, "hg"); + Map defaults = new HashMap(); + defaults.put(Constants.HG_COMMAND_PATH_PROP, "hg"); + defaults.put(Constants.SERVER_CLONE_PATH_PROP, myDefaultWorkFolderParent.getAbsolutePath()); + return defaults; } public String getVersionDisplayName(final String version, final VcsRoot root) throws VcsException { @@ -437,7 +444,7 @@ } private void removeOldWorkFolders() { - File workFoldersParent = new File(myDefaultWorkFolderParent, "mercurial"); + File workFoldersParent = myDefaultWorkFolderParent; if (!workFoldersParent.isDirectory()) return; Set workDirs = new HashSet(); @@ -454,8 +461,12 @@ for (VcsRoot vcsRoot: myVcsManager.getAllRegisteredVcsRoots()) { if (getName().equals(vcsRoot.getVcsName())) { - Settings s = createSettings(vcsRoot); - workDirs.remove(PathUtil.getCanonicalFile(s.getLocalRepositoryDir())); + try { + Settings s = createSettings(vcsRoot); + workDirs.remove(PathUtil.getCanonicalFile(s.getLocalRepositoryDir())); + } catch (VcsException e) { + Loggers.VCS.error(e); + } } } @@ -503,8 +514,32 @@ return label.replace(':', '_').replace('\r', '_').replace('\n', '_'); } - private Settings createSettings(final VcsRoot root) { - return new Settings(myDefaultWorkFolderParent, root); + private Settings createSettings(final VcsRoot root) throws VcsException { + Settings settings = new Settings(myDefaultWorkFolderParent, root); + String customClonePath = root.getProperty(Constants.SERVER_CLONE_PATH_PROP); + if (!StringUtil.isEmptyOrSpaces(customClonePath) && !myDefaultWorkFolderParent.equals(new File(customClonePath).getAbsoluteFile())) { + File parentDir = new File(customClonePath); + createClonedRepositoryParentDir(parentDir); + + // take last part of repository path + String repPath = settings.getRepository(); + String[] splitted = repPath.split("[/\\\\]"); + if (splitted.length > 0) { + repPath = splitted[splitted.length-1]; + } + + File customWorkingDir = new File(parentDir, repPath); + settings.setWorkingDir(customWorkingDir); + } else { + createClonedRepositoryParentDir(myDefaultWorkFolderParent); + } + return settings; + } + + private void createClonedRepositoryParentDir(final File parentDir) throws VcsException { + if (!parentDir.exists() && !parentDir.mkdirs()) { + throw new VcsException("Failed to create parent directory for cloned repository: " + parentDir.getAbsolutePath()); + } } public boolean isAgentSideCheckoutAvailable() { diff -r 59add01ab524 -r b328c6b6526d mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Sun Oct 26 17:08:25 2008 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Wed Nov 26 19:12:27 2008 +0300 @@ -30,6 +30,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FilenameFilter; import java.io.IOException; import java.util.List; import java.util.concurrent.Executors; @@ -114,7 +115,7 @@ assertEquals(md.getDescription(), "modified in subdir"); } - @Test(invocationCount = 3) + @Test public void test_build_patch() throws IOException, VcsException { setName("cleanPatch1"); VcsRootImpl vcsRoot = createVcsRoot(); @@ -126,6 +127,14 @@ builder.close(); checkPatchResult(output.toByteArray()); + + File clonedReposParentDir = new File(myServerPaths.getCachesDir(), "mercurial"); + assertTrue(clonedReposParentDir.isDirectory()); + assertTrue(1 == clonedReposParentDir.list(new FilenameFilter() { + public boolean accept(final File dir, final String name) { + return name.startsWith("hg_"); + } + }).length); } public void test_build_incremental_patch() throws IOException, VcsException { @@ -284,6 +293,23 @@ assertEquals("default", settings.getBranchName()); } + public void build_patch_using_custom_clone_path() throws IOException, VcsException { + setName("cleanPatch1"); + VcsRootImpl vcsRoot = createVcsRoot(); + File cloneDir = myTempFiles.createTempDir(); + vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, cloneDir.getAbsolutePath()); + + final ByteArrayOutputStream output = new ByteArrayOutputStream(); + final PatchBuilderImpl builder = new PatchBuilderImpl(output); + + myVcs.buildPatch(vcsRoot, null, "4:b06a290a363b", builder, new CheckoutRules("")); + builder.close(); + + checkPatchResult(output.toByteArray()); + + assertTrue(new File(cloneDir, new File(vcsRoot.getProperty(Constants.REPOSITORY_PROP)).getName()).isDirectory()); + } + private Object normalizePath(final String path) { return path.replace(File.separatorChar, '/'); }