pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / util / Constants.java
1 package org.apache.lucene.util;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import org.apache.lucene.LucenePackage;
21
22 /**
23  * Some useful constants.
24  **/
25
26 public final class Constants {
27   private Constants() {}                          // can't construct
28
29   /** The value of <tt>System.getProperty("java.version")<tt>. **/
30   public static final String JAVA_VERSION = System.getProperty("java.version");
31  
32   /** True iff this is Java version 1.1.
33    * @deprecated This constant is useless since Lucene is on Java 5 */
34   @Deprecated
35   public static final boolean JAVA_1_1 = JAVA_VERSION.startsWith("1.1.");
36   /** True iff this is Java version 1.2.
37    * @deprecated This constant is useless since Lucene is on Java 5 */
38   @Deprecated
39   public static final boolean JAVA_1_2 = JAVA_VERSION.startsWith("1.2.");
40   /** True iff this is Java version 1.3.
41    * @deprecated This constant is useless since Lucene is on Java 5 */
42   @Deprecated
43   public static final boolean JAVA_1_3 = JAVA_VERSION.startsWith("1.3.");
44
45   /** The value of <tt>System.getProperty("os.name")<tt>. **/
46   public static final String OS_NAME = System.getProperty("os.name");
47   /** True iff running on Linux. */
48   public static final boolean LINUX = OS_NAME.startsWith("Linux");
49   /** True iff running on Windows. */
50   public static final boolean WINDOWS = OS_NAME.startsWith("Windows");
51   /** True iff running on SunOS. */
52   public static final boolean SUN_OS = OS_NAME.startsWith("SunOS");
53   /** True iff running on Mac OS X */
54   public static final boolean MAC_OS_X = OS_NAME.startsWith("Mac OS X");
55
56   public static final String OS_ARCH = System.getProperty("os.arch");
57   public static final String OS_VERSION = System.getProperty("os.version");
58   public static final String JAVA_VENDOR = System.getProperty("java.vendor");
59
60   public static final boolean JRE_IS_64BIT;
61   public static final boolean JRE_IS_MINIMUM_JAVA6;
62   public static final boolean JRE_IS_MINIMUM_JAVA7;
63   static {
64     // NOTE: this logic may not be correct; if you know of a
65     // more reliable approach please raise it on java-dev!
66     final String x = System.getProperty("sun.arch.data.model");
67     if (x != null) {
68       JRE_IS_64BIT = x.indexOf("64") != -1;
69     } else {
70       if (OS_ARCH != null && OS_ARCH.indexOf("64") != -1) {
71         JRE_IS_64BIT = true;
72       } else {
73         JRE_IS_64BIT = false;
74       }
75     }
76
77     // this method only exists in Java 6:
78     boolean v6 = true;
79     try {
80       String.class.getMethod("isEmpty");
81     } catch (NoSuchMethodException nsme) {
82       v6 = false;
83     }
84     JRE_IS_MINIMUM_JAVA6 = v6;
85     
86     // this method only exists in Java 7:
87     boolean v7 = true;
88     try {
89       Throwable.class.getMethod("getSuppressed");
90     } catch (NoSuchMethodException nsme) {
91       v7 = false;
92     }
93     JRE_IS_MINIMUM_JAVA7 = v7;
94   }
95
96   // this method prevents inlining the final version constant in compiled classes,
97   // see: http://www.javaworld.com/community/node/3400
98   private static String ident(final String s) {
99     return s.toString();
100   }
101   
102   // NOTE: we track per-segment version as a String with the "X.Y" format, e.g.
103   // "4.0", "3.1", "3.0". Therefore when we change this constant, we should keep
104   // the format.
105   public static final String LUCENE_MAIN_VERSION = ident("3.5");
106
107   public static final String LUCENE_VERSION;
108   static {
109     Package pkg = LucenePackage.get();
110     String v = (pkg == null) ? null : pkg.getImplementationVersion();
111     if (v == null) {
112       v = LUCENE_MAIN_VERSION + "-SNAPSHOT";
113     } else if (!v.startsWith(LUCENE_MAIN_VERSION)) {
114       v = LUCENE_MAIN_VERSION + "-SNAPSHOT " + v;
115     }
116     LUCENE_VERSION = ident(v);
117   }
118 }