logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1539687 - in /logging/log4net/branches/log4net-1.2.x: src/Repository/Hierarchy/XmlHierarchyConfigurator.cs tests/src/Hierarchy/XmlHierarchyConfiguratorTest.cs
Date Thu, 07 Nov 2013 15:40:39 GMT
Author: bodewig
Date: Thu Nov  7 15:40:38 2013
New Revision: 1539687

URL: http://svn.apache.org/r1539687
Log:
LOG4NET-132 - environment variables are case insensitive on Windows

Added:
    logging/log4net/branches/log4net-1.2.x/tests/src/Hierarchy/XmlHierarchyConfiguratorTest.cs
  (with props)
Modified:
    logging/log4net/branches/log4net-1.2.x/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs

Modified: logging/log4net/branches/log4net-1.2.x/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs
URL: http://svn.apache.org/viewvc/logging/log4net/branches/log4net-1.2.x/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs?rev=1539687&r1=1539686&r2=1539687&view=diff
==============================================================================
--- logging/log4net/branches/log4net-1.2.x/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs
(original)
+++ logging/log4net/branches/log4net-1.2.x/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs
Thu Nov  7 15:40:38 2013
@@ -634,7 +634,11 @@ namespace log4net.Repository.Hierarchy
 					try
 					{
 						// Expand environment variables in the string.
-						propertyValue = OptionConverter.SubstituteVariables(propertyValue, Environment.GetEnvironmentVariables());
+					    IDictionary environmentVariables = Environment.GetEnvironmentVariables();
+					    if (HasCaseInsensitiveEnvironment) {
+						environmentVariables = CreateCaseInsensitiveWrapper(environmentVariables);
+					    }
+						propertyValue = OptionConverter.SubstituteVariables(propertyValue, environmentVariables);
 					}
 					catch(System.Security.SecurityException)
 					{
@@ -1023,6 +1027,38 @@ namespace log4net.Repository.Hierarchy
 
 		#endregion Protected Instance Methods
 
+#if !NETCF
+		private bool HasCaseInsensitiveEnvironment
+	        {
+		    get
+		    {
+#if NET_1_0 || NET_1_1 || CLI_1_0
+			// actually there is no guarantee, but we don't know better
+			return true;
+#elif MONO_1_0
+			// see above
+			return false;
+#else
+			PlatformID platform = Environment.OSVersion.Platform;
+			return platform != PlatformID.Unix && platform != PlatformID.MacOSX;
+#endif
+		    }
+		}
+
+	        private IDictionary CreateCaseInsensitiveWrapper(IDictionary dict)
+	        {
+		    if (dict == null)
+		    {
+			return dict;
+		    }
+		    Hashtable hash = SystemInfo.CreateCaseInsensitiveHashtable();
+		    foreach (DictionaryEntry entry in dict) {
+			hash[entry.Key] = entry.Value;
+		    }
+		    return hash;
+		}
+#endif
+
 		#region Private Constants
 
 		// String constants used while parsing the XML data

Added: logging/log4net/branches/log4net-1.2.x/tests/src/Hierarchy/XmlHierarchyConfiguratorTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/branches/log4net-1.2.x/tests/src/Hierarchy/XmlHierarchyConfiguratorTest.cs?rev=1539687&view=auto
==============================================================================
--- logging/log4net/branches/log4net-1.2.x/tests/src/Hierarchy/XmlHierarchyConfiguratorTest.cs
(added)
+++ logging/log4net/branches/log4net-1.2.x/tests/src/Hierarchy/XmlHierarchyConfiguratorTest.cs
Thu Nov  7 15:40:38 2013
@@ -0,0 +1,82 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+using System;
+using System.Xml;
+using NUnit.Framework;
+
+using log4net.Repository.Hierarchy;
+
+namespace log4net.Tests.Hierarchy
+{
+    [TestFixture]
+    public class XmlHierarchyConfiguratorTest
+    {
+
+	private string testProp;
+
+	public string TestProp
+	{
+	    set
+	    {
+		testProp = value;
+	    }
+	    get
+	    {
+		return testProp;
+	    }
+	}
+
+	[Test][Platform(Include="Win")]
+	public void EnvironmentOnWindowsIsCaseInsensitive()
+	{
+	    SetTestPropWithPath();	    
+	    Assert.AreNotEqual("Path=", TestProp);
+	}
+
+	[Test][Platform(Include="Unix")]
+	public void EnvironmentOnUnixIsCaseSensitive()
+	{
+	    SetTestPropWithPath();	    
+	    Assert.AreEqual("Path=", TestProp);
+	}
+
+	private void SetTestPropWithPath()
+	{
+	    XmlDocument doc = new XmlDocument();
+	    XmlElement el = doc.CreateElement("param");
+	    el.SetAttribute("name", "TestProp");
+	    el.SetAttribute("value", "Path=${path}");
+	    new TestConfigurator().PublicSetParameter(el, this);
+	}
+
+	// workaround for SetParameter being protected
+	private class TestConfigurator : XmlHierarchyConfigurator {
+	    public TestConfigurator() : base(null)
+	    {
+	    }
+	    public void PublicSetParameter(XmlElement element, object target) 
+	    {
+		SetParameter(element, target);
+	    }
+	}
+    }
+}
\ No newline at end of file

Propchange: logging/log4net/branches/log4net-1.2.x/tests/src/Hierarchy/XmlHierarchyConfiguratorTest.cs
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message