view mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/BaseCommand.java @ 511:f2666e817701

Detect changes in subrepos
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 15 Nov 2012 16:40:22 +0400
parents 7d3527fe4556
children 31a1aca3305c
line wrap: on
line source
/*
 * Copyright 2000-2011 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.command;

import jetbrains.buildServer.vcs.VcsException;
import org.jetbrains.annotations.NotNull;

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

import static java.util.Collections.emptySet;

/**
 * @author pavel
 */
public class BaseCommand {

  protected final CommandSettings myCommandSettings;
  private final String myHgPath;
  private final File myWorkDirectory;

  public BaseCommand(@NotNull CommandSettings commandSettings,
                     @NotNull final String hgPath,
                     @NotNull File workingDir) {
    myCommandSettings = commandSettings;
    myHgPath = hgPath;
    myWorkDirectory = workingDir;
  }


  public File getWorkDirectory() {
    return myWorkDirectory;
  }

  protected MercurialCommandLine createCommandLine() {
    MercurialCommandLine cli = createCL();
    cli.setWorkDirectory(myWorkDirectory.getAbsolutePath());
    return cli;
  }

  protected MercurialCommandLine createCL() {
    MercurialCommandLine cl = new MercurialCommandLine(getPrivateData());
    cl.setExePath(myHgPath);
    cl.setEnvParams(myCommandSettings.getHgEnv());
    cl.setPassParentEnvs(true);
    return cl;
  }

  protected CommandResult runCommand(@NotNull MercurialCommandLine cli) throws VcsException {
    return CommandUtil.runCommand(cli, myCommandSettings);
  }

  protected Set<String> getPrivateData() {
    return emptySet();
  }

  protected String getHgPath() {
    return myHgPath;
  }
}