Mercurial > hg4j
annotate src/org/tmatesoft/hg/repo/HgRepoConfig.java @ 332:72c6eda838a6
NPE in HgDirstate.known() when no dirstate file present
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 09 Nov 2011 04:33:44 +0100 |
parents | a37ce7145c3f |
children | 467fd379b653 |
rev | line source |
---|---|
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
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.internal.Experimental; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.util.Pair; |
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 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 * WORK IN PROGRESS |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 * |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 * Repository-specific configuration. |
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 * @author Artem Tikhomirov |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 * @author TMate Software Ltd. |
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 @Experimental(reason="WORK IN PROGRESS") |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 public final class HgRepoConfig /*implements RepoChangeListener, perhaps, also RepoChangeNotifier? */{ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 /*ease access for inner classes*/ final ConfigFile config; |
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 /*package-local*/HgRepoConfig(ConfigFile configFile) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 config = configFile; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 } |
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 public Section getSection(String name) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 if (name == null) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 throw new IllegalArgumentException(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 if ("paths".equals(name)) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 return new PathsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 if ("extensions".equals(name)) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 return new ExtensionsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 return new Section(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 hasSection(String name) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 return config.hasSection(name); |
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 boolean getBooleanValue(String section, String key, boolean defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 return config.getBoolean(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 public String getStringValue(String section, String key, String defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 return config.getString(section, key, defaultValue); |
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 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 // |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 // |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 public PathsSection getPaths() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 Section s = getSection("paths"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 if (s.exists()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 return (PathsSection) s; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 return new PathsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 public ExtensionsSection getExtensions() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 Section s = getSection("extensions"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 if (s.exists()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 return (ExtensionsSection) s; |
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 return new ExtensionsSection(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |
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 * 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
|
91 * 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
|
92 */ |
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 public class Section implements Iterable<Pair<String,String>> { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 protected final String section; |
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 /*package-local*/Section(String sectionName) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 section = sectionName; |
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 public String getName() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 return section; |
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 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 * 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
|
108 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 public boolean exists() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 return hasSection(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 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 * @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
|
115 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 public List<String> getKeys() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 return new ArrayList<String>(config.getSection(section).keySet()); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 * Find out whether key is present and got any value |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 * @param key identifies an entry to look up |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 * @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
|
124 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 public boolean isKeySet(String key) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 String value = getStringValue(section, key, null); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 return value != null && value.length() > 0; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 * Value of a key as boolean |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 * @param key identifies an entry to look up |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 * @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
|
134 * @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
|
135 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 public boolean getBoolean(String key, boolean defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 return getBooleanValue(section, key, defaultValue); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 * Value of a key as regular string |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 * @param key identifies entry to look up |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 * @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
|
144 * @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
|
145 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 public String getString(String key, String defaultValue) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 return getStringValue(section, key, defaultValue); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 public Iterator<Pair<String, String>> iterator() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 final Map<String, String> m = config.getSection(section); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 if (m.isEmpty()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 return Collections.<Pair<String,String>>emptyList().iterator(); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 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
|
156 for (Map.Entry<String, String> e : m.entrySet()) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 rv.add(new Pair<String,String>(e.getKey(), e.getValue())); |
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 return rv.iterator(); |
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 } |
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 * Few well-known sections may get their specific subclasses |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 */ |
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 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 * Section [paths] |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 */ |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 public class PathsSection extends Section { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 PathsSection() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
172 super("paths"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
173 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 public boolean hasDefault() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 return isKeySet("default"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 public String getDefault() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 return super.getString("default", null); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 public boolean hasDefaultPush() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 return isKeySet("default-push"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 public String getDefaultPush() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 return super.getString("default-push", null); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 } |
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 /** |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 * Section [extensions] |
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 * @author Artem Tikhomirov |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 * @author TMate Software Ltd. |
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 public class ExtensionsSection extends Section { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 ExtensionsSection() { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 super("extensions"); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 } |
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 public boolean isEnabled(String extensionName) { |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 String value = config.getSection(section).get(extensionName); |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 return value != null && value.length() > 0 && '!' != value.charAt(0) ; |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
203 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
204 } |
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
205 } |