SWEEP: Replaced all calls to Environment.GetEnvironmentVariable and Environment.SetEnvironmentVariable calls with SystemProperties.GetProperty and SystemProperties.SetProperty respectively.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/caa61a37 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/caa61a37 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/caa61a37 Branch: refs/heads/master Commit: caa61a37d2c7494e29a52073ce57939200f6d3c1 Parents: 81e464d Author: Shad Storhaug <[email protected]> Authored: Mon Sep 18 23:36:14 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Mon Sep 18 23:36:14 2017 +0700 ---------------------------------------------------------------------- .../Dict/BinaryDictionary.cs | 18 +----------------- .../AnalyzerProfile.cs | 18 ++---------------- .../Egothor.Stemmer/Compile.cs | 16 +--------------- .../Egothor.Stemmer/DiffIt.cs | 16 +--------------- .../Util/TestRuleSetupAndRestoreClassEnv.cs | 4 ++-- src/Lucene.Net/Store/LockVerifyServer.cs | 5 +++-- src/Lucene.Net/Support/SystemProperties.cs | 4 +--- src/Lucene.Net/Util/StringHelper.cs | 10 +--------- 8 files changed, 12 insertions(+), 79 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs b/src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs index dd011cd..66f3a68 100644 --- a/src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs +++ b/src/Lucene.Net.Analysis.Kuromoji/Dict/BinaryDictionary.cs @@ -54,7 +54,7 @@ namespace Lucene.Net.Analysis.Ja.Dict static BinaryDictionary() { - string currentPath = GetSystemProperty("kuromoji.data.dir", + string currentPath = SystemProperties.GetProperty("kuromoji.data.dir", #if NETSTANDARD1_5 System.AppContext.BaseDirectory #else @@ -206,22 +206,6 @@ namespace Lucene.Net.Analysis.Ja.Dict return new FileStream(path, FileMode.Open, FileAccess.Read); } - // LUCENENET specific helper to load environment variables and ignore security exceptions - private static string GetSystemProperty(string property, string defaultValue) - { - string setting; - try - { - setting = Environment.GetEnvironmentVariable(property); - } - catch (SecurityException) - { - setting = null; - } - - return (setting == null) ? defaultValue : setting; - } - public virtual void LookupWordIds(int sourceId, Int32sRef @ref) { @ref.Int32s = targetMap; http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs b/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs index 208d564..285dd8a 100644 --- a/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs +++ b/src/Lucene.Net.Analysis.SmartCn/AnalyzerProfile.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Security; +using Lucene.Net.Support; namespace Lucene.Net.Analysis.Cn.Smart { @@ -68,7 +69,7 @@ namespace Lucene.Net.Analysis.Cn.Smart // Try the system propertyï¼-Danalysis.data.dir=/path/to/analysis-data //ANALYSIS_DATA_DIR = System.getProperty("analysis.data.dir", ""); - ANALYSIS_DATA_DIR = GetSystemProperty("analysis.data.dir", ""); + ANALYSIS_DATA_DIR = SystemProperties.GetProperty("analysis.data.dir", ""); if (ANALYSIS_DATA_DIR.Length != 0) return; @@ -165,20 +166,5 @@ namespace Lucene.Net.Analysis.Cn.Smart // return ""; // } //} - - private static string GetSystemProperty(string property, string defaultValue) - { - string setting; - try - { - setting = Environment.GetEnvironmentVariable(property); - } - catch (SecurityException) - { - setting = null; - } - - return (setting == null) ? defaultValue : setting; - } } } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/Compile.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/Compile.cs b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/Compile.cs index decdd7e..0665b3f 100644 --- a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/Compile.cs +++ b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/Compile.cs @@ -113,22 +113,8 @@ namespace Egothor.Stemmer qq++; } - string charset = null; + string charset = SystemProperties.GetProperty("egothor.stemmer.charset", "UTF-8"); var stemmerTables = new List<string>(); - try - { - charset = System.Environment.GetEnvironmentVariable("egothor.stemmer.charset"); - } - catch - { - } - finally - { - if (string.IsNullOrEmpty(charset)) - { - charset = "UTF-8"; - } - } // LUCENENET specific // command line argument overrides environment variable or default, if supplied http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/DiffIt.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/DiffIt.cs b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/DiffIt.cs index 62937a3..54218dc 100644 --- a/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/DiffIt.cs +++ b/src/Lucene.Net.Analysis.Stempel/Egothor.Stemmer/DiffIt.cs @@ -100,22 +100,8 @@ namespace Egothor.Stemmer int rep = Get(2, args[0]); int nop = Get(3, args[0]); - string charset = null; + string charset = SystemProperties.GetProperty("egothor.stemmer.charset", "UTF-8"); var stemmerTables = new List<string>(); - try - { - charset = System.Environment.GetEnvironmentVariable("egothor.stemmer.charset"); - } - catch - { - } - finally - { - if (string.IsNullOrEmpty(charset)) - { - charset = "UTF-8"; - } - } // LUCENENET specific // command line argument overrides environment variable or default, if supplied http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs index 3b0b325..4f6d36e 100644 --- a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs +++ b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs @@ -248,8 +248,8 @@ namespace Lucene.Net.Util Codec.Default = codec; // Initialize locale/ timezone. - string testLocale = System.Environment.GetEnvironmentVariable("tests.locale") ?? "random"; - string testTimeZone = System.Environment.GetEnvironmentVariable("tests.timezone") ?? "random"; + string testLocale = SystemProperties.GetProperty("tests.locale", "random"); + string testTimeZone = SystemProperties.GetProperty("tests.timezone", "random"); // Always pick a random one for consistency (whether tests.locale was specified or not). savedLocale = CultureInfo.CurrentCulture; http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net/Store/LockVerifyServer.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/LockVerifyServer.cs b/src/Lucene.Net/Store/LockVerifyServer.cs index aa856be..6963fd2 100644 --- a/src/Lucene.Net/Store/LockVerifyServer.cs +++ b/src/Lucene.Net/Store/LockVerifyServer.cs @@ -1,3 +1,4 @@ +using Lucene.Net.Support; using Lucene.Net.Support.Threading; using System; using System.Globalization; @@ -65,7 +66,7 @@ namespace Lucene.Net.Store Console.WriteLine("Listening on " + ((IPEndPoint)s.LocalEndPoint).Port.ToString() + "..."); // we set the port as a sysprop, so the ANT task can read it. For that to work, this server must run in-process: - System.Environment.SetEnvironmentVariable("lockverifyserver.port", ((IPEndPoint)s.LocalEndPoint).Port.ToString()); + SystemProperties.SetProperty("lockverifyserver.port", ((IPEndPoint)s.LocalEndPoint).Port.ToString()); object localLock = new object(); int[] lockedID = new int[1]; @@ -91,7 +92,7 @@ namespace Lucene.Net.Store } // cleanup sysprop - System.Environment.SetEnvironmentVariable("lockverifyserver.port", null); + SystemProperties.SetProperty("lockverifyserver.port", null); Console.WriteLine("Server terminated."); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net/Support/SystemProperties.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/SystemProperties.cs b/src/Lucene.Net/Support/SystemProperties.cs index 7661eaa..32e31c9 100644 --- a/src/Lucene.Net/Support/SystemProperties.cs +++ b/src/Lucene.Net/Support/SystemProperties.cs @@ -1,6 +1,4 @@ -// LUCENENET TODO: API: Replace all references to Environment.GetEnvironmentVariable() with this (safer) class. - -/* +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/caa61a37/src/Lucene.Net/Util/StringHelper.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Util/StringHelper.cs b/src/Lucene.Net/Util/StringHelper.cs index a728c2c..8d30354 100644 --- a/src/Lucene.Net/Util/StringHelper.cs +++ b/src/Lucene.Net/Util/StringHelper.cs @@ -196,15 +196,7 @@ namespace Lucene.Net.Util { if (good_fast_hash_seed == 0) { - string prop; - try - { - prop = Environment.GetEnvironmentVariable("tests.seed"); - } - catch (System.Security.SecurityException) - { - prop = null; - } + string prop = SystemProperties.GetProperty("tests.seed", null); if (prop != null) {
