Repository: zookeeper Updated Branches: refs/heads/branch-3.4 3271f3d03 -> d6bbfd76d
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.ribe...@gmail.com> Author: Edward Ribeiro <eribe...@users.noreply.github.com> Reviewers: Mohammad Arshad <ars...@apache.org>, Michael Han <h...@apache.org> Closes #155 from eribeiro/ZOOKEEPER-2573-3.5 (cherry picked from commit 41da3c8e3c39f81aa0f667199c5f4eb3d5a28adc) Signed-off-by: Rakesh Radhakrishnan <rake...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/d6bbfd76 Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/d6bbfd76 Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/d6bbfd76 Branch: refs/heads/branch-3.4 Commit: d6bbfd76d24c044073764c5d074a9198c69fafab Parents: 3271f3d Author: Edward Ribeiro <edward.ribe...@gmail.com> Authored: Wed Jan 25 17:27:25 2017 +0530 Committer: Rakesh Radhakrishnan <rake...@apache.org> Committed: Wed Jan 25 17:39:23 2017 +0530 ---------------------------------------------------------------------- build.xml | 4 +-- src/java/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(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zookeeper/blob/d6bbfd76/build.xml ---------------------------------------------------------------------- diff --git a/build.xml b/build.xml index aec3aa5..864c5a4 100644 --- a/build.xml +++ b/build.xml @@ -309,7 +309,7 @@ xmlns:maven="antlib:org.apache.maven.artifact.ant"> includes="org/apache/zookeeper/version/util/**" debug="on" /> </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"/> @@ -324,7 +324,7 @@ xmlns:maven="antlib:org.apache.maven.artifact.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}"> http://git-wip-us.apache.org/repos/asf/zookeeper/blob/d6bbfd76/src/java/main/org/apache/zookeeper/Version.java ---------------------------------------------------------------------- diff --git a/src/java/main/org/apache/zookeeper/Version.java b/src/java/main/org/apache/zookeeper/Version.java index 4657371..1f5cf1a 100644 --- a/src/java/main/org/apache/zookeeper/Version.java +++ b/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() { http://git-wip-us.apache.org/repos/asf/zookeeper/blob/d6bbfd76/src/java/main/org/apache/zookeeper/version/util/VerGen.java ---------------------------------------------------------------------- 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 d4cbeb6..93a0710 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 @@ 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); @@ -76,18 +76,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) { @@ -146,7 +147,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> */ @@ -160,11 +161,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) { http://git-wip-us.apache.org/repos/asf/zookeeper/blob/d6bbfd76/src/java/test/org/apache/zookeeper/VerGenTest.java ---------------------------------------------------------------------- diff --git a/src/java/test/org/apache/zookeeper/VerGenTest.java b/src/java/test/org/apache/zookeeper/VerGenTest.java index 13d3abd..607edbb 100644 --- a/src/java/test/org/apache/zookeeper/VerGenTest.java +++ b/src/java/test/org/apache/zookeeper/VerGenTest.java @@ -72,7 +72,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); } } http://git-wip-us.apache.org/repos/asf/zookeeper/blob/d6bbfd76/src/lastRevision.bat ---------------------------------------------------------------------- diff --git a/src/lastRevision.bat b/src/lastRevision.bat index e31a6b9..6899947 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 ) http://git-wip-us.apache.org/repos/asf/zookeeper/blob/d6bbfd76/src/lastRevision.sh ---------------------------------------------------------------------- diff --git a/src/lastRevision.sh b/src/lastRevision.sh index a462990..0690c7d 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