1 package org.apache.lucene.util;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import org.apache.lucene.LucenePackage;
23 * Some useful constants.
26 public final class Constants {
27 private Constants() {} // can't construct
29 /** The value of <tt>System.getProperty("java.version")<tt>. **/
30 public static final String JAVA_VERSION = System.getProperty("java.version");
32 /** True iff this is Java version 1.1.
33 * @deprecated This constant is useless since Lucene is on Java 5 */
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 */
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 */
43 public static final boolean JAVA_1_3 = JAVA_VERSION.startsWith("1.3.");
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");
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");
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;
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");
68 JRE_IS_64BIT = x.indexOf("64") != -1;
70 if (OS_ARCH != null && OS_ARCH.indexOf("64") != -1) {
77 // this method only exists in Java 6:
80 String.class.getMethod("isEmpty");
81 } catch (NoSuchMethodException nsme) {
84 JRE_IS_MINIMUM_JAVA6 = v6;
86 // this method only exists in Java 7:
89 Throwable.class.getMethod("getSuppressed");
90 } catch (NoSuchMethodException nsme) {
93 JRE_IS_MINIMUM_JAVA7 = v7;
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) {
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
105 public static final String LUCENE_MAIN_VERSION = ident("3.5");
107 public static final String LUCENE_VERSION;
109 Package pkg = LucenePackage.get();
110 String v = (pkg == null) ? null : pkg.getImplementationVersion();
112 v = LUCENE_MAIN_VERSION + "-SNAPSHOT";
113 } else if (!v.startsWith(LUCENE_MAIN_VERSION)) {
114 v = LUCENE_MAIN_VERSION + "-SNAPSHOT " + v;
116 LUCENE_VERSION = ident(v);