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 2014/03/18 15:51:23 UTC

svn commit: r1578936 - in /lucene/dev/branches/lucene_solr_4_7: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/util/ lucene/core/src/test/org/apache/lucene/index/ lucene/core/src/test/org/apache/lucene/util/

Author: uschindler
Date: Tue Mar 18 14:51:22 2014
New Revision: 1578936

URL: http://svn.apache.org/r1578936
Log:
Merged revision(s) 1578933 from lucene/dev/branches/branch_4x:
Merged revision(s) 1578930 from lucene/dev/trunk:
LUCENE-5537: Fix version checks in TestCheckIndex -> TestConstants, use version instead dev.version for tests

Added:
    lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/util/TestConstants.java
      - copied unchanged from r1578933, lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestConstants.java
Modified:
    lucene/dev/branches/lucene_solr_4_7/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/common-build.xml   (contents, props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/core/   (props changed)
    lucene/dev/branches/lucene_solr_4_7/lucene/core/src/java/org/apache/lucene/util/Constants.java
    lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java
    lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/util/TestVersion.java

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/common-build.xml?rev=1578936&r1=1578935&r2=1578936&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/common-build.xml (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/common-build.xml Tue Mar 18 14:51:22 2014
@@ -973,7 +973,7 @@
             <sysproperty key="java.security.manager" value="org.apache.lucene.util.TestSecurityManager" />
             <sysproperty key="java.security.policy" file="${common.dir}/tools/junit4/tests.policy" />
 
-            <sysproperty key="lucene.version" value="${dev.version}"/>
+            <sysproperty key="lucene.version" value="${version}"/>
 
             <sysproperty key="jetty.testMode" value="1"/>
             <sysproperty key="jetty.insecurerandom" value="1"/>
@@ -2401,7 +2401,7 @@ The following arguments can be provided 
 
         <junit4:pickseed property="pitest.seed" />
 
-        <property name="pitest.sysprops" value="-Dlucene.version=${dev.version},-Dtest.seed=${pitest.seed},-Djava.security.manager=org.apache.lucene.util.TestSecurityManager,-Djava.security.policy=${common.dir}/tools/junit4/tests.policy,-Djava.io.tmpdir=${tests.workDir},-Djunit4.childvm.cwd=${tests.workDir},-Djunit4.tempDir=${tests.workDir}" />
+        <property name="pitest.sysprops" value="-Dlucene.version=${version},-Dtest.seed=${pitest.seed},-Djava.security.manager=org.apache.lucene.util.TestSecurityManager,-Djava.security.policy=${common.dir}/tools/junit4/tests.policy,-Djava.io.tmpdir=${tests.workDir},-Djunit4.childvm.cwd=${tests.workDir},-Djunit4.tempDir=${tests.workDir}" />
 
         <pitest
             classPath="pitest.classpath"

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/core/src/java/org/apache/lucene/util/Constants.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/core/src/java/org/apache/lucene/util/Constants.java?rev=1578936&r1=1578935&r2=1578936&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/core/src/java/org/apache/lucene/util/Constants.java (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/core/src/java/org/apache/lucene/util/Constants.java Tue Mar 18 14:51:22 2014
@@ -118,11 +118,14 @@ public final class Constants {
     return s.toString();
   }
   
-  // NOTE: we track per-segment version as a String with the "X.Y" format, e.g.
-  // "4.0", "3.1", "3.0". Therefore when we change this constant, we should keep
-  // the format.
+  // 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"}.
+   * <p>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.
    */
   public static final String LUCENE_MAIN_VERSION = ident("4.7");
 
@@ -134,15 +137,20 @@ public final class Constants {
     Package pkg = LucenePackage.get();
     String v = (pkg == null) ? null : pkg.getImplementationVersion();
     if (v == null) {
-      String parts[] = LUCENE_MAIN_VERSION.split("\\.");
-      if (parts.length == 4) {
-        // alpha/beta
-        assert parts[2].equals("0");
-        v = parts[0] + "." + parts[1] + "-SNAPSHOT";
-      } else {
-        v = LUCENE_MAIN_VERSION + "-SNAPSHOT";
-      }
+      v = mainVersionWithoutAlphaBeta() + "-SNAPSHOT";
     }
     LUCENE_VERSION = ident(v);
   }
+  
+  /**
+   * Returns a LUCENE_MAIN_VERSION without any ALPHA/BETA qualifier
+   * Used by test only!
+   */
+  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;
+  }
 }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java?rev=1578936&r1=1578935&r2=1578936&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/index/TestCheckIndex.java Tue Mar 18 14:51:22 2014
@@ -32,7 +32,6 @@ import org.apache.lucene.document.Docume
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType;
 import org.apache.lucene.document.TextField;
-import org.apache.lucene.util.Constants;
 
 public class TestCheckIndex extends LuceneTestCase {
 
@@ -114,26 +113,4 @@ public class TestCheckIndex extends Luce
     iw.close();
     dir.close(); // checkindex
   }
-
-  public void testLuceneConstantVersion() throws IOException {
-    // common-build.xml sets lucene.version
-    String version = System.getProperty("lucene.version");
-    assertNotNull( "null version", version);
-    // remove anything after a "-" from the version string:
-    version = version.replaceAll("-.*$", "");
-    final String constantVersion;
-    String parts[] = Constants.LUCENE_MAIN_VERSION.split("\\.");
-    if (parts.length == 4) {
-      // alpha/beta version: pull the real portion
-      assert parts[2].equals("0");
-      constantVersion = parts[0] + "." + parts[1];
-    } else {
-      // normal version
-      constantVersion = Constants.LUCENE_MAIN_VERSION;
-    }
-    assertTrue("Invalid version: "+version,
-               version.equals(constantVersion));
-    assertTrue(Constants.LUCENE_VERSION + " should start with: "+version,
-               Constants.LUCENE_VERSION.startsWith(version));
-  }
 }

Modified: lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/util/TestVersion.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/util/TestVersion.java?rev=1578936&r1=1578935&r2=1578936&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/util/TestVersion.java (original)
+++ lucene/dev/branches/lucene_solr_4_7/lucene/core/src/test/org/apache/lucene/util/TestVersion.java Tue Mar 18 14:51:22 2014
@@ -49,4 +49,14 @@ public class TestVersion extends LuceneT
       }
     }
   }
+  
+  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]);
+  }
 }