diff 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
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/BasicSessionContext.java	Mon Feb 13 15:11:27 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/BasicSessionContext.java	Wed Feb 15 22:57:56 2012 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 TMate Software Ltd
+ * Copyright (c) 2011-2012 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,6 +16,9 @@
  */
 package org.tmatesoft.hg.internal;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.tmatesoft.hg.core.SessionContext;
 import org.tmatesoft.hg.util.LogFacility;
 import org.tmatesoft.hg.util.PathPool;
@@ -30,10 +33,17 @@
 
 	private PathPool pathPool;
 	private final LogFacility logFacility;
+	private final Map<String, Object> properties;
 	
 	public BasicSessionContext(PathPool pathFactory, LogFacility log) {
+		this(null, pathFactory, log);
+	}
+	
+	@SuppressWarnings("unchecked")
+	public BasicSessionContext(Map<String,?> propertyOverrides, PathPool pathFactory, LogFacility log) {
 		pathPool = pathFactory;
 		logFacility = log != null ? log : new StreamLogFacility(true, true, true, System.out);
+		properties = propertyOverrides == null ? Collections.<String,Object>emptyMap() : (Map<String, Object>) propertyOverrides;
 	}
 
 	public PathPool getPathPool() {
@@ -49,7 +59,11 @@
 	}
 
 	public Object getProperty(String name, Object defaultValue) {
-		String value = System.getProperty(name);
+		Object value = properties.get(name);
+		if (value != null) {
+			return value;
+		}
+		value = System.getProperty(name);
 		return value == null ? defaultValue : value;
 	}
 }