Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
Constants.cs
Go to the documentation of this file.
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 
18 using System;
19 using Lucene.Net.Support;
20 using LucenePackage = Lucene.Net.LucenePackage;
21 
22 namespace Lucene.Net.Util
23 {
24 
26  public sealed class Constants
27  {
28  private Constants()
29  {
30  } // can't construct
31 
33  public static readonly System.String JAVA_VERSION = AppSettings.Get("java.version", "");
35  public static readonly bool JAVA_1_1 = JAVA_VERSION.StartsWith("1.1.");
37  public static readonly bool JAVA_1_2 = JAVA_VERSION.StartsWith("1.2.");
39  public static readonly bool JAVA_1_3 = JAVA_VERSION.StartsWith("1.3.");
40 
42  public static readonly System.String OS_NAME = GetEnvironmentVariable("OS","Windows_NT") ?? "Linux";
44  public static readonly bool LINUX = OS_NAME.StartsWith("Linux");
46  public static readonly bool WINDOWS = OS_NAME.StartsWith("Windows");
48  public static readonly bool SUN_OS = OS_NAME.StartsWith("SunOS");
49 
50  public static readonly System.String OS_ARCH = GetEnvironmentVariable("PROCESSOR_ARCHITECTURE","x86");
51  public static readonly System.String OS_VERSION = GetEnvironmentVariable("OS_VERSION", "?");
52  public static readonly System.String JAVA_VENDOR = AppSettings.Get("java.vendor", "");
53 
54  // NOTE: this logic may not be correct; if you know of a
55  // more reliable approach please raise it on java-dev!
56  public static bool JRE_IS_64BIT;
57 
58  // this method prevents inlining the final version constant in compiled
59  // classes,
60  // see: http://www.javaworld.com/community/node/3400
61  private static System.String Ident(System.String s)
62  {
63  return s.ToString();
64  }
65 
66  public static readonly System.String LUCENE_MAIN_VERSION = Ident("3.0.3");
67 
68  public static System.String LUCENE_VERSION="8.8.8.8";
69  static Constants()
70  {
71  if (IntPtr.Size == 8)
72  {
73  JRE_IS_64BIT = true;// 64 bit machine
74  }
75  else if (IntPtr.Size == 4)
76  {
77  JRE_IS_64BIT = false;// 32 bit machine
78  }
79 
80  try
81  {
82  LUCENE_VERSION = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
83  }
84  catch (System.Security.SecurityException) //Ignore in medium trust.
85  {
86  }
87 
88  }
89 
90  #region MEDIUM-TRUST Support
91  static string GetEnvironmentVariable(string variable, string defaultValueOnSecurityException)
92  {
93  try
94  {
95  if (variable == "OS_VERSION") return System.Environment.OSVersion.ToString();
96 
97  return System.Environment.GetEnvironmentVariable(variable);
98  }
99  catch (System.Security.SecurityException)
100  {
101  return defaultValueOnSecurityException;
102  }
103 
104  }
105  #endregion
106  }
107 }