comparison src/org/tmatesoft/hg/repo/ext/HgExtensionsManager.java @ 501:d2f6ab541330

Change the way extensions are accessed (with ExtensionsManager now), add preliminary Rebase extension support
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 29 Oct 2012 19:04:13 +0100
parents
children
comparison
equal deleted inserted replaced
500:465316bf97e8 501:d2f6ab541330
1 /*
2 * Copyright (c) 2012 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.repo.ext;
18
19 import org.tmatesoft.hg.internal.Internals;
20 import org.tmatesoft.hg.repo.HgRepoConfig;
21
22 /**
23 *
24 * @author Artem Tikhomirov
25 * @author TMate Software Ltd.
26 */
27 public abstract class HgExtensionsManager {
28
29 public enum HgExt {
30 MQ ("mq"), Rebase("rebase");
31
32 private final String mercurialExtName;
33
34 private HgExt(String nativeName) {
35 mercurialExtName = nativeName;
36 }
37
38 String getNativeName() {
39 return mercurialExtName;
40 }
41 }
42
43 private final Internals repo;
44 private MqManager mqExt;
45 private Rebase rebaseExt;
46
47 protected HgExtensionsManager(Internals internalRepo) {
48 repo = internalRepo;
49 }
50
51 public boolean isEnabled(HgExt e) {
52 HgRepoConfig cfg = repo.getRepo().getConfiguration();
53 return cfg.getExtensions().isEnabled(e.getNativeName());
54 }
55
56 public Rebase getRebaseExtension() {
57 if (rebaseExt == null && isEnabled(HgExt.Rebase)) {
58 rebaseExt = new Rebase(repo);
59 }
60 return rebaseExt;
61 }
62
63 public MqManager getMQ() {
64 if (mqExt == null && isEnabled(HgExt.MQ)) {
65 mqExt = new MqManager(repo);
66 }
67 return mqExt;
68 }
69 }