From 41da3c8e3c39f81aa0f667199c5f4eb3d5a28adc Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 25 Jan 2017 17:27:25 +0530 Subject: [PATCH] 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 Author: Edward Ribeiro Reviewers: Mohammad Arshad , Michael Han Closes #155 from eribeiro/ZOOKEEPER-2573-3.5 --- build.xml | 4 +-- .../main/org/apache/zookeeper/Version.java | 13 ++++++++- .../apache/zookeeper/version/util/VerGen.java | 29 ++++++++++--------- .../test/org/apache/zookeeper/VerGenTest.java | 2 +- src/lastRevision.bat | 5 ++-- src/lastRevision.sh | 2 +- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/build.xml b/build.xml index bd62aaa5936..d4a0c923c1d 100644 --- a/build.xml +++ b/build.xml @@ -312,7 +312,7 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant"> includes="org/apache/zookeeper/version/util/**" debug="on" encoding="${build.encoding}" /> - + @@ -327,7 +327,7 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant"> - + diff --git a/src/java/main/org/apache/zookeeper/Version.java b/src/java/main/org/apache/zookeeper/Version.java index 46573717b0e..1f5cf1aa2df 100644 --- a/src/java/main/org/apache/zookeeper/Version.java +++ b/src/java/main/org/apache/zookeeper/Version.java @@ -20,10 +20,21 @@ 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 static String getVersion() { } public static String getVersionRevision() { - return getVersion() + "-" + getRevision(); + return getVersion() + "-" + getRevisionHash(); } public static String getFullVersion() { diff --git a/src/java/main/org/apache/zookeeper/version/util/VerGen.java b/src/java/main/org/apache/zookeeper/version/util/VerGen.java index d3e973102dd..014f01d90ba 100644 --- a/src/java/main/org/apache/zookeeper/version/util/VerGen.java +++ b/src/java/main/org/apache/zookeeper/version/util/VerGen.java @@ -34,7 +34,7 @@ static void printUsage() { 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 static void generateFile(File outputDir, Version version, int rev, String 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 static Version parseVersionString(String input) { *
  • min - minor version number *
  • micro - minor minor version number *
  • qualifier - optional qualifier (dash followed by qualifier text) - *
  • rev - current SVN revision number + *
  • rev - current Git revision number *
  • buildDate - date the build * */ @@ -149,11 +150,11 @@ public static void main(String[] args) { "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) { diff --git a/src/java/test/org/apache/zookeeper/VerGenTest.java b/src/java/test/org/apache/zookeeper/VerGenTest.java index 15d8c8fb6c0..1d99e454691 100644 --- a/src/java/test/org/apache/zookeeper/VerGenTest.java +++ b/src/java/test/org/apache/zookeeper/VerGenTest.java @@ -73,7 +73,7 @@ public void testParser() { 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); } } diff --git a/src/lastRevision.bat b/src/lastRevision.bat index e31a6b96c34..68999471db6 100644 --- a/src/lastRevision.bat +++ b/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 ) diff --git a/src/lastRevision.sh b/src/lastRevision.sh index a462990e742..0690c7da916 100755 --- a/src/lastRevision.sh +++ b/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