Lucene.Net.Expressions: Factored out Configuration code by copying and 
converting the original text file from Java. We now have a duplicate function 
configuration, but can eliminate 4 dependencies from 2 projects and also 7 
classes from Support/Configuration.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/47ad5af0
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/47ad5af0
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/47ad5af0

Branch: refs/heads/api-work
Commit: 47ad5af00274093ab1e877c20e5d4516c0f290a8
Parents: 7c16e67
Author: Shad Storhaug <[email protected]>
Authored: Thu Apr 13 03:11:58 2017 +0700
Committer: Shad Storhaug <[email protected]>
Committed: Thu Apr 13 06:44:06 2017 +0700

----------------------------------------------------------------------
 .../JS/JavascriptCompiler.cs                    | 34 +++++++--------
 .../JS/JavascriptCompiler.properties            | 45 ++++++++++++++++++++
 src/Lucene.Net.Expressions/project.json         |  6 +--
 3 files changed, 64 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/47ad5af0/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs 
b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
index a6adabb..42578c0 100644
--- a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
+++ b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
@@ -10,8 +10,6 @@ using System.Reflection;
 using System.Reflection.Emit;
 
 #if NETSTANDARD
-using Lucene.Net.Support.Configuration;
-using Microsoft.Extensions.Configuration;
 using System.IO;
 #else
 using System.Configuration;
@@ -656,30 +654,32 @@ namespace Lucene.Net.Expressions.JS
             }
         }
 
-        private static IEnumerable<KeyValuePair<string, string>> 
GetDefaultSettings()
+        private static IDictionary<string, string> GetDefaultSettings()
         {
 #if NETSTANDARD
-            var assembly = typeof(JavascriptCompiler).GetTypeInfo().Assembly;
-            //var settingsFile = string.Join(".", assembly.GetName().Name, 
"Properties", "Settings.settings");
-            var settingsFile = string.Join(".", "Properties", 
"Settings.settings");
-            string contents;
-
-            using (var reader = new 
StreamReader(assembly.FindAndGetManifestResourceStream(typeof(JavascriptCompiler),
 settingsFile)))
+            var settings = new Dictionary<string, string>();
+            var type = typeof(JavascriptCompiler);
+            var assembly = type.GetTypeInfo().Assembly;
+            using (var reader = new 
StreamReader(assembly.FindAndGetManifestResourceStream(type, 
type.GetTypeInfo().Name + ".properties")))
             {
-                contents = reader.ReadToEnd();
+                string line;
+                while(!string.IsNullOrWhiteSpace(line = reader.ReadLine()))
+                {
+                    if (line.StartsWith("#", StringComparison.Ordinal) || 
!line.Contains('='))
+                    {
+                        continue;
+                    }
+                    var parts = line.Split('=').Select(x => 
x.Trim()).ToArray();
+                    settings[parts[0]] = parts[1];
+                }
             }
-
-            var configuration = new 
ConfigurationBuilder().AddConfigFile(contents, new 
SettingsConfigurationParser()).Build();
-
-            var settingsSection = 
configuration.GetSection(SettingsConfigurationParser.SETTINGS_ELEMENT);
-            var values = settingsSection.GetChildren().Select(section => new 
KeyValuePair<string, string>(section.Key, 
section.GetValue("(Default)"))).ToArray();
-            return values;
+            return settings;
 #else
             var props = Properties.Settings.Default;
 
             return props.Properties
                 .Cast<SettingsProperty>()
-                .Select(property => new KeyValuePair<string, 
string>(property.Name, props[property.Name].ToString()));
+                .ToDictionary(key => key.Name, value => 
props[value.Name].ToString());
 #endif
 
         }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/47ad5af0/src/Lucene.Net.Expressions/JS/JavascriptCompiler.properties
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.properties 
b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.properties
new file mode 100644
index 0000000..aa3180c
--- /dev/null
+++ b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.properties
@@ -0,0 +1,45 @@
+#  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.
+#
+#
+# This properties file contains all Javascript functions as keys.
+# The values are the implementing class, the static method name, and 
+# the number of double parameters.
+#
+abs = System.Math, Abs, 1
+acos = System.Math, Acos, 1
+acosh = Lucene.Net.Util.MathUtil, Acosh, 1
+asin = System.Math, Asin, 1
+asinh = Lucene.Net.Util.MathUtil, Asinh, 1
+atan = System.Math, Atan, 1
+atan2 = System.Math, Atan2, 2
+atanh = Lucene.Net.Util.MathUtil, Atanh, 1
+ceil = System.Math, Ceiling, 1
+cos = System.Math, Cos, 1
+cosh = System.Math, Cosh, 1
+exp = System.Math, Exp, 1
+floor = System.Math, Floor, 1
+haversin = Lucene.Net.Util.SloppyMath, Haversin, 4
+ln = System.Math, Log, 1
+log10 = System.Math, Log10, 1
+logn = Lucene.Net.Util.MathUtil, Log, 2
+max = System.Math, Max, 2
+min = System.Math, Min, 2
+pow = System.Math, Pow, 2
+sin = System.Math, Sin, 1
+sinh = System.Math, Sinh, 1
+sqrt = System.Math, Sqrt, 1
+tan = System.Math, Tan, 1
+tanh = System.Math, Tanh, 1

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/47ad5af0/src/Lucene.Net.Expressions/project.json
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Expressions/project.json 
b/src/Lucene.Net.Expressions/project.json
index f6f9514..6ba8560 100644
--- a/src/Lucene.Net.Expressions/project.json
+++ b/src/Lucene.Net.Expressions/project.json
@@ -31,9 +31,7 @@
         "NETStandard.Library": "1.6.0",
         "System.Reflection.Emit": "4.0.1",
         "System.Reflection.Emit.ILGeneration": "4.0.1",
-        "System.Reflection.TypeExtensions": "4.1.0",
-        "Microsoft.Extensions.Configuration": "1.0.0",
-        "Microsoft.Extensions.Configuration.Abstractions": "1.0.0"
+        "System.Reflection.TypeExtensions": "4.1.0"
       },
       "buildOptions": {
         "define": [ "NETSTANDARD" ],
@@ -41,7 +39,7 @@
           "excludeFiles": [ "Properties/Settings.Designer.cs" ]
         },
         "embed": {
-          "includeFiles": [ "Properties/Settings.settings" ]
+          "includeFiles": [ "JS/JavascriptCompiler.properties" ]
         }
       }
     },

Reply via email to