comparison mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java @ 280:8c1fd2e565ae

Implement mercurial detection on the agents When agent starts, hg-plugin detects installed hg (searches it in the $PATH). If plugin is able to run hg and hg has an approrpiate version (1.5.2+), then plugin reports path to hg in the 'teamcity.hg.agent.path' parameter. This parameter can be used in the "HG command path" field in a VCS root settings, configurations with such root will be run only on agents which report path to hg. Also user can set this parameter manually in the buildAgent.properties. A server side of plugin first checks value of internal property 'teamcity.hg.server.path' and if property is set, its value is used. Second, plugin tries to use path from the settings of VCS root: if path is equal to '%teamcity.hg.agent.path%' - use 'hg' as path, otherwise use a value from the root. With such order old setups, where path in the VCS root was used on both server and agent, will continue to work. New VCS roots with references in the path will also work if hg is in the $PATH on the server or internal property is set.
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 19 Aug 2011 15:21:38 +0400
parents f80e17ac2da6
children e9cdb499350d
comparison
equal deleted inserted replaced
277:f80e17ac2da6 280:8c1fd2e565ae
37 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandUtil.removePrivateData; 37 import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandUtil.removePrivateData;
38 38
39 public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules2 { 39 public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules2 {
40 40
41 private final MirrorManager myMirrorManager; 41 private final MirrorManager myMirrorManager;
42 private final HgPathProvider myHgPathProvider;
42 43
43 public MercurialAgentSideVcsSupport(BuildAgentConfiguration agentConfiguration) { 44 public MercurialAgentSideVcsSupport(@NotNull final BuildAgentConfiguration agentConfiguration,
45 @NotNull final HgPathProvider hgPathProvider) {
44 myMirrorManager = new MirrorManager(agentConfiguration.getCacheDirectory("mercurial")); 46 myMirrorManager = new MirrorManager(agentConfiguration.getCacheDirectory("mercurial"));
47 myHgPathProvider = hgPathProvider;
45 } 48 }
46 49
47 public IncludeRuleUpdater getUpdater(@NotNull final VcsRoot vcsRoot, @NotNull final CheckoutRules checkoutRules, @NotNull final String toVersion, @NotNull final File checkoutDirectory, @NotNull final AgentRunningBuild build, boolean cleanCheckoutRequested) throws VcsException { 50 public IncludeRuleUpdater getUpdater(@NotNull final VcsRoot vcsRoot, @NotNull final CheckoutRules checkoutRules, @NotNull final String toVersion, @NotNull final File checkoutDirectory, @NotNull final AgentRunningBuild build, boolean cleanCheckoutRequested) throws VcsException {
48 final BuildProgressLogger logger = build.getBuildLogger(); 51 final BuildProgressLogger logger = build.getBuildLogger();
49 final boolean useLocalMirrors = isUseLocalMirrors(build); 52 final boolean useLocalMirrors = isUseLocalMirrors(build);
53
50 return new IncludeRuleUpdater() { 54 return new IncludeRuleUpdater() {
51 public void process(@NotNull final IncludeRule includeRule, @NotNull final File workingDir) throws VcsException { 55 public void process(@NotNull final IncludeRule includeRule, @NotNull final File workingDir) throws VcsException {
52 try { 56 try {
53 checkRuleIsValid(includeRule); 57 checkRuleIsValid(includeRule);
54 Settings settings = new Settings(vcsRoot); 58 Settings settings = new Settings(myHgPathProvider, vcsRoot);
55 if (useLocalMirrors) { 59 if (useLocalMirrors) {
56 updateLocalMirror(vcsRoot, logger); 60 updateLocalMirror(vcsRoot, logger);
57 } 61 }
58 updateRepository(workingDir, settings, logger, useLocalMirrors); 62 updateRepository(workingDir, settings, logger, useLocalMirrors);
59 updateWorkingDir(settings, workingDir, toVersion, logger); 63 updateWorkingDir(settings, workingDir, toVersion, logger);
122 initRepository(workingDir, settings, logger, useLocalMirrors); 126 initRepository(workingDir, settings, logger, useLocalMirrors);
123 } 127 }
124 } 128 }
125 129
126 private void updateLocalMirror(VcsRoot root, BuildProgressLogger logger) throws VcsException, IOException { 130 private void updateLocalMirror(VcsRoot root, BuildProgressLogger logger) throws VcsException, IOException {
127 Settings settings = new Settings(root); 131 Settings settings = new Settings(myHgPathProvider, root);
128 File mirrorDir = myMirrorManager.getMirrorDir(settings.getRepositoryUrl()); 132 File mirrorDir = myMirrorManager.getMirrorDir(settings.getRepositoryUrl());
129 logger.message("Update local mirror at " + mirrorDir); 133 logger.message("Update local mirror at " + mirrorDir);
130 if (!Settings.isValidRepository(mirrorDir)) { 134 if (!Settings.isValidRepository(mirrorDir)) {
131 initRepository(mirrorDir, settings, logger, false); 135 initRepository(mirrorDir, settings, logger, false);
132 } 136 }