view mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigImpl.java @ 511:f2666e817701

Detect changes in subrepos
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 15 Nov 2012 16:40:22 +0400
parents 8eb05f24d883
children 89e9c06fbc76
line wrap: on
line source
package jetbrains.buildServer.buildTriggers.vcs.mercurial;

import com.intellij.openapi.diagnostic.Logger;
import jetbrains.buildServer.serverSide.ServerPaths;
import jetbrains.buildServer.serverSide.TeamCityProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import static com.intellij.openapi.util.text.StringUtil.isEmpty;
import static java.util.Collections.emptySet;

/**
 * @author dmitry.neverov
 */
public class ServerPluginConfigImpl implements ServerPluginConfig {

  private static final Logger LOG = Logger.getInstance(ServerPluginConfigImpl.class.getName());
  private static final String PULL_TIMEOUT_SECONDS = "teamcity.hg.pull.timeout.seconds";
  public static final int DEFAULT_PULL_TIMEOUT_SECONDS = 3600;

  private final File myCachesDir;

  public ServerPluginConfigImpl(@NotNull final ServerPaths paths) {
    myCachesDir = new File(paths.getCachesDir(), "mercurial");
  }

  public boolean isUsePullProtocol() {
    return TeamCityProperties.getBooleanOrTrue("teamcity.hg.use.pull.protocol");
  }

  @Nullable
  public String getHgPath() {
    return TeamCityProperties.getPropertyOrNull("teamcity.hg.server.path");
  }

  @NotNull
  public File getCachesDir() {
    return myCachesDir;
  }

  public boolean dontUseRevsets() {
    return TeamCityProperties.getBoolean("teamcity.hg.dont.use.revsets");
  }

  public int getPullTimeout() {
    int timeout = TeamCityProperties.getInteger(PULL_TIMEOUT_SECONDS, DEFAULT_PULL_TIMEOUT_SECONDS);
    return timeout > 0 ? timeout : DEFAULT_PULL_TIMEOUT_SECONDS;
  }

  @NotNull
  public Set<Long> getRevsetParentRootIds() {
    String parentRootIds = TeamCityProperties.getProperty("teamcity.hg.use.revsets.root.ids", "");
    if (isEmpty(parentRootIds))
      return emptySet();

    Set<Long> ids = new HashSet<Long>();
    for (String parentRootId : parentRootIds.split(",")) {
      try {
        ids.add(Long.parseLong(parentRootId));
      } catch (Exception e) {
        LOG.warn("Cannot parse rootId \"" + parentRootId + "\", ignore it");
      }
    }
    return ids;
  }

  public boolean detectSubrepoChanges() {
    return false;
  }
}