comparison src/org/tmatesoft/hg/internal/ConfigFile.java @ 628:6526d8adbc0f

Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 22 May 2013 15:52:31 +0200
parents e1b29756f901
children
comparison
equal deleted inserted replaced
627:5153eb73b18d 628:6526d8adbc0f
29 import java.util.Iterator; 29 import java.util.Iterator;
30 import java.util.LinkedHashMap; 30 import java.util.LinkedHashMap;
31 import java.util.List; 31 import java.util.List;
32 import java.util.Map; 32 import java.util.Map;
33 33
34 import org.tmatesoft.hg.core.HgIOException;
34 import org.tmatesoft.hg.core.SessionContext; 35 import org.tmatesoft.hg.core.SessionContext;
35 import org.tmatesoft.hg.repo.HgInvalidFileException;
36 import org.tmatesoft.hg.util.LogFacility; 36 import org.tmatesoft.hg.util.LogFacility;
37 37
38 /** 38 /**
39 * .ini / .rc file reader 39 * .ini / .rc file reader
40 * @author Artem Tikhomirov 40 * @author Artem Tikhomirov
48 48
49 public ConfigFile(SessionContext ctx) { 49 public ConfigFile(SessionContext ctx) {
50 sessionContext = ctx; 50 sessionContext = ctx;
51 } 51 }
52 52
53 public void addLocation(File path) throws HgInvalidFileException { 53 public void addLocation(File path) throws HgIOException {
54 read(path); 54 read(path);
55 } 55 }
56 56
57 public boolean hasSection(String sectionName) { 57 public boolean hasSection(String sectionName) {
58 return sections == null ? false : sections.indexOf(sectionName) != -1; 58 return sections == null ? false : sections.indexOf(sectionName) != -1;
123 } else { 123 } else {
124 section.put(key, newValue); 124 section.put(key, newValue);
125 } 125 }
126 } 126 }
127 127
128 private void read(File f) throws HgInvalidFileException { 128 private void read(File f) throws HgIOException {
129 if (f == null || !f.canRead()) { 129 if (f == null || !f.canRead()) {
130 return; 130 return;
131 } 131 }
132 if (sections == null) { 132 if (sections == null) {
133 sections = new ArrayList<String>(); 133 sections = new ArrayList<String>();
225 section.put(key, value); 225 section.put(key, value);
226 } 226 }
227 return true; 227 return true;
228 } 228 }
229 229
230 public void go(File f, ConfigFile cfg) throws HgInvalidFileException { 230 public void go(File f, ConfigFile cfg) throws HgIOException {
231 contextFile = f; 231 contextFile = f;
232 LineReader lr = new LineReader(f, cfg.sessionContext.getLog()); 232 LineReader lr = new LineReader(f, cfg.sessionContext.getLog());
233 lr.ignoreLineComments("#"); 233 lr.ignoreLineComments("#");
234 lr.read(this, cfg); 234 lr.read(this, cfg);
235 } 235 }
248 new Parser().go(f, cfg); 248 new Parser().go(f, cfg);
249 } else { 249 } else {
250 LogFacility lf = cfg.sessionContext.getLog(); 250 LogFacility lf = cfg.sessionContext.getLog();
251 lf.dump(ConfigFile.class, LogFacility.Severity.Debug, "Can't read file to include: %s", f); 251 lf.dump(ConfigFile.class, LogFacility.Severity.Debug, "Can't read file to include: %s", f);
252 } 252 }
253 } catch (HgInvalidFileException ex) { 253 } catch (HgIOException ex) {
254 LogFacility lf = cfg.sessionContext.getLog(); 254 LogFacility lf = cfg.sessionContext.getLog();
255 lf.dump(ConfigFile.class, LogFacility.Severity.Warn, "Can't include %s (%s)", f, includeValue); 255 lf.dump(ConfigFile.class, LogFacility.Severity.Warn, "Can't include %s (%s)", f, includeValue);
256 } 256 }
257 } 257 }
258 } 258 }