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
commit 172be69b4df8adf43637b31d627b2e0931757af9 Author: Shad Storhaug <[email protected]> AuthorDate: Mon Sep 14 07:52:54 2020 +0700 Lucene.Net.Expressions: Eliminated .NET settings file and reused JavascriptCompiler.properties file in .NET Framework so we don't have to branch for different target platforms. Simplified reading the settings by using J2N PropertyExtensions. --- .../JS/JavascriptCompiler.cs | 38 +-- .../Lucene.Net.Expressions.csproj | 22 +- .../Properties/Settings.Designer.cs | 326 --------------------- .../Properties/Settings.settings | 101 ------- src/Lucene.Net.Expressions/app.config | 108 ------- 5 files changed, 6 insertions(+), 589 deletions(-) diff --git a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs index 0bf7744..02e2b41 100644 --- a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs +++ b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs @@ -7,17 +7,13 @@ using Lucene.Net.Support; using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using JCG = J2N.Collections.Generic; using J2N; - -#if NETSTANDARD -using System.IO; -#else -using System.Configuration; -#endif +using System.Text; namespace Lucene.Net.Expressions.JS { @@ -166,11 +162,7 @@ namespace Lucene.Net.Expressions.JS /// <param name="functions">The set of functions to compile with</param> private JavascriptCompiler(string sourceText, IDictionary<string, MethodInfo> functions) { - if (sourceText == null) - { - throw new ArgumentNullException(); - } - this.sourceText = sourceText; + this.sourceText = sourceText ?? throw new ArgumentNullException(nameof(sourceText)); this.functions = functions; } @@ -657,31 +649,11 @@ namespace Lucene.Net.Expressions.JS private static IDictionary<string, string> GetDefaultSettings() { -#if NETSTANDARD var settings = new Dictionary<string, string>(); var type = typeof(JavascriptCompiler); - using (var reader = new StreamReader(type.FindAndGetManifestResourceStream(type.Name + ".properties"))) - { - 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]; - } - } + using (var reader = new StreamReader(type.FindAndGetManifestResourceStream(type.Name + ".properties"), Encoding.UTF8)) + settings.LoadProperties(reader); return settings; -#else - var props = Properties.Settings.Default; - - return props.Properties - .Cast<SettingsProperty>() - .ToDictionary(key => key.Name, value => props[value.Name].ToString()); -#endif - } private static void CheckFunction(MethodInfo method) diff --git a/src/Lucene.Net.Expressions/Lucene.Net.Expressions.csproj b/src/Lucene.Net.Expressions/Lucene.Net.Expressions.csproj index 853e8b2..3fe8003 100644 --- a/src/Lucene.Net.Expressions/Lucene.Net.Expressions.csproj +++ b/src/Lucene.Net.Expressions/Lucene.Net.Expressions.csproj @@ -35,10 +35,6 @@ </PropertyGroup> <ItemGroup> - <None Include="app.config" /> - </ItemGroup> - - <ItemGroup> <ProjectReference Include="..\Lucene.Net.Queries\Lucene.Net.Queries.csproj" /> </ItemGroup> @@ -58,24 +54,8 @@ <PackageReference Include="System.Reflection.TypeExtensions" Version="$(SystemReflectionTypeExtensionsPackageVersion)" /> </ItemGroup> - <ItemGroup Condition=" '$(TargetFramework)' != 'net45' "> - <Compile Remove="Properties\Settings.Designer.cs" /> - <EmbeddedResource Include="JS\JavascriptCompiler.properties" /> - </ItemGroup> - <ItemGroup> - <Compile Update="Properties\Settings.Designer.cs"> - <DesignTimeSharedInput>True</DesignTimeSharedInput> - <AutoGen>True</AutoGen> - <DependentUpon>Settings.settings</DependentUpon> - </Compile> - </ItemGroup> - - <ItemGroup> - <None Update="Properties\Settings.settings"> - <Generator>SettingsSingleFileGenerator</Generator> - <LastGenOutput>Settings.Designer.cs</LastGenOutput> - </None> + <EmbeddedResource Include="JS\JavascriptCompiler.properties" /> </ItemGroup> </Project> diff --git a/src/Lucene.Net.Expressions/Properties/Settings.Designer.cs b/src/Lucene.Net.Expressions/Properties/Settings.Designer.cs deleted file mode 100644 index 192142f..0000000 --- a/src/Lucene.Net.Expressions/Properties/Settings.Designer.cs +++ /dev/null @@ -1,326 +0,0 @@ -//------------------------------------------------------------------------------ -// <auto-generated> -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// </auto-generated> -//------------------------------------------------------------------------------ - -namespace Lucene.Net.Expressions.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.4.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Abs, 1")] - public string abs { - get { - return ((string)(this["abs"])); - } - set { - this["abs"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Acos, 1")] - public string acos { - get { - return ((string)(this["acos"])); - } - set { - this["acos"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Lucene.Net.Util.MathUtil, Acosh, 1")] - public string acosh { - get { - return ((string)(this["acosh"])); - } - set { - this["acosh"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Asin, 1")] - public string asin { - get { - return ((string)(this["asin"])); - } - set { - this["asin"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Lucene.Net.Util.MathUtil, Asinh, 1")] - public string asinh { - get { - return ((string)(this["asinh"])); - } - set { - this["asinh"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Atan, 1")] - public string atan { - get { - return ((string)(this["atan"])); - } - set { - this["atan"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Atan2, 2")] - public string atan2 { - get { - return ((string)(this["atan2"])); - } - set { - this["atan2"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Lucene.Net.Util.MathUtil, Atanh, 1")] - public string atanh { - get { - return ((string)(this["atanh"])); - } - set { - this["atanh"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Ceiling, 1")] - public string ceil { - get { - return ((string)(this["ceil"])); - } - set { - this["ceil"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Cos, 1")] - public string cos { - get { - return ((string)(this["cos"])); - } - set { - this["cos"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Cosh, 1")] - public string cosh { - get { - return ((string)(this["cosh"])); - } - set { - this["cosh"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Exp, 1")] - public string exp { - get { - return ((string)(this["exp"])); - } - set { - this["exp"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Floor, 1")] - public string floor { - get { - return ((string)(this["floor"])); - } - set { - this["floor"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Lucene.Net.Util.SloppyMath, Haversin, 4")] - public string haversin { - get { - return ((string)(this["haversin"])); - } - set { - this["haversin"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Log, 1")] - public string ln { - get { - return ((string)(this["ln"])); - } - set { - this["ln"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Log10, 1")] - public string log10 { - get { - return ((string)(this["log10"])); - } - set { - this["log10"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Lucene.Net.Util.MathUtil, Log, 2")] - public string logn { - get { - return ((string)(this["logn"])); - } - set { - this["logn"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Max, 2")] - public string max { - get { - return ((string)(this["max"])); - } - set { - this["max"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Min, 2")] - public string min { - get { - return ((string)(this["min"])); - } - set { - this["min"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Pow, 2")] - public string pow { - get { - return ((string)(this["pow"])); - } - set { - this["pow"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Sin, 1")] - public string sin { - get { - return ((string)(this["sin"])); - } - set { - this["sin"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Sinh, 1")] - public string sinh { - get { - return ((string)(this["sinh"])); - } - set { - this["sinh"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Sqrt, 1")] - public string sqrt { - get { - return ((string)(this["sqrt"])); - } - set { - this["sqrt"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Tan, 1")] - public string tan { - get { - return ((string)(this["tan"])); - } - set { - this["tan"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("System.Math, Tanh, 1")] - public string tanh { - get { - return ((string)(this["tanh"])); - } - set { - this["tanh"] = value; - } - } - } -} diff --git a/src/Lucene.Net.Expressions/Properties/Settings.settings b/src/Lucene.Net.Expressions/Properties/Settings.settings deleted file mode 100644 index ee9f4bd..0000000 --- a/src/Lucene.Net.Expressions/Properties/Settings.settings +++ /dev/null @@ -1,101 +0,0 @@ -<?xml version='1.0' encoding='utf-8'?> -<!-- - - 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. - ---> -<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Lucene.Net.Expressions.Properties" GeneratedClassName="Settings"> - <Profiles /> - <Settings> - <Setting Name="abs" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Abs, 1</Value> - </Setting> - <Setting Name="acos" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Acos, 1</Value> - </Setting> - <Setting Name="acosh" Type="System.String" Scope="User"> - <Value Profile="(Default)">Lucene.Net.Util.MathUtil, Acosh, 1</Value> - </Setting> - <Setting Name="asin" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Asin, 1</Value> - </Setting> - <Setting Name="asinh" Type="System.String" Scope="User"> - <Value Profile="(Default)">Lucene.Net.Util.MathUtil, Asinh, 1</Value> - </Setting> - <Setting Name="atan" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Atan, 1</Value> - </Setting> - <Setting Name="atan2" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Atan2, 2</Value> - </Setting> - <Setting Name="atanh" Type="System.String" Scope="User"> - <Value Profile="(Default)">Lucene.Net.Util.MathUtil, Atanh, 1</Value> - </Setting> - <Setting Name="ceil" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Ceiling, 1</Value> - </Setting> - <Setting Name="cos" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Cos, 1</Value> - </Setting> - <Setting Name="cosh" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Cosh, 1</Value> - </Setting> - <Setting Name="exp" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Exp, 1</Value> - </Setting> - <Setting Name="floor" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Floor, 1</Value> - </Setting> - <Setting Name="haversin" Type="System.String" Scope="User"> - <Value Profile="(Default)">Lucene.Net.Util.SloppyMath, Haversin, 4</Value> - </Setting> - <Setting Name="ln" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Log, 1</Value> - </Setting> - <Setting Name="log10" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Log10, 1</Value> - </Setting> - <Setting Name="logn" Type="System.String" Scope="User"> - <Value Profile="(Default)">Lucene.Net.Util.MathUtil, Log, 2</Value> - </Setting> - <Setting Name="max" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Max, 2</Value> - </Setting> - <Setting Name="min" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Min, 2</Value> - </Setting> - <Setting Name="pow" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Pow, 2</Value> - </Setting> - <Setting Name="sin" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Sin, 1</Value> - </Setting> - <Setting Name="sinh" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Sinh, 1</Value> - </Setting> - <Setting Name="sqrt" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Sqrt, 1</Value> - </Setting> - <Setting Name="tan" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Tan, 1</Value> - </Setting> - <Setting Name="tanh" Type="System.String" Scope="User"> - <Value Profile="(Default)">System.Math, Tanh, 1</Value> - </Setting> - </Settings> -</SettingsFile> diff --git a/src/Lucene.Net.Expressions/app.config b/src/Lucene.Net.Expressions/app.config deleted file mode 100644 index 97824d9..0000000 --- a/src/Lucene.Net.Expressions/app.config +++ /dev/null @@ -1,108 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<!-- - - 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. - ---> - -<configuration> - <configSections> - <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > - <section name="Lucene.Net.Expressions.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> - </sectionGroup> - </configSections> - <userSettings> - <Lucene.Net.Expressions.Properties.Settings> - <setting name="abs" serializeAs="String"> - <value>System.Math, Abs, 1</value> - </setting> - <setting name="acos" serializeAs="String"> - <value>System.Math, Acos, 1</value> - </setting> - <setting name="acosh" serializeAs="String"> - <value>Lucene.Net.Util.MathUtil, Acosh, 1</value> - </setting> - <setting name="asin" serializeAs="String"> - <value>System.Math, Asin, 1</value> - </setting> - <setting name="asinh" serializeAs="String"> - <value>Lucene.Net.Util.MathUtil, Asinh, 1</value> - </setting> - <setting name="atan" serializeAs="String"> - <value>System.Math, Atan, 1</value> - </setting> - <setting name="atan2" serializeAs="String"> - <value>System.Math, Atan2, 2</value> - </setting> - <setting name="atanh" serializeAs="String"> - <value>Lucene.Net.Util.MathUtil, Atanh, 1</value> - </setting> - <setting name="ceil" serializeAs="String"> - <value>System.Math, Ceiling, 1</value> - </setting> - <setting name="cos" serializeAs="String"> - <value>System.Math, Cos, 1</value> - </setting> - <setting name="cosh" serializeAs="String"> - <value>System.Math, Cosh, 1</value> - </setting> - <setting name="exp" serializeAs="String"> - <value>System.Math, Exp, 1</value> - </setting> - <setting name="floor" serializeAs="String"> - <value>System.Math, Floor, 1</value> - </setting> - <setting name="haversin" serializeAs="String"> - <value>Lucene.Net.Util.SloppyMath, Haversin, 4</value> - </setting> - <setting name="ln" serializeAs="String"> - <value>System.Math, Log, 1</value> - </setting> - <setting name="log10" serializeAs="String"> - <value>System.Math, Log10, 1</value> - </setting> - <setting name="logn" serializeAs="String"> - <value>Lucene.Net.Util.MathUtil, Log, 2</value> - </setting> - <setting name="max" serializeAs="String"> - <value>System.Math, Max, 2</value> - </setting> - <setting name="min" serializeAs="String"> - <value>System.Math, Min, 2</value> - </setting> - <setting name="pow" serializeAs="String"> - <value>System.Math, Pow, 2</value> - </setting> - <setting name="sin" serializeAs="String"> - <value>System.Math, Sin, 1</value> - </setting> - <setting name="sinh" serializeAs="String"> - <value>System.Math, Sinh, 1</value> - </setting> - <setting name="sqrt" serializeAs="String"> - <value>System.Math, Sqrt, 1</value> - </setting> - <setting name="tan" serializeAs="String"> - <value>System.Math, Tan, 1</value> - </setting> - <setting name="tanh" serializeAs="String"> - <value>System.Math, Tanh, 1</value> - </setting> - </Lucene.Net.Expressions.Properties.Settings> - </userSettings> -</configuration>
