Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/BasicSessionContext.java @ 388:b015f3918120
Work on FIXME: correct HgDataFile#workingCopy with tests; BasicSessionContext with property override; platform-specific options to internals
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 15 Feb 2012 22:57:56 +0100 |
| parents | 3cfa4d908fc9 |
| children | 30922c728341 |
comparison
equal
deleted
inserted
replaced
| 387:cdea37239b01 | 388:b015f3918120 |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 TMate Software Ltd |
| 3 * | 3 * |
| 4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
| 5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
| 6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
| 7 * | 7 * |
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
| 18 | 18 |
| 19 import java.util.Collections; | |
| 20 import java.util.Map; | |
| 21 | |
| 19 import org.tmatesoft.hg.core.SessionContext; | 22 import org.tmatesoft.hg.core.SessionContext; |
| 20 import org.tmatesoft.hg.util.LogFacility; | 23 import org.tmatesoft.hg.util.LogFacility; |
| 21 import org.tmatesoft.hg.util.PathPool; | 24 import org.tmatesoft.hg.util.PathPool; |
| 22 import org.tmatesoft.hg.util.PathRewrite; | 25 import org.tmatesoft.hg.util.PathRewrite; |
| 23 | 26 |
| 28 */ | 31 */ |
| 29 public class BasicSessionContext implements SessionContext { | 32 public class BasicSessionContext implements SessionContext { |
| 30 | 33 |
| 31 private PathPool pathPool; | 34 private PathPool pathPool; |
| 32 private final LogFacility logFacility; | 35 private final LogFacility logFacility; |
| 36 private final Map<String, Object> properties; | |
| 33 | 37 |
| 34 public BasicSessionContext(PathPool pathFactory, LogFacility log) { | 38 public BasicSessionContext(PathPool pathFactory, LogFacility log) { |
| 39 this(null, pathFactory, log); | |
| 40 } | |
| 41 | |
| 42 @SuppressWarnings("unchecked") | |
| 43 public BasicSessionContext(Map<String,?> propertyOverrides, PathPool pathFactory, LogFacility log) { | |
| 35 pathPool = pathFactory; | 44 pathPool = pathFactory; |
| 36 logFacility = log != null ? log : new StreamLogFacility(true, true, true, System.out); | 45 logFacility = log != null ? log : new StreamLogFacility(true, true, true, System.out); |
| 46 properties = propertyOverrides == null ? Collections.<String,Object>emptyMap() : (Map<String, Object>) propertyOverrides; | |
| 37 } | 47 } |
| 38 | 48 |
| 39 public PathPool getPathPool() { | 49 public PathPool getPathPool() { |
| 40 if (pathPool == null) { | 50 if (pathPool == null) { |
| 41 pathPool = new PathPool(new PathRewrite.Empty()); | 51 pathPool = new PathPool(new PathRewrite.Empty()); |
| 47 // 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() |
| 48 return logFacility; | 58 return logFacility; |
| 49 } | 59 } |
| 50 | 60 |
| 51 public Object getProperty(String name, Object defaultValue) { | 61 public Object getProperty(String name, Object defaultValue) { |
| 52 String value = System.getProperty(name); | 62 Object value = properties.get(name); |
| 63 if (value != null) { | |
| 64 return value; | |
| 65 } | |
| 66 value = System.getProperty(name); | |
| 53 return value == null ? defaultValue : value; | 67 return value == null ? defaultValue : value; |
| 54 } | 68 } |
| 55 } | 69 } |
