PageRenderTime 74ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/src/core/Util/Constants.cs

https://github.com/DevChive/lucene.net
C# | 107 lines | 62 code | 15 blank | 30 comment | 7 complexity | 9d4582a88f4bb838e82de707bfe4afcf MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  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 Lucene.Net.Support;
  19. using LucenePackage = Lucene.Net.LucenePackage;
  20. namespace Lucene.Net.Util
  21. {
  22. /// <summary> Some useful constants.</summary>
  23. public sealed class Constants
  24. {
  25. private Constants()
  26. {
  27. } // can't construct
  28. /// <summary>The value of <tt>System.getProperty("java.version")</tt>. *</summary>
  29. public static readonly System.String JAVA_VERSION = AppSettings.Get("java.version", "");
  30. /// <summary>True iff this is Java version 1.1. </summary>
  31. public static readonly bool JAVA_1_1 = JAVA_VERSION.StartsWith("1.1.");
  32. /// <summary>True iff this is Java version 1.2. </summary>
  33. public static readonly bool JAVA_1_2 = JAVA_VERSION.StartsWith("1.2.");
  34. /// <summary>True iff this is Java version 1.3. </summary>
  35. public static readonly bool JAVA_1_3 = JAVA_VERSION.StartsWith("1.3.");
  36. /// <summary>The value of <tt>System.getProperty("os.name")</tt>. *</summary>
  37. public static readonly System.String OS_NAME = GetEnvironmentVariable("OS","Windows_NT") ?? "Linux";
  38. /// <summary>True iff running on Linux. </summary>
  39. public static readonly bool LINUX = OS_NAME.StartsWith("Linux");
  40. /// <summary>True iff running on Windows. </summary>
  41. public static readonly bool WINDOWS = OS_NAME.StartsWith("Windows");
  42. /// <summary>True iff running on SunOS. </summary>
  43. public static readonly bool SUN_OS = OS_NAME.StartsWith("SunOS");
  44. public static readonly System.String OS_ARCH = GetEnvironmentVariable("PROCESSOR_ARCHITECTURE","x86");
  45. public static readonly System.String OS_VERSION = GetEnvironmentVariable("OS_VERSION", "?");
  46. public static readonly System.String JAVA_VENDOR = AppSettings.Get("java.vendor", "");
  47. // NOTE: this logic may not be correct; if you know of a
  48. // more reliable approach please raise it on java-dev!
  49. public static bool JRE_IS_64BIT;
  50. // this method prevents inlining the final version constant in compiled
  51. // classes,
  52. // see: http://www.javaworld.com/community/node/3400
  53. private static System.String Ident(System.String s)
  54. {
  55. return s.ToString();
  56. }
  57. public static readonly System.String LUCENE_MAIN_VERSION = Ident("3.0.3");
  58. public static System.String LUCENE_VERSION="8.8.8.8";
  59. static Constants()
  60. {
  61. if (IntPtr.Size == 8)
  62. {
  63. JRE_IS_64BIT = true;// 64 bit machine
  64. }
  65. else if (IntPtr.Size == 4)
  66. {
  67. JRE_IS_64BIT = false;// 32 bit machine
  68. }
  69. try
  70. {
  71. LUCENE_VERSION = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  72. }
  73. catch (System.Security.SecurityException) //Ignore in medium trust.
  74. {
  75. }
  76. }
  77. #region MEDIUM-TRUST Support
  78. static string GetEnvironmentVariable(string variable, string defaultValueOnSecurityException)
  79. {
  80. try
  81. {
  82. if (variable == "OS_VERSION") return System.Environment.OSVersion.ToString();
  83. return System.Environment.GetEnvironmentVariable(variable);
  84. }
  85. catch (System.Security.SecurityException)
  86. {
  87. return defaultValueOnSecurityException;
  88. }
  89. }
  90. #endregion
  91. }
  92. }