Note: this is public only to allow access from
* the codecs package.
*/
- public SegmentInfo(Directory dir, String version, String name, int docCount,
+ public SegmentInfo(Directory dir, Version version, String name, int docCount,
boolean isCompoundFile, Codec codec, Map diagnostics) {
assert !(dir instanceof TrackingDirectoryWrapper);
this.dir = dir;
@@ -203,23 +206,9 @@ public final class SegmentInfo {
return dir.hashCode() + name.hashCode();
}
- /**
- * Used by DefaultSegmentInfosReader to upgrade a 3.0 segment to record its
- * version is "3.0". This method can be removed when we're not required to
- * support 3x indexes anymore, e.g. in 5.0.
- *
- * NOTE: this method is used for internal purposes only - you should
- * not modify the version of a SegmentInfo, or it may result in unexpected
- * exceptions thrown when you attempt to open the index.
- *
- * @lucene.internal
+ /** Returns the version of the code which wrote the segment.
*/
- public void setVersion(String version) {
- this.version = version;
- }
-
- /** Returns the version of the code which wrote the segment. */
- public String getVersion() {
+ public Version getVersion() {
return version;
}
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java
index b8b5abc66fa..3f4de57f2ac 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java
@@ -200,8 +200,8 @@ public final class SegmentReader extends AtomicReader implements Accountable {
return;
}
- String ver = si.info.getVersion();
- if (ver != null && StringHelper.getVersionComparator().compare(ver, "4.9.0") >= 0) {
+ Version ver = si.info.getVersion();
+ if (ver != null && ver.onOrAfter(Version.LUCENE_4_9_0)) {
DocValuesProducer baseProducer = null;
for (FieldInfo fi : fieldInfos) {
if (!fi.hasDocValues()) continue;
diff --git a/lucene/core/src/java/org/apache/lucene/index/UpgradeIndexMergePolicy.java b/lucene/core/src/java/org/apache/lucene/index/UpgradeIndexMergePolicy.java
index 7781df35e20..9374e646bec 100644
--- a/lucene/core/src/java/org/apache/lucene/index/UpgradeIndexMergePolicy.java
+++ b/lucene/core/src/java/org/apache/lucene/index/UpgradeIndexMergePolicy.java
@@ -17,7 +17,7 @@ package org.apache.lucene.index;
* limitations under the License.
*/
-import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.Version;
import java.io.IOException;
import java.util.ArrayList;
@@ -60,12 +60,12 @@ public class UpgradeIndexMergePolicy extends MergePolicy {
}
/** Returns if the given segment should be upgraded. The default implementation
- * will return {@code !Constants.LUCENE_MAIN_VERSION.equals(si.getVersion())},
+ * will return {@code !Version.LATEST.equals(si.getVersion())},
* so all segments created with a different version number than this Lucene version will
* get upgraded.
*/
protected boolean shouldUpgradeSegment(SegmentCommitInfo si) {
- return !Constants.LUCENE_MAIN_VERSION.equals(si.info.getVersion());
+ return !Version.LATEST.equals(si.info.getVersion());
}
@Override
diff --git a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
index 8f79fd9e2c4..7719dc3c717 100644
--- a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -52,7 +52,7 @@ import org.apache.lucene.util.IOUtils;
*
* Directory fsDir = FSDirectory.open(new File("/path/to/index"));
* NRTCachingDirectory cachedFSDir = new NRTCachingDirectory(fsDir, 5.0, 60.0);
- * IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_5_0, analyzer);
+ * IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_5_0_0, analyzer);
* IndexWriter writer = new IndexWriter(cachedFSDir, conf);
*
*
diff --git a/lucene/core/src/java/org/apache/lucene/util/Constants.java b/lucene/core/src/java/org/apache/lucene/util/Constants.java
index a5c8d9f3fe2..ec703d9d6b2 100644
--- a/lucene/core/src/java/org/apache/lucene/util/Constants.java
+++ b/lucene/core/src/java/org/apache/lucene/util/Constants.java
@@ -19,7 +19,6 @@ package org.apache.lucene.util;
import java.lang.reflect.Field;
import java.util.Collections;
-import org.apache.lucene.LucenePackage;
/**
* Some useful constants.
@@ -93,45 +92,18 @@ public final class Constants {
JRE_IS_MINIMUM_JAVA8 = v8;
}
- // this method prevents inlining the final version constant in compiled classes,
- // see: http://www.javaworld.com/community/node/3400
- private static String ident(final String s) {
- return s.toString();
- }
-
- // We should never change index format with minor versions, so it should always be x.y or x.y.0.z for alpha/beta versions!
/**
- * This is the internal Lucene version, recorded into each segment.
- * NOTE: we track per-segment version as a String with the {@code "X.Y"} format
- * (no minor version), e.g. {@code "4.0", "3.1", "3.0"}.
- * Alpha and Beta versions will have numbers like {@code "X.Y.0.Z"},
- * anything else is not allowed. This is done to prevent people from
- * using indexes created with ALPHA/BETA versions with the released version.
+ * This is the internal Lucene version, including bugfix versions, recorded into each segment.
+ * @deprecated Use {@link Version#LATEST}
*/
- public static final String LUCENE_MAIN_VERSION = ident("5.0");
-
- /**
- * This is the Lucene version for display purposes.
- */
- public static final String LUCENE_VERSION;
- static {
- Package pkg = LucenePackage.get();
- String v = (pkg == null) ? null : pkg.getImplementationVersion();
- if (v == null) {
- v = mainVersionWithoutAlphaBeta() + "-SNAPSHOT";
- }
- LUCENE_VERSION = ident(v);
- }
+ @Deprecated
+ public static final String LUCENE_MAIN_VERSION = Version.LATEST.toString();
/**
- * Returns a LUCENE_MAIN_VERSION without any ALPHA/BETA qualifier
- * Used by test only!
+ * Don't use this constant because the name is not self-describing!
+ * @deprecated Use {@link Version#LATEST}
*/
- static String mainVersionWithoutAlphaBeta() {
- final String parts[] = LUCENE_MAIN_VERSION.split("\\.");
- if (parts.length == 4 && "0".equals(parts[2])) {
- return parts[0] + "." + parts[1];
- }
- return LUCENE_MAIN_VERSION;
- }
+ @Deprecated
+ public static final String LUCENE_VERSION = Version.LATEST.toString();
+
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/StringHelper.java b/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
index f759d21a6b7..3a753de5f52 100644
--- a/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
+++ b/lucene/core/src/java/org/apache/lucene/util/StringHelper.java
@@ -66,45 +66,6 @@ public abstract class StringHelper {
private StringHelper() {
}
-
- /**
- * @return a Comparator over versioned strings such as X.YY.Z
- * @lucene.internal
- */
- public static Comparator getVersionComparator() {
- return versionComparator;
- }
-
- private static Comparator versionComparator = new Comparator() {
- @Override
- public int compare(String a, String b) {
- StringTokenizer aTokens = new StringTokenizer(a, ".");
- StringTokenizer bTokens = new StringTokenizer(b, ".");
-
- while (aTokens.hasMoreTokens()) {
- int aToken = Integer.parseInt(aTokens.nextToken());
- if (bTokens.hasMoreTokens()) {
- int bToken = Integer.parseInt(bTokens.nextToken());
- if (aToken != bToken) {
- return aToken < bToken ? -1 : 1;
- }
- } else {
- // a has some extra trailing tokens. if these are all zeroes, thats ok.
- if (aToken != 0) {
- return 1;
- }
- }
- }
-
- // b has some extra trailing tokens. if these are all zeroes, thats ok.
- while (bTokens.hasMoreTokens()) {
- if (Integer.parseInt(bTokens.nextToken()) != 0)
- return -1;
- }
-
- return 0;
- }
- };
public static boolean equals(String s1, String s2) {
if (s1 == null) {
diff --git a/lucene/core/src/java/org/apache/lucene/util/Version.java b/lucene/core/src/java/org/apache/lucene/util/Version.java
index bb6157c33eb..3f1293672ed 100644
--- a/lucene/core/src/java/org/apache/lucene/util/Version.java
+++ b/lucene/core/src/java/org/apache/lucene/util/Version.java
@@ -29,95 +29,158 @@ import java.util.Locale;
* change the version at search-time, but instead also adjust
* your indexing code to match, and re-index.
*/
-// remove me when java 5 is no longer supported
-// this is a workaround for a JDK bug that wrongly emits a warning.
-@SuppressWarnings("dep-ann")
-public enum Version {
+public final class Version {
+
/**
- * Match settings and bugs in Lucene's 4.0 release.
+ * Match settings and bugs in Lucene's 4.0.0-ALPHA release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_0,
+ public static final Version LUCENE_4_0_0_ALPHA = new Version(4, 0, 0, 1);
+
+ /**
+ * Match settings and bugs in Lucene's 4.0.0-BETA release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_0_0_BETA = new Version(4, 0, 0, 2);
+
+ /**
+ * Match settings and bugs in Lucene's 4.0.0 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_0_0 = new Version(4, 0, 0);
/**
- * Match settings and bugs in Lucene's 4.1 release.
+ * Match settings and bugs in Lucene's 4.1.0 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_1,
+ public static final Version LUCENE_4_1_0 = new Version(4, 1, 0);
/**
- * Match settings and bugs in Lucene's 4.2 release.
+ * Match settings and bugs in Lucene's 4.2.0 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_2,
+ public static final Version LUCENE_4_2_0 = new Version(4, 2, 0);
/**
- * Match settings and bugs in Lucene's 4.3 release.
+ * Match settings and bugs in Lucene's 4.2.1 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_3,
+ public static final Version LUCENE_4_2_1 = new Version(4, 2, 1);
/**
- * Match settings and bugs in Lucene's 4.4 release.
+ * Match settings and bugs in Lucene's 4.3.0 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_4,
+ public static final Version LUCENE_4_3_0 = new Version(4, 3, 0);
/**
- * Match settings and bugs in Lucene's 4.5 release.
+ * Match settings and bugs in Lucene's 4.3.1 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_5,
+ public static final Version LUCENE_4_3_1 = new Version(4, 3, 1);
/**
- * Match settings and bugs in Lucene's 4.6 release.
+ * Match settings and bugs in Lucene's 4.4.0 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_6,
+ public static final Version LUCENE_4_4_0 = new Version(4, 4, 0);
+
+ /**
+ * Match settings and bugs in Lucene's 4.5.0 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_5_0 = new Version(4, 5, 0);
+
+ /**
+ * Match settings and bugs in Lucene's 4.5.1 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_5_1 = new Version(4, 5, 1);
+
+ /**
+ * Match settings and bugs in Lucene's 4.6.0 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_6_0 = new Version(4, 6, 0);
+
+ /**
+ * Match settings and bugs in Lucene's 4.6.1 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_6_1 = new Version(4, 6, 1);
/**
- * Match settings and bugs in Lucene's 4.7 release.
+ * Match settings and bugs in Lucene's 4.7.0 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_7,
-
- /**
- * Match settings and bugs in Lucene's 4.8 release.
- * @deprecated (5.0) Use latest
- */
- @Deprecated
- LUCENE_4_8,
+ public static final Version LUCENE_4_7_0 = new Version(4, 7, 0);
/**
- * Match settings and bugs in Lucene's 4.9 release.
+ * Match settings and bugs in Lucene's 4.7.1 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_9,
+ public static final Version LUCENE_4_7_1 = new Version(4, 7, 1);
+
+ /**
+ * Match settings and bugs in Lucene's 4.7.2 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_7_2 = new Version(4, 7, 2);
+
+ /**
+ * Match settings and bugs in Lucene's 4.8.0 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_8_0 = new Version(4, 8, 0);
+
+ /**
+ * Match settings and bugs in Lucene's 4.8.1 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_8_1 = new Version(4, 8, 1);
+
+ /**
+ * Match settings and bugs in Lucene's 4.9.0 release.
+ * @deprecated (5.0) Use latest
+ */
+ @Deprecated
+ public static final Version LUCENE_4_9_0 = new Version(4, 9, 0);
/**
* Match settings and bugs in Lucene's 4.10 release.
* @deprecated (5.0) Use latest
*/
@Deprecated
- LUCENE_4_10,
+ public static final Version LUCENE_4_10_0 = new Version(4, 10, 0);
/** Match settings and bugs in Lucene's 5.0 release.
*
* Use this to get the latest & greatest settings, bug
* fixes, etc, for Lucene.
*/
- LUCENE_5_0,
-
- /* Add new constants for later versions **here** to respect order! */
+ public static final Version LUCENE_5_0_0 = new Version(5, 0, 0);
+
+ // To add a new version:
+ // * Only add above this comment
+ // * If the new version is the newest, change LATEST below and deprecate the previous LATEST
/**
*
WARNING: if you use this setting, and then
@@ -132,21 +195,158 @@ public enum Version {
* Additionally, you may need to re-test your entire
* application to ensure it behaves as expected, as
* some defaults may have changed and may break functionality
- * in your application.
- * @deprecated Use an actual version instead.
+ * in your application.
+ */
+ public static final Version LATEST = LUCENE_5_0_0;
+
+ /**
+ * Constant for backwards compatibility.
+ * @deprecated Use {@link #LATEST}
*/
@Deprecated
- LUCENE_CURRENT;
+ public static final Version LUCENE_CURRENT = LATEST;
- public boolean onOrAfter(Version other) {
- return compareTo(other) >= 0;
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_0_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_0 = LUCENE_4_0_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_1_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_1 = LUCENE_4_1_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_2_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_2 = LUCENE_4_2_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_3_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_3 = LUCENE_4_3_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_4_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_4 = LUCENE_4_4_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_5_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_5 = LUCENE_4_5_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_6_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_6 = LUCENE_4_6_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_7_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_7 = LUCENE_4_7_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_8_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_8 = LUCENE_4_8_0;
+
+ /** @deprecated Bad naming of constant; use {@link #LUCENE_4_9_0} instead. */
+ @Deprecated
+ public static final Version LUCENE_4_9 = LUCENE_4_9_0;
+
+
+ /**
+ * Parse a version number of the form {@code "major.minor.bugfix.prerelease"}.
+ *
+ * Part {@code ".bugfix"} and part {@code ".prerelease"} are optional.
+ * Note that this is forwards compatible: the parsed version does not have to exist as
+ * a constant.
+ */
+ public static Version parse(String version) {
+ String[] pieces = version.split("\\.");
+ if (pieces.length < 2 || pieces.length > 4) {
+ throw new IllegalArgumentException("Version is not in form major.minor.bugfix(.prerelease): " + version);
+ }
+
+ int major = Integer.parseInt(pieces[0]);
+ int minor = Integer.parseInt(pieces[1]);
+ int bugfix = 0;
+ int prerelease = 0;
+ if (pieces.length > 2) {
+ bugfix = Integer.parseInt(pieces[2]);
+ }
+ if (pieces.length > 3) {
+ prerelease = Integer.parseInt(pieces[3]);
+ if (prerelease == 0) {
+ throw new IllegalArgumentException("Invalid value " + prerelease + " for prelrease of version " + version +", should be 1 or 2");
+ }
+ }
+
+ return new Version(major, minor, bugfix, prerelease);
}
-
+
+ /**
+ * Parse the given version number as a constant or dot based version.
+ *
This method allows to use {@code "LUCENE_X_Y"} constant names,
+ * or version numbers in the format {@code "x.y.z"}.
+ */
public static Version parseLeniently(String version) {
+ if (version.equals("LATEST") || version.equals("LUCENE_CURRENT")) return LATEST;
final String parsedMatchVersion = version
.toUpperCase(Locale.ROOT)
- .replaceFirst("^(\\d+)\\.(\\d+)$", "LUCENE_$1_$2")
- .replaceFirst("^LUCENE_(\\d)(\\d)$", "LUCENE_$1_$2");
- return Version.valueOf(parsedMatchVersion);
+ .replaceFirst("^LUCENE_(\\d+)_(\\d+)_(\\d+)$", "$1.$2.$3")
+ .replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2.0")
+ .replaceFirst("^LUCENE_(\\d)(\\d)$", "$1.$2.0");
+ return parse(parsedMatchVersion);
+ }
+
+ // stores the version pieces, with most significant pieces in high bits
+ // ie: | 1 byte | 1 byte | 1 byte | 2 bits |
+ // major minor bugfix prerelease
+ private final int encodedValue;
+
+ private Version(int major, int minor, int bugfix) {
+ this(major, minor, bugfix, 0);
+ }
+
+ private Version(int major, int minor, int bugfix, int prerelease) {
+ if (major > 5 || major < 4) {
+ throw new IllegalArgumentException("Lucene 5.x only supports 5.x and 4.x versions");
+ }
+ if (minor > 255 | minor < 0) {
+ throw new IllegalArgumentException("Illegal minor version: " + minor);
+ }
+ if (bugfix > 255 | bugfix < 0) {
+ throw new IllegalArgumentException("Illegal bugfix version: " + bugfix);
+ }
+ if (prerelease > 2 | prerelease < 0) {
+ throw new IllegalArgumentException("Illegal prerelease version: " + prerelease);
+ }
+ if (prerelease != 0 && (minor != 0 || bugfix != 0)) {
+ throw new IllegalArgumentException("Prerelease version only supported with major release");
+ }
+
+ if (prerelease == 0) {
+ // final release should sort after alpha/beta
+ prerelease = 3;
+ }
+
+ encodedValue = major << 18 | minor << 10 | bugfix << 2 | prerelease;
+ }
+
+ /**
+ * Returns true if this version is the same or after the version from the argument.
+ */
+ public boolean onOrAfter(Version other) {
+ return encodedValue >= other.encodedValue;
+ }
+
+ @Override
+ public String toString() {
+ int major = (encodedValue >>> 18) & 0xFF;
+ int minor = (encodedValue >>> 10) & 0xFF;
+ int bugfix = (encodedValue >>> 2) & 0xFF;
+ int prerelease = encodedValue & 0x3;
+ if (prerelease == 3) { // ie unencoded value is 0
+ return "" + major + "." + minor + "." + bugfix;
+ }
+ return "" + major + "." + minor + "." + bugfix + "." + prerelease;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return o != null && o instanceof Version && ((Version)o).encodedValue == encodedValue;
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
index 1f0c44fc444..87970c3fd8c 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -59,14 +58,13 @@ import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.SimpleFSDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.Constants;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.NumericUtils;
-import org.apache.lucene.util.StringHelper;
import org.apache.lucene.util.TestUtil;
+import org.apache.lucene.util.Version;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -846,23 +844,21 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
riw.close();
DirectoryReader ir = DirectoryReader.open(currentDir);
SegmentReader air = (SegmentReader)ir.leaves().get(0).reader();
- String currentVersion = air.getSegmentInfo().info.getVersion();
+ Version currentVersion = air.getSegmentInfo().info.getVersion();
assertNotNull(currentVersion); // only 3.0 segments can have a null version
ir.close();
currentDir.close();
- Comparator comparator = StringHelper.getVersionComparator();
-
// now check all the old indexes, their version should be < the current version
for (String name : oldNames) {
Directory dir = oldIndexDirs.get(name);
DirectoryReader r = DirectoryReader.open(dir);
for (AtomicReaderContext context : r.leaves()) {
air = (SegmentReader) context.reader();
- String oldVersion = air.getSegmentInfo().info.getVersion();
+ Version oldVersion = air.getSegmentInfo().info.getVersion();
assertNotNull(oldVersion); // only 3.0 segments can have a null version
- assertTrue("current Constants.LUCENE_MAIN_VERSION is <= an old index: did you forget to bump it?!",
- comparator.compare(oldVersion, currentVersion) < 0);
+ assertTrue("current Version.LATEST is <= an old index: did you forget to bump it?!",
+ currentVersion.onOrAfter(oldVersion));
}
r.close();
}
@@ -920,7 +916,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
System.out.println("checkAllSegmentsUpgraded: " + infos);
}
for (SegmentCommitInfo si : infos) {
- assertEquals(Constants.LUCENE_MAIN_VERSION, si.info.getVersion());
+ assertEquals(Version.LATEST, si.info.getVersion());
}
return infos.size();
}
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java b/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
index b24a6f60f68..e1753f9945b 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
@@ -43,11 +43,11 @@ import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.Constants;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
+import org.apache.lucene.util.Version;
import org.junit.BeforeClass;
// TODO: test multiple codecs here?
@@ -252,7 +252,7 @@ public class TestCodecs extends LuceneTestCase {
final Directory dir = newDirectory();
this.write(fieldInfos, dir, fields);
Codec codec = Codec.getDefault();
- final SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
+ final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null);
final FieldsProducer reader = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random())));
@@ -309,7 +309,7 @@ public class TestCodecs extends LuceneTestCase {
this.write(fieldInfos, dir, fields);
Codec codec = Codec.getDefault();
- final SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
+ final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null);
if (VERBOSE) {
System.out.println("TEST: now read postings");
@@ -804,7 +804,7 @@ public class TestCodecs extends LuceneTestCase {
private void write(final FieldInfos fieldInfos, final Directory dir, final FieldData[] fields) throws Throwable {
final Codec codec = Codec.getDefault();
- final SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
+ final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null);
final SegmentWriteState state = new SegmentWriteState(InfoStream.getDefault(), dir, si, fieldInfos, null, newIOContext(random()));
Arrays.sort(fields);
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java
index 6c322a9debd..9dbb7563095 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java
@@ -41,9 +41,9 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.TrackingDirectoryWrapper;
-import org.apache.lucene.util.Constants;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.Version;
/** JUnit adaptation of an older test case DocTest. */
@@ -217,7 +217,7 @@ public class TestDoc extends LuceneTestCase {
final Codec codec = Codec.getDefault();
TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(si1.info.dir);
- final SegmentInfo si = new SegmentInfo(si1.info.dir, Constants.LUCENE_MAIN_VERSION, merged, -1, false, codec, null);
+ final SegmentInfo si = new SegmentInfo(si1.info.dir, Version.LATEST, merged, -1, false, codec, null);
SegmentMerger merger = new SegmentMerger(Arrays.asList(r1, r2),
si, InfoStream.getDefault(), trackingDir,
@@ -226,7 +226,7 @@ public class TestDoc extends LuceneTestCase {
MergeState mergeState = merger.merge();
r1.close();
r2.close();
- final SegmentInfo info = new SegmentInfo(si1.info.dir, Constants.LUCENE_MAIN_VERSION, merged,
+ final SegmentInfo info = new SegmentInfo(si1.info.dir, Version.LATEST, merged,
si1.info.getDocCount() + si2.info.getDocCount(),
false, codec, null);
info.setFiles(new HashSet<>(trackingDir.getCreatedFiles()));
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java
index ed6ee459bf7..041ca16e712 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java
@@ -25,11 +25,11 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.Constants;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
+import org.apache.lucene.util.Version;
public class TestSegmentMerger extends LuceneTestCase {
//The variables for the new merged segment
@@ -78,7 +78,7 @@ public class TestSegmentMerger extends LuceneTestCase {
public void testMerge() throws IOException {
final Codec codec = Codec.getDefault();
- final SegmentInfo si = new SegmentInfo(mergedDir, Constants.LUCENE_MAIN_VERSION, mergedSegment, -1, false, codec, null);
+ final SegmentInfo si = new SegmentInfo(mergedDir, Version.LATEST, mergedSegment, -1, false, codec, null);
SegmentMerger merger = new SegmentMerger(Arrays.asList(reader1, reader2),
si, InfoStream.getDefault(), mergedDir,
@@ -88,7 +88,7 @@ public class TestSegmentMerger extends LuceneTestCase {
assertTrue(docsMerged == 2);
//Should be able to open a new SegmentReader against the new directory
SegmentReader mergedReader = new SegmentReader(new SegmentCommitInfo(
- new SegmentInfo(mergedDir, Constants.LUCENE_MAIN_VERSION, mergedSegment, docsMerged,
+ new SegmentInfo(mergedDir, Version.LATEST, mergedSegment, docsMerged,
false, codec, null),
0, -1L, -1L, -1L),
newIOContext(random()));
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestConstants.java b/lucene/core/src/test/org/apache/lucene/util/TestConstants.java
deleted file mode 100644
index e6f00e3a57a..00000000000
--- a/lucene/core/src/test/org/apache/lucene/util/TestConstants.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.apache.lucene.util;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-public class TestConstants extends LuceneTestCase {
-
- private String getVersionDetails() {
- return " (LUCENE_MAIN_VERSION=" + Constants.LUCENE_MAIN_VERSION +
- ", LUCENE_MAIN_VERSION(without alpha/beta)=" + Constants.mainVersionWithoutAlphaBeta() +
- ", LUCENE_VERSION=" + Constants.LUCENE_VERSION + ")";
- }
-
- public void testLuceneMainVersionConstant() {
- assertTrue("LUCENE_MAIN_VERSION does not follow pattern: 'x.y' (stable release) or 'x.y.0.z' (alpha/beta version)" + getVersionDetails(),
- Constants.LUCENE_MAIN_VERSION.matches("\\d+\\.\\d+(|\\.0\\.\\d+)"));
- assertTrue("LUCENE_VERSION does not start with LUCENE_MAIN_VERSION (without alpha/beta marker)" + getVersionDetails(),
- Constants.LUCENE_VERSION.startsWith(Constants.mainVersionWithoutAlphaBeta()));
- }
-
- public void testBuildSetup() {
- // common-build.xml sets lucene.version, if not, we skip this test!
- String version = System.getProperty("lucene.version");
- assumeTrue("Null lucene.version test property. You should run the tests with the official Lucene build file",
- version != null);
-
- // remove anything after a "-" from the version string:
- version = version.replaceAll("-.*$", "");
- String versionConstant = Constants.LUCENE_VERSION.replaceAll("-.*$", "");
- assertTrue("LUCENE_VERSION should share the same prefix with lucene.version test property ('" + version + "')." + getVersionDetails(),
- versionConstant.startsWith(version) || version.startsWith(versionConstant));
- }
-
-}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestVersion.java b/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
index e079269f122..8e15efe040e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
@@ -17,46 +17,173 @@
package org.apache.lucene.util;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
public class TestVersion extends LuceneTestCase {
- public void test() {
- for (Version v : Version.values()) {
- assertTrue("LUCENE_CURRENT must be always onOrAfter("+v+")", Version.LUCENE_CURRENT.onOrAfter(v));
+ public void testOnOrAfter() throws Exception {
+ for (Field field : Version.class.getDeclaredFields()) {
+ if (Modifier.isStatic(field.getModifiers()) && field.getType() == Version.class) {
+ Version v = (Version)field.get(Version.class);
+ assertTrue("LATEST must be always onOrAfter("+v+")", Version.LATEST.onOrAfter(v));
+ }
}
- assertTrue(Version.LUCENE_5_0.onOrAfter(Version.LUCENE_4_0));
- assertFalse(Version.LUCENE_4_0.onOrAfter(Version.LUCENE_5_0));
+ assertTrue(Version.LUCENE_5_0_0.onOrAfter(Version.LUCENE_4_0_0));
+ assertFalse(Version.LUCENE_4_0_0.onOrAfter(Version.LUCENE_5_0_0));
+ assertTrue(Version.LUCENE_4_0_0_ALPHA.onOrAfter(Version.LUCENE_4_0_0_ALPHA));
+ assertTrue(Version.LUCENE_4_0_0_BETA.onOrAfter(Version.LUCENE_4_0_0_ALPHA));
+ assertTrue(Version.LUCENE_4_0_0.onOrAfter(Version.LUCENE_4_0_0_ALPHA));
+ assertTrue(Version.LUCENE_4_0_0.onOrAfter(Version.LUCENE_4_0_0_BETA));
+ }
+
+ public void testToString() {
+ assertEquals("4.2.0", Version.LUCENE_4_2_0.toString());
+ assertEquals("4.2.0", Version.LUCENE_4_2.toString());
+ assertEquals("4.2.1", Version.LUCENE_4_2_1.toString());
+ assertEquals("4.0.0.1", Version.LUCENE_4_0_0_ALPHA.toString());
+ assertEquals("4.0.0.2", Version.LUCENE_4_0_0_BETA.toString());
}
public void testParseLeniently() {
- assertEquals(Version.LUCENE_4_0, Version.parseLeniently("4.0"));
- assertEquals(Version.LUCENE_4_0, Version.parseLeniently("LUCENE_40"));
- assertEquals(Version.LUCENE_4_0, Version.parseLeniently("LUCENE_4_0"));
- assertEquals(Version.LUCENE_CURRENT, Version.parseLeniently("LUCENE_CURRENT"));
+ assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("4.0"));
+ assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("4.0.0"));
+ assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("LUCENE_40"));
+ assertEquals(Version.LUCENE_4_0_0, Version.parseLeniently("LUCENE_4_0"));
+ assertEquals(Version.LATEST, Version.parseLeniently("LATEST"));
+ assertEquals(Version.LATEST, Version.parseLeniently("LUCENE_CURRENT"));
}
- public void testDeprecations() throws Exception {
- Version values[] = Version.values();
- // all but the latest version should be deprecated
- for (int i = 0; i < values.length; i++) {
- if (i + 1 == values.length) {
- assertSame("Last constant must be LUCENE_CURRENT", Version.LUCENE_CURRENT, values[i]);
- }
- final boolean dep = Version.class.getField(values[i].name()).isAnnotationPresent(Deprecated.class);
- if (i + 2 != values.length) {
- assertTrue(values[i].name() + " should be deprecated", dep);
- } else {
- assertFalse(values[i].name() + " should not be deprecated", dep);
- }
+ public void testParseLenientlyExceptions() {
+ try {
+ Version.parseLeniently("LUCENE");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+ }
+
+ public void testParse() {
+ assertEquals(Version.LUCENE_5_0_0, Version.parse("5.0.0"));
+ assertEquals(Version.LUCENE_4_1_0, Version.parse("4.1"));
+ assertEquals(Version.LUCENE_4_1_0, Version.parseLeniently("4.1.0"));
+ assertEquals(Version.LUCENE_4_0_0_ALPHA, Version.parseLeniently("4.0.0.1"));
+ assertEquals(Version.LUCENE_4_0_0_BETA, Version.parseLeniently("4.0.0.2"));
+ }
+
+ public void testForwardsCompatibility() {
+ assertTrue(Version.parse("4.7.10").onOrAfter(Version.LUCENE_4_7_2));
+ assertTrue(Version.parse("4.20.0").onOrAfter(Version.LUCENE_4_8_1));
+ assertTrue(Version.parse("5.10.20").onOrAfter(Version.LUCENE_5_0_0));
+ }
+
+ public void testParseExceptions() {
+ try {
+ Version.parse("1.0");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("LUCENE_4_0_0");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.256");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.-1");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.1.256");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.1.-1");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.1.1.3");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.1.1.-1");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.1.1.1");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.1.1.2");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("4.0.0.0");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
+ }
+
+ try {
+ Version.parse("6.0.0");
+ fail();
+ } catch (IllegalArgumentException iae) {
+ // pass
}
}
- public void testAgainstMainVersionConstant() {
- final Version values[] = Version.values();
- assertTrue(values.length >= 2);
- final String mainVersionWithoutAlphaBeta = Constants.mainVersionWithoutAlphaBeta();
- final Version mainVersionParsed = Version.parseLeniently(mainVersionWithoutAlphaBeta);
- assertSame("Constant one before last must be the same as the parsed LUCENE_MAIN_VERSION (without alpha/beta) constant: " +
- mainVersionWithoutAlphaBeta,
- mainVersionParsed, values[values.length - 2]);
+ public void testDeprecations() throws Exception {
+ // all but the latest version should be deprecated
+ for (Field field : Version.class.getDeclaredFields()) {
+ if (Modifier.isStatic(field.getModifiers()) && field.getType() == Version.class) {
+ Version v = (Version)field.get(Version.class);
+ final boolean dep = field.isAnnotationPresent(Deprecated.class);
+ if (v.equals(Version.LATEST) && field.getName().equals("LUCENE_CURRENT") == false) {
+ assertFalse(field.getName() + " should not be deprecated", dep);
+ } else {
+ assertTrue(field.getName() + " should be deprecated", dep);
+ }
+ }
+ }
+ }
+
+ public void testLatestVersionCommonBuild() {
+ // common-build.xml sets 'tests.LUCENE_VERSION', if not, we skip this test!
+ String commonBuildVersion = System.getProperty("tests.LUCENE_VERSION");
+ assumeTrue("Null 'tests.LUCENE_VERSION' test property. You should run the tests with the official Lucene build file",
+ commonBuildVersion != null);
+ assertEquals("Version.LATEST does not match the one given in common-build.xml",
+ Version.LATEST.toString(), commonBuildVersion);
}
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestVersionComparator.java b/lucene/core/src/test/org/apache/lucene/util/TestVersionComparator.java
deleted file mode 100644
index 8c649d796f9..00000000000
--- a/lucene/core/src/test/org/apache/lucene/util/TestVersionComparator.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.apache.lucene.util;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.util.Comparator;
-
-/**
- * Tests for StringHelper.getVersionComparator
- */
-public class TestVersionComparator extends LuceneTestCase {
- public void testVersions() {
- Comparator comp = StringHelper.getVersionComparator();
- assertTrue(comp.compare("1", "2") < 0);
- assertTrue(comp.compare("1", "1") == 0);
- assertTrue(comp.compare("2", "1") > 0);
-
- assertTrue(comp.compare("1.1", "1") > 0);
- assertTrue(comp.compare("1", "1.1") < 0);
- assertTrue(comp.compare("1.1", "1.1") == 0);
-
- assertTrue(comp.compare("1.0", "1") == 0);
- assertTrue(comp.compare("1", "1.0") == 0);
- assertTrue(comp.compare("1.0.1", "1.0") > 0);
- assertTrue(comp.compare("1.0", "1.0.1") < 0);
-
- assertTrue(comp.compare("1.02.003", "1.2.3.0") == 0);
- assertTrue(comp.compare("1.2.3.0", "1.02.003") == 0);
-
- assertTrue(comp.compare("1.10", "1.9") > 0);
- assertTrue(comp.compare("1.9", "1.10") < 0);
-
- assertTrue(comp.compare("0", "1.0") < 0);
- assertTrue(comp.compare("00", "1.0") < 0);
- assertTrue(comp.compare("-1.0", "1.0") < 0);
- assertTrue(comp.compare("3.0", Integer.toString(Integer.MIN_VALUE)) > 0);
- }
-}
diff --git a/lucene/demo/src/java/org/apache/lucene/demo/facet/FacetExamples.java b/lucene/demo/src/java/org/apache/lucene/demo/facet/FacetExamples.java
index faf643cab49..f1b0de80501 100644
--- a/lucene/demo/src/java/org/apache/lucene/demo/facet/FacetExamples.java
+++ b/lucene/demo/src/java/org/apache/lucene/demo/facet/FacetExamples.java
@@ -28,6 +28,6 @@ public interface FacetExamples {
// :Post-Release-Update-Version.LUCENE_XY:
/** The Lucene {@link Version} used by the example code. */
- public static final Version EXAMPLES_VER = Version.LUCENE_5_0;
+ public static final Version EXAMPLES_VER = Version.LUCENE_5_0_0;
}
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java
index 18774fea2d1..29c307a6ae9 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldTermStack.java
@@ -41,13 +41,13 @@ public class FieldTermStack {
LinkedList termList = new LinkedList<>();
//public static void main( String[] args ) throws Exception {
- // Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_CURRENT);
- // QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, "f", analyzer );
+ // Analyzer analyzer = new WhitespaceAnalyzer(Version.LATEST);
+ // QueryParser parser = new QueryParser(Version.LATEST, "f", analyzer );
// Query query = parser.parse( "a x:b" );
// FieldQuery fieldQuery = new FieldQuery( query, true, false );
// Directory dir = new RAMDirectory();
- // IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer));
+ // IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LATEST, analyzer));
// Document doc = new Document();
// FieldType ft = new FieldType(TextField.TYPE_STORED);
// ft.setStoreTermVectors(true);
diff --git a/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java b/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java
index bf1e11abbcc..746c26b8ff3 100644
--- a/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java
+++ b/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java
@@ -170,7 +170,7 @@ public class MultiPassIndexSplitter {
} else {
input = new MultiReader(indexes.toArray(new IndexReader[indexes.size()]));
}
- splitter.split(Version.LUCENE_CURRENT, input, dirs, seq);
+ splitter.split(Version.LATEST, input, dirs, seq);
}
/**
diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java
index 80aa659f446..28e0d937a21 100644
--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java
+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java
@@ -260,7 +260,7 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
if (fieldName.equals("textgrams") && minPrefixChars > 0) {
// TODO: should use an EdgeNGramTokenFilterFactory here
TokenFilter filter;
- if (matchVersion.onOrAfter(Version.LUCENE_4_4)) {
+ if (matchVersion.onOrAfter(Version.LUCENE_4_4_0)) {
filter = new EdgeNGramTokenFilter(components.getTokenStream(), 1, minPrefixChars);
} else {
filter = new Lucene43EdgeNGramTokenFilter(components.getTokenStream(), 1, minPrefixChars);
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
index 579b4471d2c..d6038acd4bd 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
@@ -53,13 +53,13 @@ import org.apache.lucene.store.FlushInfo;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.Constants;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LineFileDocs;
import org.apache.lucene.util.RamUsageTester;
import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.UnicodeUtil;
+import org.apache.lucene.util.Version;
import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.AutomatonTestUtil.RandomAcceptedStrings;
import org.apache.lucene.util.automaton.AutomatonTestUtil;
@@ -675,7 +675,7 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTest
// randomly index at lower IndexOption
private FieldsProducer buildIndex(Directory dir, IndexOptions maxAllowed, boolean allowPayloads, boolean alwaysTestMax) throws IOException {
Codec codec = getCodec();
- SegmentInfo segmentInfo = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, "_0", maxDoc, false, codec, null);
+ SegmentInfo segmentInfo = new SegmentInfo(dir, Version.LATEST, "_0", maxDoc, false, codec, null);
int maxIndexOption = Arrays.asList(IndexOptions.values()).indexOf(maxAllowed);
if (VERBOSE) {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
index f1afee8c3de..5d2dc6111b4 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
@@ -373,7 +373,7 @@ public abstract class LuceneTestCase extends Assert {
* Use this constant when creating Analyzers and any other version-dependent stuff.
* NOTE: Change this when development starts for new Lucene version:
*/
- public static final Version TEST_VERSION_CURRENT = Version.LUCENE_5_0;
+ public static final Version TEST_VERSION_CURRENT = Version.LUCENE_5_0_0;
/**
* True if and only if tests are run in verbose mode. If this flag is false
diff --git a/solr/common-build.xml b/solr/common-build.xml
index 3655ca5b2aa..cedfb719d51 100644
--- a/solr/common-build.xml
+++ b/solr/common-build.xml
@@ -200,7 +200,7 @@
-
+
diff --git a/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java b/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java
index 42919174cff..d72d38b55fa 100644
--- a/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java
+++ b/solr/contrib/analysis-extras/src/java/org/apache/solr/schema/ICUCollationField.java
@@ -187,7 +187,7 @@ public class ICUCollationField extends FieldType {
rbc.setVariableTop(variableTop);
}
- analyzer = new ICUCollationKeyAnalyzer(Version.LUCENE_CURRENT, collator);
+ analyzer = new ICUCollationKeyAnalyzer(Version.LATEST, collator);
}
/**
diff --git a/solr/core/src/java/org/apache/solr/core/Config.java b/solr/core/src/java/org/apache/solr/core/Config.java
index 8d1ef498c5b..8ac097e22f7 100644
--- a/solr/core/src/java/org/apache/solr/core/Config.java
+++ b/solr/core/src/java/org/apache/solr/core/Config.java
@@ -443,14 +443,12 @@ public class Config {
version = Version.parseLeniently(matchVersion);
} catch (IllegalArgumentException iae) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Invalid luceneMatchVersion '" + matchVersion +
- "', valid values are: " + Arrays.toString(Version.values()) +
- " or a string in format 'V.V'", iae);
+ "Invalid luceneMatchVersion. Should be of the form 'V.V.V' (e.g. 4.8.0)", iae);
}
- if (version == Version.LUCENE_CURRENT && !versionWarningAlreadyLogged.getAndSet(true)) {
+ if (version == Version.LATEST && !versionWarningAlreadyLogged.getAndSet(true)) {
log.warn(
- "You should not use LUCENE_CURRENT as luceneMatchVersion property: "+
+ "You should not use LATEST as luceneMatchVersion property: "+
"if you use this setting, and then Solr upgrades to a newer release of Lucene, "+
"sizable changes may happen. If precise back compatibility is important "+
"then you should instead explicitly specify an actual Lucene version."
diff --git a/solr/core/src/java/org/apache/solr/core/SolrConfig.java b/solr/core/src/java/org/apache/solr/core/SolrConfig.java
index bab158fc8ff..3ab2a711094 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrConfig.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrConfig.java
@@ -163,19 +163,19 @@ public class SolrConfig extends Config {
luceneMatchVersion = getLuceneVersion("luceneMatchVersion");
String indexConfigPrefix;
- // Old indexDefaults and mainIndex sections are deprecated and fails fast for luceneMatchVersion=>LUCENE_4_0.
+ // Old indexDefaults and mainIndex sections are deprecated and fails fast for luceneMatchVersion=>LUCENE_4_0_0.
// For older solrconfig.xml's we allow the old sections, but never mixed with the new
boolean hasDeprecatedIndexConfig = (getNode("indexDefaults", false) != null) || (getNode("mainIndex", false) != null);
boolean hasNewIndexConfig = getNode("indexConfig", false) != null;
if(hasDeprecatedIndexConfig){
- if(luceneMatchVersion.onOrAfter(Version.LUCENE_4_0)) {
+ if(luceneMatchVersion.onOrAfter(Version.LUCENE_4_0_0)) {
throw new SolrException(ErrorCode.FORBIDDEN, " and configuration sections are discontinued. Use instead.");
} else {
// Still allow the old sections for older LuceneMatchVersion's
if(hasNewIndexConfig) {
throw new SolrException(ErrorCode.FORBIDDEN, "Cannot specify both , and at the same time. Please use only.");
}
- log.warn(" and configuration sections are deprecated and will fail for luceneMatchVersion=LUCENE_4_0 and later. Please use instead.");
+ log.warn(" and configuration sections are deprecated and will fail for luceneMatchVersion=LUCENE_4_0_0 and later. Please use instead.");
defaultIndexConfig = new SolrIndexConfig(this, "indexDefaults", null);
mainIndexConfig = new SolrIndexConfig(this, "mainIndex", defaultIndexConfig);
indexConfigPrefix = "mainIndex";
diff --git a/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java b/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
index 8cd3f26890b..ea0c2ca8319 100644
--- a/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
+++ b/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java
@@ -35,7 +35,6 @@ import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.util.*;
-import java.lang.reflect.Constructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -399,7 +398,7 @@ public final class FieldTypePluginLoader
Version version = (configuredVersion != null) ?
Config.parseLuceneVersionString(configuredVersion) : schema.getDefaultLuceneMatchVersion();
- if (!version.onOrAfter(Version.LUCENE_4_0)) {
+ if (!version.onOrAfter(Version.LUCENE_4_0_0)) {
log.warn(pluginClassName + " is using deprecated " + version +
" emulation. You should at some point declare and reindex to at least 4.0, because " +
"3.x emulation is deprecated and will be removed in 5.0");
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index 67ecb951161..c4fbc034a77 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -500,7 +500,7 @@ public class IndexSchema {
similarityFactory = new DefaultSimilarityFactory();
final NamedList similarityParams = new NamedList();
Version luceneVersion = getDefaultLuceneMatchVersion();
- if (!luceneVersion.onOrAfter(Version.LUCENE_4_7)) {
+ if (!luceneVersion.onOrAfter(Version.LUCENE_4_7_0)) {
similarityParams.add(DefaultSimilarityFactory.DISCOUNT_OVERLAPS, false);
}
similarityFactory.init(SolrParams.toSolrParams(similarityParams));
diff --git a/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java b/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
index e755f3c8fa1..24b4f5ab952 100644
--- a/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
+++ b/solr/core/src/test/org/apache/solr/analysis/TestLuceneMatchVersion.java
@@ -37,7 +37,7 @@ public class TestLuceneMatchVersion extends SolrTestCaseJ4 {
// this must match the solrconfig.xml version for this test
public static final Version DEFAULT_VERSION =
- Config.parseLuceneVersionString(System.getProperty("tests.luceneMatchVersion", "LUCENE_CURRENT"));
+ Config.parseLuceneVersionString(System.getProperty("tests.luceneMatchVersion", "LATEST"));
public void testStandardTokenizerVersions() throws Exception {
assertEquals(DEFAULT_VERSION, solrConfig.luceneMatchVersion);
@@ -51,18 +51,17 @@ public class TestLuceneMatchVersion extends SolrTestCaseJ4 {
type = schema.getFieldType("text40");
ana = (TokenizerChain) type.getIndexAnalyzer();
- assertEquals(Version.LUCENE_4_0, (ana.getTokenizerFactory()).getLuceneMatchVersion());
- assertEquals(Version.LUCENE_5_0, (ana.getTokenFilterFactories()[2]).getLuceneMatchVersion());
+ assertEquals(Version.LUCENE_4_0_0, (ana.getTokenizerFactory()).getLuceneMatchVersion());
+ assertEquals(Version.LUCENE_5_0_0, (ana.getTokenFilterFactories()[2]).getLuceneMatchVersion());
type = schema.getFieldType("textTurkishAnalyzerDefault");
Analyzer ana1 = type.getIndexAnalyzer();
assertTrue(ana1 instanceof TurkishAnalyzer);
- System.out.println("DEFAULT_VERSION = " + ana1.getVersion().name());
assertEquals(DEFAULT_VERSION, ana1.getVersion());
type = schema.getFieldType("textTurkishAnalyzer40");
ana1 = type.getIndexAnalyzer();
assertTrue(ana1 instanceof TurkishAnalyzer);
- assertEquals(Version.LUCENE_4_0, ana1.getVersion());
+ assertEquals(Version.LUCENE_4_0_0, ana1.getVersion());
}
}
diff --git a/solr/core/src/test/org/apache/solr/rest/schema/TestSerializedLuceneMatchVersion.java b/solr/core/src/test/org/apache/solr/rest/schema/TestSerializedLuceneMatchVersion.java
index d137eda4ac9..ca3d8ed8c25 100644
--- a/solr/core/src/test/org/apache/solr/rest/schema/TestSerializedLuceneMatchVersion.java
+++ b/solr/core/src/test/org/apache/solr/rest/schema/TestSerializedLuceneMatchVersion.java
@@ -45,13 +45,13 @@ public class TestSerializedLuceneMatchVersion extends RestTestBase {
"count(/response/lst[@name='fieldType']) = 1",
"//lst[str[@name='class'][.='org.apache.solr.analysis.MockCharFilterFactory']]"
- +" [str[@name='luceneMatchVersion'][.='LUCENE_4_0']]",
+ +" [str[@name='luceneMatchVersion'][.='4.0.0']]",
"//lst[str[@name='class'][.='org.apache.solr.analysis.MockTokenizerFactory']]"
- +" [str[@name='luceneMatchVersion'][.='LUCENE_4_0']]",
+ +" [str[@name='luceneMatchVersion'][.='4.0.0']]",
"//lst[str[@name='class'][.='org.apache.solr.analysis.MockTokenFilterFactory']]"
- +" [str[@name='luceneMatchVersion'][.='LUCENE_4_0']]");
+ +" [str[@name='luceneMatchVersion'][.='4.0.0']]");
}
@Test
diff --git a/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java b/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java
index 70cb5e0ffc4..f78e8d49aff 100644
--- a/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java
+++ b/solr/core/src/test/org/apache/solr/search/similarities/TestNonDefinedSimilarityFactory.java
@@ -18,7 +18,6 @@ package org.apache.solr.search.similarities;
*/
import org.apache.lucene.search.similarities.DefaultSimilarity;
-import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.util.Version;
import org.junit.After;
@@ -36,21 +35,21 @@ public class TestNonDefinedSimilarityFactory extends BaseSimilarityTestCase {
}
public void testCurrent() throws Exception {
- // no sys prop set, rely on LUCENE_CURRENT
+ // no sys prop set, rely on LATEST
initCore("solrconfig-basic.xml","schema-tiny.xml");
DefaultSimilarity sim = getSimilarity("text", DefaultSimilarity.class);
assertEquals(true, sim.getDiscountOverlaps());
}
public void test47() throws Exception {
- System.setProperty("tests.luceneMatchVersion", Version.LUCENE_4_7.toString());
+ System.setProperty("tests.luceneMatchVersion", Version.LUCENE_4_7_0.toString());
initCore("solrconfig-basic.xml","schema-tiny.xml");
DefaultSimilarity sim = getSimilarity("text", DefaultSimilarity.class);
assertEquals(true, sim.getDiscountOverlaps());
}
public void test46() throws Exception {
- System.setProperty("tests.luceneMatchVersion", Version.LUCENE_4_6.toString());
+ System.setProperty("tests.luceneMatchVersion", Version.LUCENE_4_6_0.toString());
initCore("solrconfig-basic.xml","schema-tiny.xml");
DefaultSimilarity sim = getSimilarity("text", DefaultSimilarity.class);
assertEquals(false, sim.getDiscountOverlaps());
diff --git a/solr/example/example-DIH/solr/db/conf/solrconfig.xml b/solr/example/example-DIH/solr/db/conf/solrconfig.xml
index e2a76c5a203..710ed72fd92 100755
--- a/solr/example/example-DIH/solr/db/conf/solrconfig.xml
+++ b/solr/example/example-DIH/solr/db/conf/solrconfig.xml
@@ -35,7 +35,7 @@
that you fully re-index after changing this setting as it can
affect both how text is indexed and queried.
-->
- 5.0
+ 5.0.0
- 5.0
+ 5.0.0
- 5.0
+ 5.0.0
- 5.0
+ 5.0.0
- 5.0
+ 5.0.0
- 5.0
+ 5.0.0
- 5.0
+ 5.0.0
diff --git a/solr/example/multicore/core1/conf/solrconfig.xml b/solr/example/multicore/core1/conf/solrconfig.xml
index ea88aedb2d1..cd2a1d549aa 100644
--- a/solr/example/multicore/core1/conf/solrconfig.xml
+++ b/solr/example/multicore/core1/conf/solrconfig.xml
@@ -21,7 +21,7 @@
It is *not* a good example to work from.
-->
- 5.0
+ 5.0.0
diff --git a/solr/example/solr/collection1/conf/solrconfig.xml b/solr/example/solr/collection1/conf/solrconfig.xml
index c3cb5f389cf..85160fe5dc3 100755
--- a/solr/example/solr/collection1/conf/solrconfig.xml
+++ b/solr/example/solr/collection1/conf/solrconfig.xml
@@ -35,7 +35,7 @@
that you fully re-index after changing this setting as it can
affect both how text is indexed and queried.
-->
- 5.0
+ 5.0.0