Skip to content

Commit

Permalink
ZOOKEEPER-2573: Modify Info.REVISION to adapt git repo
Browse files Browse the repository at this point in the history
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 apache#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. 😃

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 apache#155 from eribeiro/ZOOKEEPER-2573-3.5

(cherry picked from commit 41da3c8)
Signed-off-by: Rakesh Radhakrishnan <rakeshr@apache.org>
  • Loading branch information
eribeiro authored and Fangmin Lyu committed Jun 17, 2018
1 parent 21681b3 commit e7a3460
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand All @@ -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}">
Expand Down
13 changes: 12 additions & 1 deletion src/java/main/org/apache/zookeeper/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -34,7 +45,7 @@ public static String getVersion() {
}

public static String getVersionRevision() {
return getVersion() + "-" + getRevision();
return getVersion() + "-" + getRevisionHash();
}

public static String getFullVersion() {
Expand Down
29 changes: 15 additions & 14 deletions src/java/main/org/apache/zookeeper/version/util/VerGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -135,7 +136,7 @@ public static Version parseVersionString(String input) {
* <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>
*/
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/java/test/org/apache/zookeeper/VerGenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 2 additions & 3 deletions src/lastRevision.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion src/lastRevision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e7a3460

Please sign in to comment.