annotate src/org/tmatesoft/hg/repo/HgRepoConfig.java @ 480:f3fab7a20841

Refactor LineReader utility as stanalone class to facilitate reuse
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 17 Jul 2012 22:14:21 +0200
parents 51d682cf9cdc
children db48a77ec8ff
rev   line source
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
467
51d682cf9cdc Cleaned experimental tag and updated comments/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 369
diff changeset
2 * Copyright (c) 2011-2012 TMate Software Ltd
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.repo;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.util.ArrayList;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.util.Collections;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.util.Iterator;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.List;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.Map;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.internal.ConfigFile;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.util.Pair;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 * Repository-specific configuration.
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 *
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 * @author Artem Tikhomirov
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * @author TMate Software Ltd.
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 public final class HgRepoConfig /*implements RepoChangeListener, perhaps, also RepoChangeNotifier? */{
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 /*ease access for inner classes*/ final ConfigFile config;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 /*package-local*/HgRepoConfig(ConfigFile configFile) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 config = configFile;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 public Section getSection(String name) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 if (name == null) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 throw new IllegalArgumentException();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 if ("paths".equals(name)) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 return new PathsSection();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 if ("extensions".equals(name)) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 return new ExtensionsSection();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 return new Section(name);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 public boolean hasSection(String name) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 return config.hasSection(name);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 public boolean getBooleanValue(String section, String key, boolean defaultValue) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 return config.getBoolean(section, key, defaultValue);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 public String getStringValue(String section, String key, String defaultValue) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 return config.getString(section, key, defaultValue);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 //
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 //
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 public PathsSection getPaths() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 Section s = getSection("paths");
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 if (s.exists()) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 return (PathsSection) s;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 return new PathsSection();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 public ExtensionsSection getExtensions() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 Section s = getSection("extensions");
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 if (s.exists()) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 return (ExtensionsSection) s;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 return new ExtensionsSection();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 /*
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 * IMPLEMENTATION NOTE: Section is merely a view to configuration file, without any state.
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 * In case I need to sync access to config (i.e. write) or refresh it later - can be easily done
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 public class Section implements Iterable<Pair<String,String>> {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 protected final String section;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 /*package-local*/Section(String sectionName) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 section = sectionName;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 public String getName() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 return section;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 * Whether this is real section or a bare non-null instance
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 public boolean exists() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 return hasSection(section);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 * @return defined keys, in the order they appear in the section
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 public List<String> getKeys() {
333
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
113 // PathsSection depends on return value being modifiable
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 return new ArrayList<String>(config.getSection(section).keySet());
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 * Find out whether key is present and got any value
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 * @param key identifies an entry to look up
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 * @return true if key is present in the section and has non-empty value
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 public boolean isKeySet(String key) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 String value = getStringValue(section, key, null);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 return value != null && value.length() > 0;
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128 * Value of a key as boolean
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 * @param key identifies an entry to look up
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 * @param defaultValue optional value to return if no entry for the key found in this section
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 * @return value corresponding to the key, or defaultValue if key not found
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 public boolean getBoolean(String key, boolean defaultValue) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 return getBooleanValue(section, key, defaultValue);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 * Value of a key as regular string
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 * @param key identifies entry to look up
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 * @param defaultValue optional value to return if no entry for the key found in this section
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 * @return value corresponding to the key, or defaultValue if key not found
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143 public String getString(String key, String defaultValue) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 return getStringValue(section, key, defaultValue);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 public Iterator<Pair<String, String>> iterator() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 final Map<String, String> m = config.getSection(section);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149 if (m.isEmpty()) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 return Collections.<Pair<String,String>>emptyList().iterator();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 ArrayList<Pair<String, String>> rv = new ArrayList<Pair<String,String>>(m.size());
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 for (Map.Entry<String, String> e : m.entrySet()) {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 rv.add(new Pair<String,String>(e.getKey(), e.getValue()));
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 return rv.iterator();
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 /*
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 * Few well-known sections may get their specific subclasses
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 * Section [paths]
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 public class PathsSection extends Section {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 PathsSection() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 super("paths");
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 }
333
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
171
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
172 /**
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
173 * Similar to {@link #getKeys()}, but without entries for <b>default</b> and <b>default-push</b> paths
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
174 * @return list of path symbolic names
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
175 */
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
176 public List<String> getPathSymbolicNames() {
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
177 final List<String> rv = getKeys();
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
178 rv.remove("default");
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
179 rv.remove("default-push");
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
180 return rv;
467fd379b653 Specific accessor that omits predefined entries in the [paths] section
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 331
diff changeset
181 }
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
182
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
183 public boolean hasDefault() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
184 return isKeySet("default");
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 public String getDefault() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 return super.getString("default", null);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 public boolean hasDefaultPush() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
190 return isKeySet("default-push");
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 public String getDefaultPush() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 return super.getString("default-push", null);
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 /**
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 * Section [extensions]
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 *
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 * @author Artem Tikhomirov
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 * @author TMate Software Ltd.
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 */
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 public class ExtensionsSection extends Section {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 ExtensionsSection() {
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 super("extensions");
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 public boolean isEnabled(String extensionName) {
369
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
209 final Map<String, String> sect = config.getSection(section);
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
210 String value = sect.get(extensionName);
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
211 if (value == null) {
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
212 value = sect.get("hgext." + extensionName);
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
213 }
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
214 if (value == null) {
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
215 value = sect.get("hgext/" + extensionName);
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
216 }
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
217 if (value != null) {
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
218 // empty line, just "extension =" is valid way to enable it
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
219 return value.length() == 0 || '!' != value.charAt(0);
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
220 }
091666b87f62 Issue 21: Recognize extensions with prefixed names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 349
diff changeset
221 return false;
331
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
222 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 }
a37ce7145c3f Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 }