This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git


The following commit(s) were added to refs/heads/master by this push:
     new 33faa93  Lucene.Net.Configuration: Removed ConfigurationBuilder, 
ConfigurationProvider, and LuceneDefaultConfigurationSource. Renamed 
LuceneDefaultConfigurationProvider > EnvironmentVariablesConfigurationProvider 
to match .NET. (fixes #311)
33faa93 is described below

commit 33faa93989e33eb7dda06a1cb3f1327c563eacc1
Author: Shad Storhaug <[email protected]>
AuthorDate: Tue Jul 21 11:42:06 2020 +0700

    Lucene.Net.Configuration: Removed ConfigurationBuilder, 
ConfigurationProvider, and LuceneDefaultConfigurationSource. Renamed 
LuceneDefaultConfigurationProvider > EnvironmentVariablesConfigurationProvider 
to match .NET. (fixes #311)
---
 Directory.Build.targets                            |  2 -
 .../Configuration/Base/ConfigurationBuilder.cs     | 71 ----------------
 .../Configuration/Base/ConfigurationProvider.cs    | 99 ----------------------
 .../Configuration/Base/ConfigurationRoot.cs        |  2 +-
 .../Configuration/DefaultConfigurationFactory.cs   | 17 +---
 ...> EnvironmentVariablesConfigurationProvider.cs} |  8 +-
 .../LuceneDefaultConfigurationSource.cs            | 46 ----------
 .../Configuration/TestConfigurationSettings.cs     |  2 +-
 8 files changed, 10 insertions(+), 237 deletions(-)

diff --git a/Directory.Build.targets b/Directory.Build.targets
index 88f406b..063b8fc 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -39,8 +39,6 @@
   <PropertyGroup Condition=" $(TargetFramework.StartsWith('netstandard2.')) Or 
$(TargetFramework.StartsWith('netcoreapp2.')) Or 
$(TargetFramework.StartsWith('netcoreapp3.')) ">
 
     
<DefineConstants>$(DefineConstants);FEATURE_ICONFIGURATIONROOT_PROVIDERS</DefineConstants>
-    
<DefineConstants>$(DefineConstants);FEATURE_ICONFIGURATIONBUILDER_PROPERTIES_AS_IDICTIONARY</DefineConstants>
-    
<DefineConstants>$(DefineConstants);FEATURE_ICONFIGURATIONBUILDER_SOURCES_AS_ILIST</DefineConstants>
 
   </PropertyGroup>
 
diff --git a/src/Lucene.Net/Support/Configuration/Base/ConfigurationBuilder.cs 
b/src/Lucene.Net/Support/Configuration/Base/ConfigurationBuilder.cs
deleted file mode 100644
index dcb53d3..0000000
--- a/src/Lucene.Net/Support/Configuration/Base/ConfigurationBuilder.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the 
project root for license information.
-
-using Microsoft.Extensions.Configuration;
-using System;
-using System.Collections.Generic;
-
-namespace Lucene.Net.Configuration
-{
-    /// <summary>
-    /// Used to build key/value based configuration settings for use in an 
application.
-    /// </summary>
-    internal class ConfigurationBuilder : IConfigurationBuilder
-    {
-        private readonly IList<IConfigurationSource> _sources = new 
List<IConfigurationSource>();
-        private readonly Dictionary<string, object> _properties = new 
Dictionary<string, object>();
-
-        /// <summary>
-        /// Returns the sources used to obtain configuration values.
-        /// </summary>
-#if FEATURE_ICONFIGURATIONBUILDER_SOURCES_AS_ILIST
-        public IList<IConfigurationSource> Sources => _sources;
-#else
-        
-        public IEnumerable<IConfigurationSource> Sources => _sources;
-#endif
-
-        /// <summary>
-        /// Gets a key/value collection that can be used to share data between 
the <see cref="IConfigurationBuilder"/>
-        /// and the registered <see cref="IConfigurationProvider"/>s.
-        /// </summary>
-#if FEATURE_ICONFIGURATIONBUILDER_PROPERTIES_AS_IDICTIONARY
-        public IDictionary<string, object> Properties => _properties;
-#else
-        
-        public Dictionary<string, object> Properties => _properties;
-#endif
-        /// <summary>
-        /// Adds a new configuration source.
-        /// </summary>
-        /// <param name="source">The configuration source to add.</param>
-        /// <returns>The same <see cref="IConfigurationBuilder"/>.</returns>
-        public IConfigurationBuilder Add(IConfigurationSource source)
-        {
-            if (source == null)
-            {
-                throw new ArgumentNullException(nameof(source));
-            }
-
-            _sources.Add(source);
-
-            return this;
-        }
-
-        /// <summary>
-        /// Builds an <see cref="IConfiguration"/> with keys and values from 
the set of providers registered in
-        /// <see cref="Sources"/>.
-        /// </summary>
-        /// <returns>An <see cref="IConfigurationRoot"/> with keys and values 
from the registered providers.</returns>
-        public IConfigurationRoot Build()
-        {
-            var providers = new List<IConfigurationProvider>();
-            foreach (var source in Sources)
-            {
-                var provider = source.Build(this);
-                providers.Add(provider);
-            }
-            return new ConfigurationRoot(providers);
-        }
-    }
-}
diff --git a/src/Lucene.Net/Support/Configuration/Base/ConfigurationProvider.cs 
b/src/Lucene.Net/Support/Configuration/Base/ConfigurationProvider.cs
deleted file mode 100644
index f8f287d..0000000
--- a/src/Lucene.Net/Support/Configuration/Base/ConfigurationProvider.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (c) .NET Foundation. All rights reserved.
-// Licensed under the Apache License, Version 2.0. See License.txt in the 
project root for license information.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Primitives;
-
-namespace Lucene.Net.Configuration
-{
-    /// <summary>
-    /// Base helper class for implementing an <see 
cref="IConfigurationProvider"/>
-    /// </summary>
-    internal abstract class ConfigurationProvider : IConfigurationProvider
-    {
-        private ConfigurationReloadToken _reloadToken = new 
ConfigurationReloadToken();
-
-        /// <summary>
-        /// Initializes a new <see cref="IConfigurationProvider"/>
-        /// </summary>
-        protected ConfigurationProvider()
-        {
-            Data = new Dictionary<string, 
string>(StringComparer.OrdinalIgnoreCase);
-        }
-
-        /// <summary>
-        /// The configuration key value pairs for this provider.
-        /// </summary>
-        protected IDictionary<string, string> Data { get; set; }
-
-        /// <summary>
-        /// Attempts to find a value with the given key, returns true if one 
is found, false otherwise.
-        /// </summary>
-        /// <param name="key">The key to lookup.</param>
-        /// <param name="value">The value found at key if one is found.</param>
-        /// <returns>True if key has a value, false otherwise.</returns>
-        public virtual bool TryGet(string key, out string value)
-            => Data.TryGetValue(key, out value);
-
-        /// <summary>
-        /// Sets a value for a given key.
-        /// </summary>
-        /// <param name="key">The configuration key to set.</param>
-        /// <param name="value">The value to set.</param>
-        public virtual void Set(string key, string value)
-            => Data[key] = value;
-
-        /// <summary>
-        /// Loads (or reloads) the data for this provider.
-        /// </summary>
-        public virtual void Load()
-        { }
-       
-        /// <summary>
-        /// Returns the list of keys that this provider has.
-        /// </summary>
-        /// <param name="earlierKeys">The earlier keys that other providers 
contain.</param>
-        /// <param name="parentPath">The path for the parent 
IConfiguration.</param>
-        /// <returns>The list of keys for this provider.</returns>
-        public virtual IEnumerable<string> GetChildKeys(
-            IEnumerable<string> earlierKeys,
-            string parentPath)
-        {
-            var prefix = parentPath == null ? string.Empty : parentPath + 
ConfigurationPath.KeyDelimiter;
-
-            return Data
-                .Where(kv => kv.Key.StartsWith(prefix, 
StringComparison.OrdinalIgnoreCase))
-                .Select(kv => Segment(kv.Key, prefix.Length))
-                .Concat(earlierKeys)
-                .OrderBy(k => k);
-        }
-
-        private static string Segment(string key, int prefixLength)
-        {
-            var indexOf = key.IndexOf(ConfigurationPath.KeyDelimiter, 
prefixLength, StringComparison.OrdinalIgnoreCase);
-            return indexOf < 0 ? key.Substring(prefixLength) : 
key.Substring(prefixLength, indexOf - prefixLength);
-        }
-
-        /// <summary>
-        /// Returns a <see cref="IChangeToken"/> that can be used to listen 
when this provider is reloaded.
-        /// </summary>
-        /// <returns></returns>
-        public IChangeToken GetReloadToken()
-        {
-            return _reloadToken;
-        }
-
-        /// <summary>
-        /// Triggers the reload change token and creates a new one.
-        /// </summary>
-        protected void OnReload()
-        {
-            var previousToken = Interlocked.Exchange(ref _reloadToken, new 
ConfigurationReloadToken());
-            previousToken.OnReload();
-        }
-    }
-}
diff --git a/src/Lucene.Net/Support/Configuration/Base/ConfigurationRoot.cs 
b/src/Lucene.Net/Support/Configuration/Base/ConfigurationRoot.cs
index d27c329..9b14b70 100644
--- a/src/Lucene.Net/Support/Configuration/Base/ConfigurationRoot.cs
+++ b/src/Lucene.Net/Support/Configuration/Base/ConfigurationRoot.cs
@@ -108,7 +108,7 @@ namespace Lucene.Net.Configuration
         ///     This method will never return <c>null</c>. If no matching 
sub-section is found with the specified key,
         ///     an empty <see cref="IConfigurationSection"/> will be returned.
         /// </remarks>
-        public IConfigurationSection GetSection(string key) 
+        public IConfigurationSection GetSection(string key)
             => new ConfigurationSection(this, key);
 
         /// <summary>
diff --git 
a/src/Lucene.Net/Support/Configuration/DefaultConfigurationFactory.cs 
b/src/Lucene.Net/Support/Configuration/DefaultConfigurationFactory.cs
index d79a8eb..2a41b83 100644
--- a/src/Lucene.Net/Support/Configuration/DefaultConfigurationFactory.cs
+++ b/src/Lucene.Net/Support/Configuration/DefaultConfigurationFactory.cs
@@ -27,27 +27,18 @@ namespace Lucene.Net.Configuration
     /// </summary>
     internal sealed class DefaultConfigurationFactory : IConfigurationFactory
     {
-        private readonly IConfigurationBuilder builder;
         private IConfiguration configuration;
 
-        public DefaultConfigurationFactory()
-        {
-            this.builder = new ConfigurationBuilder()
-                .Add(new LuceneDefaultConfigurationSource()
-                {
-                    Prefix = "lucene:",
-                    // Always ignore security exceptions when they are thrown 
during static initialization
-                    IgnoreSecurityExceptionsOnRead = true
-                });
-        }
-
         /// <summary>
         /// Returns the default configuration instance, creating it first if 
necessary.
         /// </summary>
         /// <returns>The default <see cref="IConfiguration"/> 
instance.</returns>
         public IConfiguration GetConfiguration()
         {
-            return LazyInitializer.EnsureInitialized(ref this.configuration, 
builder.Build);
+            return LazyInitializer.EnsureInitialized(ref this.configuration,
+                () => new ConfigurationRoot(new IConfigurationProvider[] {
+                    new EnvironmentVariablesConfigurationProvider(prefix: 
"lucene:", ignoreSecurityExceptionsOnRead: true)
+                }));
         }
     }
 }
