Merged revision(s) 1201739 from lucene/dev/branches/branch_3x:

LUCENE-3574: Deprecate outdated constants in org.apache.lucene.util.Constants and add new ones for Java 6 and Java 7

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1201741 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2011-11-14 15:08:57 +00:00
parent 0a225a1cc2
commit 627817bed3
3 changed files with 24 additions and 21 deletions

View File

@ -735,6 +735,9 @@ API Changes
for multi-segment indexes. They were only needed for tests of for multi-segment indexes. They were only needed for tests of
NumericRangeQuery. (Mike McCandless, Uwe Schindler) 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 New Features
* LUCENE-3448: Added FixedBitSet.and(other/DISI), andNot(other/DISI). * LUCENE-3448: Added FixedBitSet.and(other/DISI), andNot(other/DISI).

View File

@ -28,12 +28,6 @@ public final class Constants {
/** The value of <tt>System.getProperty("java.version")<tt>. **/ /** The value of <tt>System.getProperty("java.version")<tt>. **/
public static final String JAVA_VERSION = System.getProperty("java.version"); public static final String JAVA_VERSION = System.getProperty("java.version");
/** True iff this is Java version 1.1. */
public static final boolean JAVA_1_1 = JAVA_VERSION.startsWith("1.1.");
/** True iff this is Java version 1.2. */
public static final boolean JAVA_1_2 = JAVA_VERSION.startsWith("1.2.");
/** True iff this is Java version 1.3. */
public static final boolean JAVA_1_3 = JAVA_VERSION.startsWith("1.3.");
/** The value of <tt>System.getProperty("os.name")<tt>. **/ /** The value of <tt>System.getProperty("os.name")<tt>. **/
public static final String OS_NAME = System.getProperty("os.name"); public static final String OS_NAME = System.getProperty("os.name");
@ -50,11 +44,16 @@ public final class Constants {
public static final String OS_VERSION = System.getProperty("os.version"); public static final String OS_VERSION = System.getProperty("os.version");
public static final String JAVA_VENDOR = System.getProperty("java.vendor"); public static final String JAVA_VENDOR = System.getProperty("java.vendor");
// NOTE: this logic may not be correct; if you know of a /** @deprecated With Lucene 4.0, we are always on Java 6 */
// more reliable approach please raise it on java-dev! @Deprecated
public static final boolean JRE_IS_64BIT; public static final boolean JRE_IS_MINIMUM_JAVA6 = true;
public static final boolean JRE_IS_64BIT;
public static final boolean JRE_IS_MINIMUM_JAVA7;
static { 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) { if (x != null) {
JRE_IS_64BIT = x.indexOf("64") != -1; JRE_IS_64BIT = x.indexOf("64") != -1;
} else { } else {
@ -64,6 +63,15 @@ public final class Constants {
JRE_IS_64BIT = false; JRE_IS_64BIT = false;
} }
} }
// 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, // this method prevents inlining the final version constant in compiled classes,

View File

@ -44,15 +44,7 @@ public class TestIOUtils extends LuceneTestCase {
} }
public void testSuppressedExceptions() { public void testSuppressedExceptions() {
boolean isJava7 = true; if (!Constants.JRE_IS_MINIMUM_JAVA7) {
try {
// this class only exists in Java 7:
Class.forName("java.lang.AutoCloseable");
} catch (ClassNotFoundException cnfe) {
isJava7 = false;
}
if (!isJava7) {
System.err.println("WARNING: TestIOUtils.testSuppressedExceptions: Full test coverage only with Java 7, as suppressed exception recording is not supported before."); 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 LuceneTestCase {
System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:"); System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:");
System.out.println(trace); System.out.println(trace);
} }
if (isJava7) { if (Constants.JRE_IS_MINIMUM_JAVA7) {
assertTrue("Stack trace does not contain first suppressed Exception: " + trace, assertTrue("Stack trace does not contain first suppressed Exception: " + trace,
trace.contains("java.io.IOException: TEST-IO-EXCEPTION-1")); trace.contains("java.io.IOException: TEST-IO-EXCEPTION-1"));
assertTrue("Stack trace does not contain second suppressed Exception: " + trace, assertTrue("Stack trace does not contain second suppressed Exception: " + trace,
@ -97,7 +89,7 @@ public class TestIOUtils extends LuceneTestCase {
System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:"); System.out.println("TestIOUtils.testSuppressedExceptions: Thrown Exception stack trace:");
System.out.println(trace); System.out.println(trace);
} }
if (isJava7) { if (Constants.JRE_IS_MINIMUM_JAVA7) {
assertTrue("Stack trace does not contain suppressed Exception: " + trace, assertTrue("Stack trace does not contain suppressed Exception: " + trace,
trace.contains("java.io.IOException: TEST-IO-EXCEPTION-2")); trace.contains("java.io.IOException: TEST-IO-EXCEPTION-2"));
} }