You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/02/08 14:32:26 UTC

[47/53] [abbrv] lucenenet git commit: Lucene.Net.Core.Util.Constants refactor: Renamed JAVA_VERSION > RUNTIME_VERSION, JAVA_VENDOR > RUNTIME_VENDOR, JRE_IS_64BIT > RUNTIME_IS_64BIT. Commented unused JVM_ constants. Refactored RUNTIME_VERSION to pull the

Lucene.Net.Core.Util.Constants refactor: Renamed JAVA_VERSION > RUNTIME_VERSION, JAVA_VENDOR > RUNTIME_VENDOR, JRE_IS_64BIT > RUNTIME_IS_64BIT. Commented unused JVM_ constants. Refactored RUNTIME_VERSION to pull the correct setting from System.Environment.Version in .NET Framework and parsed from RuntimeInformation.FrameworkDescription in .NET Core. Commented unused JVM_INFO_STRING constant in RamUsageEstimator.


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

Branch: refs/heads/api-work
Commit: 45bb8132c3f9385f9caf9d6818f880090599b472
Parents: aef5205
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Wed Feb 8 20:45:35 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Wed Feb 8 21:08:25 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Index/IndexWriter.cs        |  4 +-
 src/Lucene.Net.Core/Store/FSDirectory.cs        |  2 +-
 src/Lucene.Net.Core/Store/MMapDirectory.cs      |  2 +-
 src/Lucene.Net.Core/Util/ArrayUtil.cs           |  2 +-
 src/Lucene.Net.Core/Util/Constants.cs           | 77 +++++++++++++++-----
 src/Lucene.Net.Core/Util/Fst/FST.cs             |  2 +-
 src/Lucene.Net.Core/Util/RamUsageEstimator.cs   | 21 +++---
 .../core/Util/TestRamUsageEstimator.cs          |  2 +-
 8 files changed, 76 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Core/Index/IndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/IndexWriter.cs b/src/Lucene.Net.Core/Index/IndexWriter.cs
index 2155239..3bc5253 100644
--- a/src/Lucene.Net.Core/Index/IndexWriter.cs
+++ b/src/Lucene.Net.Core/Index/IndexWriter.cs
@@ -4846,8 +4846,8 @@ namespace Lucene.Net.Index
             diagnostics["os"] = Constants.OS_NAME;
             diagnostics["os.arch"] = Constants.OS_ARCH;
             diagnostics["os.version"] = Constants.OS_VERSION;
