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

/src/java/org/apache/lucene/util/Constants.java

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