Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/BasicSessionContext.java @ 414:bb278ccf9866
Pull changes from smartgit3 branch
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 21 Mar 2012 20:51:12 +0100 |
| parents | 30922c728341 |
| children | 12f668401613 |
comparison
equal
deleted
inserted
replaced
| 413:7f27122011c3 | 414:bb278ccf9866 |
|---|---|
| 30 * @author TMate Software Ltd. | 30 * @author TMate Software Ltd. |
| 31 */ | 31 */ |
| 32 public class BasicSessionContext implements SessionContext { | 32 public class BasicSessionContext implements SessionContext { |
| 33 | 33 |
| 34 private PathPool pathPool; | 34 private PathPool pathPool; |
| 35 private final LogFacility logFacility; | 35 private LogFacility logFacility; |
| 36 private final Map<String, Object> properties; | 36 private final Map<String, Object> properties; |
| 37 | 37 |
| 38 public BasicSessionContext(PathPool pathFactory, LogFacility log) { | 38 public BasicSessionContext(PathPool pathFactory, LogFacility log) { |
| 39 this(null, pathFactory, log); | 39 this(null, pathFactory, log); |
| 40 } | 40 } |
| 41 | 41 |
| 42 @SuppressWarnings("unchecked") | 42 @SuppressWarnings("unchecked") |
| 43 public BasicSessionContext(Map<String,?> propertyOverrides, PathPool pathFactory, LogFacility log) { | 43 public BasicSessionContext(Map<String,?> propertyOverrides, PathPool pathFactory, LogFacility log) { |
| 44 pathPool = pathFactory; | 44 pathPool = pathFactory; |
| 45 logFacility = log != null ? log : new StreamLogFacility(true, true, true, System.out); | 45 logFacility = log; |
| 46 properties = propertyOverrides == null ? Collections.<String,Object>emptyMap() : (Map<String, Object>) propertyOverrides; | 46 properties = propertyOverrides == null ? Collections.<String,Object>emptyMap() : (Map<String, Object>) propertyOverrides; |
| 47 } | 47 } |
| 48 | 48 |
| 49 public PathPool getPathPool() { | 49 public PathPool getPathPool() { |
| 50 if (pathPool == null) { | 50 if (pathPool == null) { |
| 53 return pathPool; | 53 return pathPool; |
| 54 } | 54 } |
| 55 | 55 |
| 56 public LogFacility getLog() { | 56 public LogFacility getLog() { |
| 57 // e.g. for exceptions that we can't handle but log (e.g. FileNotFoundException when we've checked beforehand file.canRead() | 57 // e.g. for exceptions that we can't handle but log (e.g. FileNotFoundException when we've checked beforehand file.canRead() |
| 58 if (logFacility == null) { | |
| 59 boolean needDebug = _getBooleanProperty("hg.consolelog.debug", false); | |
| 60 boolean needInfo = needDebug || _getBooleanProperty("hg.consolelog.info", false); | |
| 61 logFacility = new StreamLogFacility(needDebug, needInfo, true, System.out); | |
| 62 } | |
| 58 return logFacility; | 63 return logFacility; |
| 59 } | 64 } |
| 65 | |
| 66 private boolean _getBooleanProperty(String name, boolean defaultValue) { | |
| 67 // can't use <T> and unchecked cast because got no confidence passed properties are strictly of the kind of my default values, | |
| 68 // i.e. if boolean from outside comes as "true", while I pass default as Boolean or vice versa. | |
| 69 Object p = getProperty(name, defaultValue); | |
| 70 return p instanceof Boolean ? ((Boolean) p).booleanValue() : Boolean.parseBoolean(String.valueOf(p)); | |
| 71 } | |
| 60 | 72 |
| 73 // TODO specific helpers for boolean and int values | |
| 61 public Object getProperty(String name, Object defaultValue) { | 74 public Object getProperty(String name, Object defaultValue) { |
| 75 // NOTE, this method is invoked from getLog(), hence do not call getLog from here unless changed appropriately | |
| 62 Object value = properties.get(name); | 76 Object value = properties.get(name); |
| 63 if (value != null) { | 77 if (value != null) { |
| 64 return value; | 78 return value; |
| 65 } | 79 } |
| 66 value = System.getProperty(name); | 80 value = System.getProperty(name); |