diff --git 
a/src/Lucene.Net/Support/Configuration/LuceneDefaultConfigurationProvider.cs 
b/src/Lucene.Net/Support/Configuration/EnvironmentVariablesConfigurationProvider.cs
similarity index 91%
rename from 
src/Lucene.Net/Support/Configuration/LuceneDefaultConfigurationProvider.cs
rename to 
src/Lucene.Net/Support/Configuration/EnvironmentVariablesConfigurationProvider.cs
index 7c4172a..350f067 100644
--- a/src/Lucene.Net/Support/Configuration/LuceneDefaultConfigurationProvider.cs
+++ 
b/src/Lucene.Net/Support/Configuration/EnvironmentVariablesConfigurationProvider.cs
@@ -26,9 +26,9 @@ namespace Lucene.Net.Configuration
      */
 
     /// <summary>
-    /// An environment variable based <see cref="ConfigurationProvider"/>.
+    /// An environment variable based <see cref="IConfigurationProvider"/>.
     /// </summary>
-    internal class LuceneDefaultConfigurationProvider : IConfigurationProvider
+    internal class EnvironmentVariablesConfigurationProvider : 
IConfigurationProvider
     {
         private readonly bool ignoreSecurityExceptionsOnRead;
         private readonly string _prefix;
@@ -36,14 +36,14 @@ namespace Lucene.Net.Configuration
         /// <summary>
         /// Initializes a new instance.
         /// </summary>
-        public LuceneDefaultConfigurationProvider(bool 
ignoreSecurityExceptionsOnRead) : this(string.Empty, 
ignoreSecurityExceptionsOnRead)
+        public EnvironmentVariablesConfigurationProvider(bool 
ignoreSecurityExceptionsOnRead = true) : this(string.Empty, 
ignoreSecurityExceptionsOnRead)
         { }
 
         /// <summary>
         /// Initializes a new instance with the specified prefix.
         /// </summary>
         /// <param name="prefix">A prefix used to filter the environment 
variables.</param>
-        public LuceneDefaultConfigurationProvider(string prefix, bool 
ignoreSecurityExceptionsOnRead = true)
+        public EnvironmentVariablesConfigurationProvider(string prefix, bool 
ignoreSecurityExceptionsOnRead = true)
         {
             _prefix = prefix ?? string.Empty;
             this.ignoreSecurityExceptionsOnRead = 
ignoreSecurityExceptionsOnRead;
diff --git 
a/src/Lucene.Net/Support/Configuration/LuceneDefaultConfigurationSource.cs 
b/src/Lucene.Net/Support/Configuration/LuceneDefaultConfigurationSource.cs
deleted file mode 100644
index 612fcc7..0000000
--- a/src/Lucene.Net/Support/Configuration/LuceneDefaultConfigurationSource.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using Microsoft.Extensions.Configuration;
-
-namespace Lucene.Net.Configuration
-{
-    /*
-     * 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.
-     */
-
-    /// <summary>
-    /// Represents environment variables as an <see 
cref="IConfigurationSource"/>.
-    /// </summary>
-    internal class LuceneDefaultConfigurationSource : IConfigurationSource
-    {
-        /// <summary>
-        /// A prefix used to filter environment variables.
-        /// </summary>
-        public string Prefix { get; set; }
-        /// <summary>
-        /// Set to true by default - used to prevent any security exceptions 
thrown when reading environment variables
-        /// </summary>
-        public bool IgnoreSecurityExceptionsOnRead { get; set; }
-
-        /// <summary>
-        /// Builds the <see cref="LuceneDefaultConfigurationProvider"/> for 
this source.
-        /// </summary>
-        /// <param name="builder">The <see 
cref="IConfigurationBuilder"/>.</param>
-        /// <returns>A <see 
cref="LuceneDefaultConfigurationProvider"/></returns>
-        public IConfigurationProvider Build(IConfigurationBuilder builder)
-        {
-            return new LuceneDefaultConfigurationProvider(Prefix, 
IgnoreSecurityExceptionsOnRead);
-        }
-    }
-}
diff --git 
a/src/dotnet/tools/Lucene.Net.Tests.Cli/Configuration/TestConfigurationSettings.cs
 
b/src/dotnet/tools/Lucene.Net.Tests.Cli/Configuration/TestConfigurationSettings.cs
index 9e18132..cbed8a2 100644
--- 
a/src/dotnet/tools/Lucene.Net.Tests.Cli/Configuration/TestConfigurationSettings.cs
+++ 
b/src/dotnet/tools/Lucene.Net.Tests.Cli/Configuration/TestConfigurationSettings.cs
@@ -36,7 +36,7 @@ namespace Lucene.Net.Cli.Configuration
 
         protected override IConfiguration LoadConfiguration()
         {
-            IConfigurationRoot configuration = new 
Lucene.Net.Configuration.ConfigurationBuilder()
+            IConfigurationRoot configuration = new ConfigurationBuilder()
                 .AddEnvironmentVariables(prefix: EnvironmentVariablePrefix) // 
Use a custom prefix to only load Lucene.NET settings 
                 .AddJsonFile(TestJsonFilePath)
                 .Build();

Reply via email to