Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,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 @@ -327,7 +327,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
27 changes: 13 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,9 @@ 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";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Else block is missing. Could you add rev.trim() function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, really sorry about that. 😞 I squashed the commits from #137, but for whatever reason this latest change didn't make through. 🤔 Well, gonna change now. Thanks for pointing out!

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