PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/redistributable/third-party/Lucene.Net/src/Lucene.Net/Util/Constants.cs

https://github.com/DevExperience/ONLYOFFICE-Server
C# | 108 lines | 55 code | 17 blank | 36 comment | 7 complexity | f3c835c2c0481d52e084419fe114c6ea MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. using System;
  18. using LucenePackage = Lucene.Net.LucenePackage;
  19. namespace Lucene.Net.Util
  20. {
  21. /// <summary> Some useful constants.
  22. ///
  23. ///
  24. /// </summary>
  25. /// <version> $Id: Constants.java 828327 2009-10-22 06:47:40Z uschindler $
  26. ///
  27. /// </version>
  28. public sealed class Constants
  29. {
  30. private Constants()
  31. {
  32. } // can't construct
  33. /// <summary>The value of <tt>System.getProperty("java.version")</tt>. *</summary>
  34. public static readonly System.String JAVA_VERSION = SupportClass.AppSettings.Get("java.version", "");
  35. /// <summary>True iff this is Java version 1.1. </summary>
  36. public static readonly bool JAVA_1_1 = JAVA_VERSION.StartsWith("1.1.");
  37. /// <summary>True iff this is Java version 1.2. </summary>
  38. public static readonly bool JAVA_1_2 = JAVA_VERSION.StartsWith("1.2.");
  39. /// <summary>True iff this is Java version 1.3. </summary>
  40. public static readonly bool JAVA_1_3 = JAVA_VERSION.StartsWith("1.3.");
  41. /// <summary>The value of <tt>System.getProperty("os.name")</tt>. *</summary>
  42. public static readonly System.String OS_NAME = GetEnvironmentVariable("OS","Windows_NT") ?? "Linux";
  43. /// <summary>True iff running on Linux. </summary>
  44. public static readonly bool LINUX = OS_NAME.StartsWith("Linux");
  45. /// <summary>True iff running on Windows. </summary>
  46. public static readonly bool WINDOWS = OS_NAME.StartsWith("Windows");
  47. /// <summary>True iff running on SunOS. </summary>
  48. public static readonly bool SUN_OS = OS_NAME.StartsWith("SunOS");
  49. public static readonly System.String OS_ARCH = GetEnvironmentVariable("PROCESSOR_ARCHITECTURE","x86");
  50. public static readonly System.String OS_VERSION = GetEnvironmentVariable("OS_VERSION", "?");
  51. public static readonly System.String JAVA_VENDOR = SupportClass.AppSettings.Get("java.vendor", "");
  52. // NOTE: this logic may not be correct; if you know of a
  53. // more reliable approach please raise it on java-dev!
  54. public static bool JRE_IS_64BIT;
  55. // this method prevents inlining the final version constant in compiled
  56. // classes,
  57. // see: http://www.javaworld.com/community/node/3400
  58. private static System.String Ident(System.String s)
  59. {
  60. return s.ToString();
  61. }
  62. public static readonly System.String LUCENE_MAIN_VERSION = Ident("2.9.2");
  63. public static System.String LUCENE_VERSION;
  64. static Constants()
  65. {
  66. if (IntPtr.Size == 8)
  67. {
  68. JRE_IS_64BIT = true;// 64 bit machine
  69. }
  70. else if (IntPtr.Size == 4)
  71. {
  72. JRE_IS_64BIT = false;// 32 bit machine
  73. }
  74. LUCENE_VERSION = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  75. }
  76. #region MEDIUM-TRUST Support
  77. static string GetEnvironmentVariable(string variable, string defaultValueOnSecurityException)
  78. {
  79. try
  80. {
  81. if (variable == "OS_VERSION") return System.Environment.OSVersion.ToString();
  82. return System.Environment.GetEnvironmentVariable(variable);
  83. }
  84. catch (System.Security.SecurityException)
  85. {
  86. return defaultValueOnSecurityException;
  87. }
  88. }
  89. #endregion
  90. }
  91. }