kitaev@213: /* kitaev@213: * Copyright (c) 2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.core; kitaev@213: kitaev@213: import java.io.File; kitaev@213: kitaev@213: import org.tmatesoft.hg.repo.HgRepository; kitaev@213: import org.tmatesoft.hg.repo.HgLookup; kitaev@213: kitaev@213: /** kitaev@213: * Starting point for the library. kitaev@213: *
Sample use: kitaev@213: *
kitaev@213: * HgRepoFacade f = new HgRepoFacade(); kitaev@213: * f.initFrom(System.getenv("whatever.repo.location")); kitaev@213: * HgStatusCommand statusCmd = f.createStatusCommand(); kitaev@213: * HgStatusCommand.Handler handler = ...; kitaev@213: * statusCmd.execute(handler); kitaev@213: *kitaev@213: * kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: */ kitaev@213: public class HgRepoFacade { kitaev@213: private HgRepository repo; kitaev@213: kitaev@213: public HgRepoFacade() { kitaev@213: } kitaev@213: kitaev@213: /** kitaev@213: * @param hgRepo kitaev@213: * @return true on successful initialization kitaev@213: * @throws IllegalArgumentException when argument is null kitaev@213: */ kitaev@213: public boolean init(HgRepository hgRepo) { kitaev@213: if (hgRepo == null) { kitaev@213: throw new IllegalArgumentException(); kitaev@213: } kitaev@213: repo = hgRepo; kitaev@213: return !repo.isInvalid(); kitaev@213: } kitaev@213: kitaev@213: /** kitaev@213: * Tries to find repository starting from the current working directory. kitaev@213: * @return
true
if found valid repository
kitaev@213: * @throws HgException in case of errors during repository initialization
kitaev@213: */
kitaev@213: public boolean init() throws HgException {
kitaev@213: repo = new HgLookup().detectFromWorkingDir();
kitaev@213: return repo != null && !repo.isInvalid();
kitaev@213: }
kitaev@213:
kitaev@213: /**
kitaev@213: * Looks up Mercurial repository starting from specified location and up to filesystem root.
kitaev@213: *
kitaev@213: * @param repoLocation path to any folder within structure of a Mercurial repository.
kitaev@213: * @return true
if found valid repository
kitaev@213: * @throws HgException if there are errors accessing specified location
kitaev@213: * @throws IllegalArgumentException if argument is null
kitaev@213: */
kitaev@213: public boolean initFrom(File repoLocation) throws HgException {
kitaev@213: if (repoLocation == null) {
kitaev@213: throw new IllegalArgumentException();
kitaev@213: }
kitaev@213: repo = new HgLookup().detect(repoLocation);
kitaev@213: return repo != null && !repo.isInvalid();
kitaev@213: }
kitaev@213:
kitaev@213: public HgRepository getRepository() {
kitaev@213: if (repo == null) {
kitaev@213: throw new IllegalStateException("Call any of #init*() methods first first");
kitaev@213: }
kitaev@213: return repo;
kitaev@213: }
kitaev@213:
kitaev@213: public HgLogCommand createLogCommand() {
kitaev@213: return new HgLogCommand(repo/*, getCommandContext()*/);
kitaev@213: }
kitaev@213:
kitaev@213: public HgStatusCommand createStatusCommand() {
kitaev@213: return new HgStatusCommand(repo/*, getCommandContext()*/);
kitaev@213: }
kitaev@213:
kitaev@213: public HgCatCommand createCatCommand() {
kitaev@213: return new HgCatCommand(repo);
kitaev@213: }
kitaev@213:
kitaev@213: public HgManifestCommand createManifestCommand() {
kitaev@213: return new HgManifestCommand(repo);
kitaev@213: }
kitaev@213:
kitaev@213: public HgOutgoingCommand createOutgoingCommand() {
kitaev@213: return new HgOutgoingCommand(repo);
kitaev@213: }
kitaev@213:
kitaev@213: public HgIncomingCommand createIncomingCommand() {
kitaev@213: return new HgIncomingCommand(repo);
kitaev@213: }
kitaev@213: }