浏览代码

ZOOKEEPER-2573: Modify Info.REVISION to adapt git repo

rakeshadr Hi, I have created this PR. The commit can be cherry picked on master too. In fact, I guess when you merge this then #137 will be automatically closed. I tested quickly and was able to cherry-pick this commit on branch-3.4 too, so you may want to give it a try. :smiley:

Author: Edward Ribeiro <edward.ribeiro@gmail.com>
Author: Edward Ribeiro <eribeiro@users.noreply.github.com>

Reviewers: Mohammad Arshad <arshad@apache.org>, Michael Han <hanm@apache.org>

Closes #155 from eribeiro/ZOOKEEPER-2573-3.5

(cherry picked from commit 41da3c8e3c39f81aa0f667199c5f4eb3d5a28adc)
Signed-off-by: Rakesh Radhakrishnan <rakeshr@apache.org>
Edward Ribeiro 8 年之前
父节点
当前提交
8771ffdaac

+ 2 - 2
build.xml

@@ -313,7 +313,7 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant">
             includes="org/apache/zookeeper/version/util/**" debug="on" encoding="${build.encoding}" />
     </target>
     
-    <target name="svn-revision" unless="lastRevision">
+    <target name="git-revision" unless="lastRevision">
         <mkdir dir="${revision.dir}" />
         <condition property="shell.name" value="cmd" else="sh">
       	    <os family="windows"/>
@@ -328,7 +328,7 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant">
         <property file="${revision.dir}/${revision.properties}" />
     </target>
     
-    <target name="version-info" depends="ver-gen,svn-revision">
+    <target name="version-info" depends="ver-gen,git-revision">
         <mkdir dir="${src_generated.dir}" />
         <java classname="org.apache.zookeeper.version.util.VerGen" fork="true" 
                 dir="${src_generated.dir}">

+ 12 - 1
src/java/main/org/apache/zookeeper/Version.java

@@ -20,10 +20,21 @@ package org.apache.zookeeper;
 
 public class Version implements org.apache.zookeeper.version.Info {
 
+    /*
+     * Since the SVN to Git port this field doesn't return the revision anymore
+     * TODO: remove this method and associated field declaration in VerGen
+     * @see {@link #getHashRevision()}
+     * @return the default value -1
+     */
+    @Deprecated
     public static int getRevision() {
         return REVISION;
     }
 
+    public static String getRevisionHash() {
+        return REVISION_HASH;
+    }
+
     public static String getBuildDate() {
         return BUILD_DATE;
     }
@@ -34,7 +45,7 @@ public class Version implements org.apache.zookeeper.version.Info {
     }
 
     public static String getVersionRevision() {
-        return getVersion() + "-" + getRevision();
+        return getVersion() + "-" + getRevisionHash();
     }
 
     public static String getFullVersion() {

+ 15 - 14
src/java/main/org/apache/zookeeper/version/util/VerGen.java

@@ -34,7 +34,7 @@ public class VerGen {
         System.exit(1);
     }
 
-    public static void generateFile(File outputDir, Version version, int rev, String buildDate)
+    public static void generateFile(File outputDir, Version version, String rev, String buildDate)
     {
         String path = PACKAGE_NAME.replaceAll("\\.", "/");
         File pkgdir = new File(outputDir, path);
@@ -74,18 +74,19 @@ public class VerGen {
             w.write("\n");
             w.write("package " + PACKAGE_NAME + ";\n\n");
             w.write("public interface " + TYPE_NAME + " {\n");
-            w.write("    public static final int MAJOR=" + version.maj + ";\n");
-            w.write("    public static final int MINOR=" + version.min + ";\n");
-            w.write("    public static final int MICRO=" + version.micro + ";\n");
-            w.write("    public static final String QUALIFIER="
+            w.write("    int MAJOR=" + version.maj + ";\n");
+            w.write("    int MINOR=" + version.min + ";\n");
+            w.write("    int MICRO=" + version.micro + ";\n");
+            w.write("    String QUALIFIER="
                     + (version.qualifier == null ? null :
                         "\"" + version.qualifier + "\"")
                     + ";\n");
-            if (rev < 0) {
+            if (rev.equals("-1")) {
                 System.out.println("Unknown REVISION number, using " + rev);
             }
-            w.write("    public static final int REVISION=" + rev + ";\n");
-            w.write("    public static final String BUILD_DATE=\"" + buildDate
+            w.write("    int REVISION=-1; //TODO: remove as related to SVN VCS\n");
+            w.write("    String REVISION_HASH=\"" + rev + "\";\n");
+            w.write("    String BUILD_DATE=\"" + buildDate
                     + "\";\n");
             w.write("}\n");
         } catch (IOException e) {
@@ -135,7 +136,7 @@ public class VerGen {
      *            <li>min - minor version number
      *            <li>micro - minor minor version number
      *            <li>qualifier - optional qualifier (dash followed by qualifier text)
-     *            <li>rev - current SVN revision number
+     *            <li>rev - current Git revision number
      *            <li>buildDate - date the build
      *            </ul>
      */
@@ -149,11 +150,11 @@ public class VerGen {
                         "Invalid version number format, must be \"x.y.z(-.*)?\"");
                 System.exit(1);
             }
-            int rev;
-            try {
-                rev = Integer.parseInt(args[1]);
-            } catch (NumberFormatException e) {
-                rev = -1;
+            String rev = args[1];
+            if (rev == null || rev.trim().isEmpty()) {
+                rev = "-1";
+            } else {
+                rev = rev.trim();
             }
             generateFile(new File("."), version, rev, args[2]);
         } catch (NumberFormatException e) {

+ 1 - 1
src/java/test/org/apache/zookeeper/VerGenTest.java

@@ -73,7 +73,7 @@ public class VerGenTest extends ZKTestCase {
     public void testGenFile() throws Exception {
         VerGen.Version v = VerGen.parseVersionString(input);
         File outputDir = ClientBase.createTmpDir();
-        VerGen.generateFile(outputDir, v, 1, "Nov1");
+        VerGen.generateFile(outputDir, v, "1", "Nov1");
         ClientBase.recursiveDelete(outputDir);
     }
 }

+ 2 - 3
src/lastRevision.bat

@@ -16,8 +16,7 @@ rem See the License for the specific language governing permissions and
 rem limitations under the License.
 
 rem Find the current revision, store it in a file, for DOS
-svn info | findstr Revision > %1
 
-For /F "tokens=1,2 delims= " %%a In (%1) Do (
-	echo lastRevision=%%b> %1
+for /f "delims=" %%i in ('git rev-parse HEAD') do set rev=%%i
+       echo lastRevision=%rev% > %1
 )

+ 1 - 1
src/lastRevision.sh

@@ -16,6 +16,6 @@
 
 # Find the current revision, store it in a file
 FILE=$1
-LASTREV=`svn info | grep '^Revision' | sed -e 's/Revision: *//'`
+LASTREV=`git rev-parse HEAD`
 
 echo "lastRevision=${LASTREV}" > $FILE