Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/ConfigFile.java @ 344:168f1994de7e
Distinguish active from removed tags
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 22 Nov 2011 02:57:14 +0100 |
parents | a37ce7145c3f |
children | 9fb990c8a724 |
rev | line source |
---|---|
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2011 TMate Software Ltd |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
73
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.BufferedReader; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.io.File; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.FileReader; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.IOException; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.util.ArrayList; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.util.Collections; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.util.LinkedHashMap; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.util.List; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.util.Map; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 /** |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
30 * .ini / .rc file reader |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 * @author Artem Tikhomirov |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 * @author TMate Software Ltd. |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 */ |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 public class ConfigFile { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 private List<String> sections; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 private List<Map<String,String>> content; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
39 public ConfigFile() { |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
42 public void addLocation(File path) throws IOException { |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 read(path); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
46 public boolean hasSection(String sectionName) { |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
47 return sections == null ? false : sections.indexOf(sectionName) != -1; |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
48 } |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
49 |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 public List<String> getSectionNames() { |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
51 return sections == null ? Collections.<String>emptyList() : Collections.unmodifiableList(sections); |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 public Map<String,String> getSection(String sectionName) { |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
55 if (sections == null) { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
56 return Collections.emptyMap(); |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
57 } |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 int x = sections.indexOf(sectionName); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 if (x == -1) { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 return Collections.emptyMap(); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 return Collections.unmodifiableMap(content.get(x)); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
65 public boolean getBoolean(String sectionName, String key, boolean defaultValue) { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
66 String value = getSection(sectionName).get(key); |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
67 if (value == null) { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
68 return defaultValue; |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
69 } |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
70 for (String s : new String[] { "true", "yes", "on", "1" }) { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
71 if (s.equalsIgnoreCase(value)) { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
72 return true; |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
73 } |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
74 } |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
75 return false; |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
76 } |
128
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
114
diff
changeset
|
77 |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
114
diff
changeset
|
78 public String getString(String sectionName, String key, String defaultValue) { |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
114
diff
changeset
|
79 String value = getSection(sectionName).get(key); |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
114
diff
changeset
|
80 return value == null ? defaultValue : value; |
44b97930570c
Introduced ChangelogHelper to look up changesets files were modified in
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
114
diff
changeset
|
81 } |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
82 |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
83 // TODO handle %include and %unset directives |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
84 // TODO "" and lists |
331
a37ce7145c3f
Access to repository configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
85 // XXX perhaps, single string to keep whole section with substrings for keys/values to minimize number of arrays (String.value) |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
86 private void read(File f) throws IOException { |
114
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
87 if (f == null || !f.canRead()) { |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
88 return; |
46291ec605a0
Filters to read and initialize according to configuration files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
102
diff
changeset
|
89 } |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 if (sections == null) { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 sections = new ArrayList<String>(); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 content = new ArrayList<Map<String,String>>(); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 } |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
94 BufferedReader br = null; |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 try { |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
96 br = new BufferedReader(new FileReader(f)); |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 String line; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 String sectionName = ""; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 Map<String,String> section = new LinkedHashMap<String, String>(); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 while ((line = br.readLine()) != null) { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 line = line.trim(); |
136
947bf231acbb
Strip off comments in config file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
128
diff
changeset
|
102 int x; |
947bf231acbb
Strip off comments in config file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
128
diff
changeset
|
103 if ((x = line.indexOf('#')) != -1) { |
947bf231acbb
Strip off comments in config file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
128
diff
changeset
|
104 // do not keep comments in memory, get new, shorter string |
947bf231acbb
Strip off comments in config file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
128
diff
changeset
|
105 line = new String(line.substring(0, x).trim()); |
947bf231acbb
Strip off comments in config file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
128
diff
changeset
|
106 } |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 if (line.length() <= 2) { // a=b or [a] are at least of length 3 |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 continue; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 if (line.charAt(0) == '[' && line.charAt(line.length() - 1) == ']') { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 sectionName = line.substring(1, line.length() - 1); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 if (sections.indexOf(sectionName) == -1) { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 sections.add(sectionName); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 content.add(section = new LinkedHashMap<String, String>()); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 } else { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 section = null; // drop cached value |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 } else if ((x = line.indexOf('=')) != -1) { |
136
947bf231acbb
Strip off comments in config file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
128
diff
changeset
|
119 // share char[] of the original string |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 String key = line.substring(0, x).trim(); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 String value = line.substring(x+1).trim(); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 if (section == null) { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 int i = sections.indexOf(sectionName); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 assert i >= 0; |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 section = content.get(i); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 if (sectionName.length() == 0) { |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 // add fake section only if there are any values |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 sections.add(sectionName); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 content.add(section); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 section.put(key, value); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } |
295
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
135 } finally { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
136 ((ArrayList<?>) sections).trimToSize(); |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
137 ((ArrayList<?>) content).trimToSize(); |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
138 if (br != null) { |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
139 br.close(); |
981f9f50bb6c
Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
136
diff
changeset
|
140 } |
69
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 assert sections.size() == content.size(); |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 } |
5a69397f0f99
Discovery utility for Hg network protocol finally in the repo, with quick-n-dirty ConfigFile impl that helps to hide auth info
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 } |