-            diagnostics["java.version"] = Constants.JAVA_VERSION;
-            diagnostics["java.vendor"] = Constants.JAVA_VENDOR;
+            diagnostics["java.version"] = Constants.RUNTIME_VERSION;
+            diagnostics["java.vendor"] = Constants.RUNTIME_VENDOR;
             diagnostics["timestamp"] = Convert.ToString((DateTime.Now));
             if (details != null)
             {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Core/Store/FSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/FSDirectory.cs b/src/Lucene.Net.Core/Store/FSDirectory.cs
index 8a53c23..538d484 100644
--- a/src/Lucene.Net.Core/Store/FSDirectory.cs
+++ b/src/Lucene.Net.Core/Store/FSDirectory.cs
@@ -177,7 +177,7 @@ namespace Lucene.Net.Store
         /// </summary>
         public static FSDirectory Open(DirectoryInfo path, LockFactory lockFactory)
         {
-            if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.JRE_IS_64BIT &&
+            if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.RUNTIME_IS_64BIT &&
                 MMapDirectory.UNMAP_SUPPORTED)
             {
                 return new MMapDirectory(path, lockFactory);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Core/Store/MMapDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Store/MMapDirectory.cs b/src/Lucene.Net.Core/Store/MMapDirectory.cs
index bc31b73..4bd2868 100644
--- a/src/Lucene.Net.Core/Store/MMapDirectory.cs
+++ b/src/Lucene.Net.Core/Store/MMapDirectory.cs
@@ -77,7 +77,7 @@ namespace Lucene.Net.Store
         /// <summary>
         /// Default max chunk size. </summary>
         /// <seealso cref= #MMapDirectory(File, LockFactory, int) </seealso>
-        public static readonly int DEFAULT_MAX_BUFF = Constants.JRE_IS_64BIT ? (1 << 30) : (1 << 28);
+        public static readonly int DEFAULT_MAX_BUFF = Constants.RUNTIME_IS_64BIT ? (1 << 30) : (1 << 28);
 
         private readonly int chunkSizePower;
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Core/Util/ArrayUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/ArrayUtil.cs b/src/Lucene.Net.Core/Util/ArrayUtil.cs
index 9fc79e0..2d9ba0c 100644
--- a/src/Lucene.Net.Core/Util/ArrayUtil.cs
+++ b/src/Lucene.Net.Core/Util/ArrayUtil.cs
@@ -210,7 +210,7 @@ namespace Lucene.Net.Util
                 return int.MaxValue;
             }
 
-            if (Constants.JRE_IS_64BIT)
+            if (Constants.RUNTIME_IS_64BIT)
             {
                 // round up to 8 byte alignment in 64bit env
                 switch (bytesPerElement)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Core/Util/Constants.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Constants.cs b/src/Lucene.Net.Core/Util/Constants.cs
index 4bfc54a..2b853e8 100644
--- a/src/Lucene.Net.Core/Util/Constants.cs
+++ b/src/Lucene.Net.Core/Util/Constants.cs
@@ -34,17 +34,31 @@ namespace Lucene.Net.Util
         {
         }
 
+        // LUCENENET NOTE: IMPORTANT - this line must be placed before RUNTIME_VERSION so it can be parsed.
+        private static Regex VERSION_PARSER = new Regex(@"(\d+\.\d+\.\d+\.\d+)", RegexOptions.Compiled);
+
         /// <summary>
-        /// The value of <tt>System.getProperty("java.version")</tt>. * </summary>
-        public static readonly string JAVA_VERSION = AppSettings.Get("java.version", "");
+#if NETSTANDARD
+        /// The value of the version parsed from <see cref="RuntimeInformation.FrameworkDescription"/>.
+#else
+        /// The value of <see cref="Environment.Version"/>.
+#endif
+        /// <para/>
+        /// NOTE: This was JAVA_VERSION in Lucene
+        /// </summary>
+        public static readonly string RUNTIME_VERSION = GetEnvironmentVariable("RUNTIME_VERSION", "?");
 
-        public static readonly string JAVA_VENDOR = AppSettings.Get("java.vendor", "");
-        public static readonly string JVM_VENDOR = AppSettings.Get("java.vm.vendor", "");
-        public static readonly string JVM_VERSION = AppSettings.Get("java.vm.version", "");
-        public static readonly string JVM_NAME = AppSettings.Get("java.vm.name", "");
 
         /// <summary>
-        /// The value of <tt>System.getProperty("os.name")</tt>. * </summary>
+        /// NOTE: This was JAVA_VENDOR in Lucene
+        /// </summary>
+        public static readonly string RUNTIME_VENDOR = "Microsoft"; // AppSettings.Get("java.vendor", "");
+        //public static readonly string JVM_VENDOR = AppSettings.Get("java.vm.vendor", "");
+        //public static readonly string JVM_VERSION = AppSettings.Get("java.vm.version", "");
+        //public static readonly string JVM_NAME = AppSettings.Get("java.vm.name", "");
+
+        /// <summary>
+        /// The value of <see cref="Environment.GetEnvironmentVariable(string)"/> with parameter "OS".</summary>
         public static readonly string OS_NAME = GetEnvironmentVariable("OS", "Windows_NT") ?? "Linux";
 
         /// <summary>
@@ -70,27 +84,29 @@ namespace Lucene.Net.Util
         public static readonly string OS_ARCH = GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", "x86");
         public static readonly string OS_VERSION = GetEnvironmentVariable("OS_VERSION", "?");
 
-        [Obsolete("We are not running on Java for heavens sake")]
-        public static readonly bool JRE_IS_MINIMUM_JAVA6 = (bool)new bool?(true); // prevent inlining in foreign class files
-
-        [Obsolete("We are not running on Java for heavens sake")]
-        public static readonly bool JRE_IS_MINIMUM_JAVA7 = (bool)new bool?(true); // prevent inlining in foreign class files
+        //[Obsolete("We are not running on Java for heavens sake")]
+        //public static readonly bool JRE_IS_MINIMUM_JAVA6 = (bool)new bool?(true); // prevent inlining in foreign class files
 
-        [Obsolete("We are not running on Java for heavens sake")]
-        public static readonly bool JRE_IS_MINIMUM_JAVA8;
+        //[Obsolete("We are not running on Java for heavens sake")]
+        //public static readonly bool JRE_IS_MINIMUM_JAVA7 = (bool)new bool?(true); // prevent inlining in foreign class files
 
         //[Obsolete("We are not running on Java for heavens sake")]
-        public static readonly bool JRE_IS_64BIT; // LUCENENET NOTE: We still need this constant to indicate 64 bit runtime.
+        //public static readonly bool JRE_IS_MINIMUM_JAVA8;
+
+        /// <summary>
+        /// NOTE: This was JRE_IS_64BIT in Lucene
+        /// </summary>
+        public static readonly bool RUNTIME_IS_64BIT; // LUCENENET NOTE: We still need this constant to indicate 64 bit runtime.
 
         static Constants()
         {
             if (IntPtr.Size == 8)
             {
-                JRE_IS_64BIT = true;// 64 bit machine
+                RUNTIME_IS_64BIT = true;// 64 bit machine
             }
             else if (IntPtr.Size == 4)
             {
-                JRE_IS_64BIT = false;// 32 bit machine
+                RUNTIME_IS_64BIT = false;// 32 bit machine
             }
 
             try
@@ -130,7 +146,7 @@ namespace Lucene.Net.Util
                 }
               }
             }
