view mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialAgentSideVcsSupport.java @ 896:4e29b1244707

Add VCS root option to use shared mirrors during agent-side checkout
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 07 Nov 2014 18:07:06 +0100
parents b11ace800435
children 3db6c332fc3b
line wrap: on
line source
/*
 * 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.agent.AgentRunningBuild;
import jetbrains.buildServer.agent.vcs.AgentVcsSupport;
import jetbrains.buildServer.agent.vcs.IncludeRuleUpdater;
import jetbrains.buildServer.agent.vcs.UpdateByIncludeRules2;
import jetbrains.buildServer.agent.vcs.UpdatePolicy;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.CheckoutInfo;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.MercurialExtension;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.MercurialExtensionManager;
import jetbrains.buildServer.vcs.CheckoutRules;
import jetbrains.buildServer.vcs.VcsException;
import jetbrains.buildServer.vcs.VcsRoot;
import org.jetbrains.annotations.NotNull;

import java.io.File;

public class MercurialAgentSideVcsSupport extends AgentVcsSupport implements UpdateByIncludeRules2 {

  private final AgentPluginConfig myConfig;
  private final MirrorManager myMirrorManager;
  private final AgentRepoFactory myRepoFactory;
  private final MercurialExtensionManager myExtentionManager;

  public MercurialAgentSideVcsSupport(@NotNull AgentPluginConfig pluginConfig,
                                      @NotNull MirrorManager mirrorManager,
                                      @NotNull AgentRepoFactory repoFactory,
                                      @NotNull MercurialExtensionManager extentionManager) {
    myConfig = pluginConfig;
    myMirrorManager = mirrorManager;
    myRepoFactory = repoFactory;
    myExtentionManager = extentionManager;
  }

  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 {
    MercurialIncludeRuleUpdater updater;
    if (myConfig.shareLocalMirrors(build, vcsRoot)) {
      updater = new SharingMercurialUpdater(myConfig, myMirrorManager, myRepoFactory, vcsRoot, toVersion, build);
    } else {
      updater = new MercurialIncludeRuleUpdater(myConfig, myMirrorManager, myRepoFactory, vcsRoot, toVersion, build);
    }
    registerExtensions(vcsRoot, checkoutRules, updater);
    return updater;
  }


  private void registerExtensions(@NotNull VcsRoot root, @NotNull CheckoutRules checkoutRules, @NotNull MercurialIncludeRuleUpdater updater) {
    CheckoutInfo info = new CheckoutInfo(myRepoFactory, new HgVcsRoot(root), checkoutRules);
    for (MercurialExtension ext :myExtentionManager.getExtensionsForCheckout(info)) {
      updater.registerExtension(ext);
    }
  }

  @NotNull
  @Override
  public String getName() {
    return Constants.VCS_NAME;
  }

  @NotNull
  @Override
  public UpdatePolicy getUpdatePolicy() {
    return this;
  }
}