You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2011/11/14 16:03:34 UTC

svn commit: r1201739 - in /lucene/dev/branches/branch_3x/lucene: CHANGES.txt src/java/org/apache/lucene/util/Constants.java src/test/org/apache/lucene/util/TestIOUtils.java

Author: uschindler
Date: Mon Nov 14 15:03:33 2011
New Revision: 1201739

URL: http://svn.apache.org/viewvc?rev=1201739&view=rev
Log:
LUCENE-3574: Deprecate outdated constants in org.apache.lucene.util.Constants and add new ones for Java 6 and Java 7

Modified:
    lucene/dev/branches/branch_3x/lucene/CHANGES.txt
    lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/Constants.java
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java

Modified: lucene/dev/branches/branch_3x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/CHANGES.txt?rev=1201739&r1=1201738&r2=1201739&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/CHANGES.txt Mon Nov 14 15:03:33 2011
@@ -116,6 +116,9 @@ API Changes
   for multi-segment indexes. They were only needed for tests of
   NumericRangeQuery.  (Mike McCandless, Uwe Schindler)
 
+* LUCENE-3574: Deprecate outdated constants in org.apache.lucene.util.Constants
+  and add new ones for Java 6 and Java 7.  (Uwe Schindler)
+
 New Features
 
 * LUCENE-3448: Added FixedBitSet.and(other/DISI), andNot(other/DISI).

Modified: lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/Constants.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/Constants.java?rev=1201739&r1=1201738&r2=1201739&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/Constants.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/Constants.java Mon Nov 14 15:03:33 2011
@@ -28,13 +28,20 @@ public final class Constants {
 
   /** The value of <tt>System.getProperty("java.version")<tt>. **/
   public static final String JAVA_VERSION = System.getProperty("java.version");
-  /** True iff this is Java version 1.1. */
+ 
+  /** True iff this is Java version 1.1.
+   * @deprecated This constant is useless since Lucene is on Java 5 */
+  @Deprecated
   public static final boolean JAVA_1_1 = JAVA_VERSION.startsWith("1.1.");
-  /** True iff this is Java version 1.2. */
+  /** True iff this is Java version 1.2.
+   * @deprecated This constant is useless since Lucene is on Java 5 */
+  @Deprecated
   public static final boolean JAVA_1_2 = JAVA_VERSION.startsWith("1.2.");
-  /** True iff this is Java version 1.3. */
+  /** True iff this is Java version 1.3.
+   * @deprecated This constant is useless since Lucene is on Java 5 */
+  @Deprecated
   public static final boolean JAVA_1_3 = JAVA_VERSION.startsWith("1.3.");
- 
+
   /** The value of <tt>System.getProperty("os.name")<tt>. **/
   public static final String OS_NAME = System.getProperty("os.name");
   /** True iff running on Linux. */
@@ -50,11 +57,13 @@ public final class Constants {
   public static final String OS_VERSION = System.getProperty("os.version");
   public static final String JAVA_VENDOR = System.getProperty("java.vendor");
 
-  // NOTE: this logic may not be correct; if you know of a
-  // more reliable approach please raise it on java-dev!
   public static final boolean JRE_IS_64BIT;
+  public static final boolean JRE_IS_MINIMUM_JAVA6;
+  public static final boolean JRE_IS_MINIMUM_JAVA7;
   static {
-    String x = System.getProperty("sun.arch.data.model");
+    // NOTE: this logic may not be correct; if you know of a
+    // more reliable approach please raise it on java-dev!
+    final String x = System.getProperty("sun.arch.data.model");
     if (x != null) {
       JRE_IS_64BIT = x.indexOf("64") != -1;
     } else {
@@ -64,6 +73,24 @@ public final class Constants {
         JRE_IS_64BIT = false;
       }
     }
+
+    // this method only exists in Java 6:
+    boolean v6 = true;
+    try {
+      String.class.getMethod("isEmpty");
+    } catch (NoSuchMethodException nsme) {
+      v6 = false;
+    }
+    JRE_IS_MINIMUM_JAVA6 = v6;
+    
+    // this method only exists in Java 7:
+    boolean v7 = true;
+    try {
+      Throwable.class.getMethod("getSuppressed");
+    } catch (NoSuchMethodException nsme) {
+      v7 = false;
+    }
+    JRE_IS_MINIMUM_JAVA7 = v7;
   }
 
   // this method prevents inlining the final version constant in compiled classes,

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java?rev=1201739&r1=1201738&r2=1201739&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestIOUtils.java Mon Nov 14 15:03:33 2011
@@ -44,15 +44,7 @@ public class TestIOUtils extends LuceneT
   }
 
   public void testSuppressedExceptions() {
-    boolean isJava7 = true;
-    try {
-      // this class only exists in Java 7:
-      Class.forName("java.lang.AutoCloseable");
-    } catch (ClassNotFoundException cnfe) {
-      isJava7 = false;
-    }
-    
-    if (!isJava7) {
+    if (!Constants.JRE_IS_MINIMUM_JAVA7) {
       System.err.println("WARNING: TestIOUtils.testSuppressedExceptions: Full test coverage only with Java 7, as suppressed exception recording is not supported before.");
     }
     
@@ -71,7 +63,7 @@ public class TestIOUtils extends LuceneT
         System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:");
         System.out.println(trace);
       }
-      if (isJava7) {
+      if (Constants.JRE_IS_MINIMUM_JAVA7) {
         assertTrue("Stack trace does not contain first suppressed Exception: " + trace,
           trace.contains("java.io.IOException: TEST-IO-EXCEPTION-1"));
         assertTrue("Stack trace does not contain second suppressed Exception: " + trace,
@@ -97,7 +89,7 @@ public class TestIOUtils extends LuceneT
         System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:");
         System.out.println(trace);
       }
-      if (isJava7) {
+      if (Constants.JRE_IS_MINIMUM_JAVA7) {
         assertTrue("Stack trace does not contain suppressed Exception: " + trace,
           trace.contains("java.io.IOException: TEST-IO-EXCEPTION-2"));
       }