-            JRE_IS_64BIT = is64Bit;
+            RUNTIME_IS_64BIT = is64Bit;
 
             // this method only exists in Java 8:
             bool v8 = true;
@@ -190,8 +206,9 @@ namespace Lucene.Net.Util
         }
 
         private static Regex MAIN_VERSION_WITHOUT_ALPHA_BETA = new Regex("\\.", RegexOptions.Compiled);
+        
 
-        #region MEDIUM-TRUST Support
+#region MEDIUM-TRUST Support
 
         private static string GetEnvironmentVariable(string variable, string defaultValueOnSecurityException)
         {
@@ -208,10 +225,20 @@ namespace Lucene.Net.Util
 				
 #if NETSTANDARD
                 if (variable == "PROCESSOR_ARCHITECTURE") {
+                    
                     return RuntimeInformation.OSArchitecture.ToString();
                 }
 #endif
 
+                if (variable == "RUNTIME_VERSION")
+                {
+#if NETSTANDARD
+                    return ExtractString(RuntimeInformation.FrameworkDescription, VERSION_PARSER);
+#else
+                    return Environment.Version.ToString();
+#endif
+                }
+
                 return System.Environment.GetEnvironmentVariable(variable);
             }
             catch (System.Security.SecurityException)
@@ -221,5 +248,17 @@ namespace Lucene.Net.Util
         }
 
 #endregion MEDIUM-TRUST Support
+
+        // LUCENENET TODO: Move to Support ?
+        /// <summary>
+        /// Extracts the first group matched with the regex as a new string.
+        /// </summary>
+        /// <param name="input">The string to examine</param>
+        /// <param name="pattern">A regex object to use to extract the string</param>
+        private static string ExtractString(string input, Regex pattern)
+        {
+            Match m = pattern.Match(input);
+            return (m.Groups.Count > 1) ? m.Groups[1].Value : string.Empty;
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Core/Util/Fst/FST.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/Fst/FST.cs b/src/Lucene.Net.Core/Util/Fst/FST.cs
index 8e187a0..88d4d4c 100644
--- a/src/Lucene.Net.Core/Util/Fst/FST.cs
+++ b/src/Lucene.Net.Core/Util/Fst/FST.cs
@@ -2070,7 +2070,7 @@ namespace Lucene.Net.Util.Fst
     /// </summary>
     public sealed class FST
     {
-        public static readonly int DEFAULT_MAX_BLOCK_BITS = Constants.JRE_IS_64BIT ? 30 : 28;
+        public static readonly int DEFAULT_MAX_BLOCK_BITS = Constants.RUNTIME_IS_64BIT ? 30 : 28;
 
         public FST()
         { }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Core/Util/RamUsageEstimator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/RamUsageEstimator.cs b/src/Lucene.Net.Core/Util/RamUsageEstimator.cs
index 1f5aaf5..589e10c 100644
--- a/src/Lucene.Net.Core/Util/RamUsageEstimator.cs
+++ b/src/Lucene.Net.Core/Util/RamUsageEstimator.cs
@@ -36,9 +36,9 @@ namespace Lucene.Net.Util
     /// @lucene.internal </seealso>
     public sealed class RamUsageEstimator
     {
-        /// <summary>
-        /// JVM info string for debugging and reports. </summary>
-        public static readonly string JVM_INFO_STRING;
+        ///// <summary>
+        ///// JVM info string for debugging and reports. </summary>
+        //public static readonly string JVM_INFO_STRING; // LUCENENET specific - this is not being used
 
         /// <summary>
         /// One kilobyte bytes. </summary>
@@ -124,12 +124,12 @@ namespace Lucene.Net.Util
 
             // Initialize empirically measured defaults. We'll modify them to the current
             // JVM settings later on if possible.
-            int referenceSize = Constants.JRE_IS_64BIT ? 8 : 4;
-            int objectHeader = Constants.JRE_IS_64BIT ? 16 : 8;
+            int referenceSize = Constants.RUNTIME_IS_64BIT ? 8 : 4;
+            int objectHeader = Constants.RUNTIME_IS_64BIT ? 16 : 8;
             // The following is objectHeader + NUM_BYTES_INT32, but aligned (object alignment)
             // so on 64 bit JVMs it'll be align(16 + 4, @8) = 24.
-            int arrayHeader = Constants.JRE_IS_64BIT ? 24 : 12;
-            int objectAlignment = Constants.JRE_IS_64BIT ? 8 : 4;
+            int arrayHeader = Constants.RUNTIME_IS_64BIT ? 24 : 12;
+            int objectAlignment = Constants.RUNTIME_IS_64BIT ? 8 : 4;
 
 
             /* LUCENENET TODO
@@ -163,8 +163,8 @@ namespace Lucene.Net.Util
 
             // "best guess" based on reference size. We will attempt to modify
             // these to exact values if there is supported infrastructure.
-            objectHeader = Constants.JRE_IS_64BIT ? (8 + referenceSize) : 8;
-		    arrayHeader = Constants.JRE_IS_64BIT ? (8 + 2 * referenceSize) : 12;
+            objectHeader = Constants.RUNTIME_IS_64BIT ? (8 + referenceSize) : 8;
+		    arrayHeader = Constants.RUNTIME_IS_64BIT ? (8 + 2 * referenceSize) : 12;
 
             /* LUCENENET TODO
              
@@ -234,7 +234,8 @@ namespace Lucene.Net.Util
 
             NUM_BYTES_OBJECT_ALIGNMENT = objectAlignment;
 
-            JVM_INFO_STRING = "[JVM: " + Constants.JVM_NAME + ", " + Constants.JVM_VERSION + ", " + Constants.JVM_VENDOR + ", " + Constants.JAVA_VENDOR + ", " + Constants.JAVA_VERSION + "]";
+            // LUCENENET specific - this is not being used
+            //JVM_INFO_STRING = "[JVM: " + Constants.JVM_NAME + ", " + Constants.JVM_VERSION + ", " + Constants.JVM_VENDOR + ", " + Constants.JAVA_VENDOR + ", " + Constants.JAVA_VERSION + "]";
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/45bb8132/src/Lucene.Net.Tests/core/Util/TestRamUsageEstimator.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/core/Util/TestRamUsageEstimator.cs b/src/Lucene.Net.Tests/core/Util/TestRamUsageEstimator.cs
index b08739d..dc6fb9b 100644
--- a/src/Lucene.Net.Tests/core/Util/TestRamUsageEstimator.cs
+++ b/src/Lucene.Net.Tests/core/Util/TestRamUsageEstimator.cs
@@ -109,7 +109,7 @@ namespace Lucene.Net.Util
             //}
 
             Assert.IsTrue(RamUsageEstimator.NUM_BYTES_OBJECT_REF == 4 || RamUsageEstimator.NUM_BYTES_OBJECT_REF == 8);
-            if (!Constants.JRE_IS_64BIT)
+            if (!Constants.RUNTIME_IS_64BIT)
             {
                 assertEquals("For 32bit JVMs, reference size must always be 4?", 4, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
             }