Author: phunt
Date: Thu Jan 27 07:44:32 2011
New Revision: 1064014
URL: http://svn.apache.org/viewvc?rev=1064014&view=rev
Log:
ZOOKEEPER-913. Version parser fails to parse "3.3.2-dev" from build.xml
Added:
zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/VerGenTest.java
Modified:
zookeeper/branches/branch-3.3/CHANGES.txt
zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/Version.java
zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/version/util/VerGen.java
Modified: zookeeper/branches/branch-3.3/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/CHANGES.txt?rev=1064014&r1=1064013&r2=1064014&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.3/CHANGES.txt Thu Jan 27 07:44:32 2011
@@ -9,9 +9,14 @@ BUGFIXES:
ZOOKEEPER-921. zkPython incorrectly checks for existence of required
ACL elements (Nicholas Knight via henryr)
- ZOOKEEPER-882. Startup loads last transaction from snapshot (Jared Cantwell via breed)
+ ZOOKEEPER-882. Startup loads last transaction from snapshot
+ (Jared Cantwell via breed)
- ZOOKEEPER-962. leader/follower coherence issue when follower is receiving a DIFF (Camille
Fournier via breed)
+ ZOOKEEPER-962. leader/follower coherence issue when follower is receiving a
+ DIFF (Camille Fournier via breed)
+
+ ZOOKEEPER-913. Version parser fails to parse "3.3.2-dev" from build.xml
+ (Anthony Urso and phunt via phunt)
IMPROVEMENTS:
ZOOKEEPER-963. Make Forrest work with JDK6 (Carl Steinbach via henryr)
Modified: zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/Version.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/Version.java?rev=1064014&r1=1064013&r2=1064014&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/Version.java (original)
+++ zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/Version.java Thu Jan
27 07:44:32 2011
@@ -18,7 +18,7 @@
package org.apache.zookeeper;
-public class Version implements org.apache.zookeeper.version.Info{
+public class Version implements org.apache.zookeeper.version.Info {
public static int getRevision() {
return REVISION;
@@ -29,7 +29,8 @@ public class Version implements org.apac
}
public static String getVersion() {
- return MAJOR + "." + MINOR + "." + MICRO;
+ return MAJOR + "." + MINOR + "." + MICRO
+ + (QUALIFIER == null ? "" : "-" + QUALIFIER);
}
public static String getVersionRevision() {
Modified: zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/version/util/VerGen.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/version/util/VerGen.java?rev=1064014&r1=1064013&r2=1064014&view=diff
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/version/util/VerGen.java
(original)
+++ zookeeper/branches/branch-3.3/src/java/main/org/apache/zookeeper/version/util/VerGen.java
Thu Jan 27 07:44:32 2011
@@ -21,6 +21,8 @@ package org.apache.zookeeper.version.uti
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class VerGen {
private static final String PACKAGE_NAME = "org.apache.zookeeper.version";
@@ -28,12 +30,12 @@ public class VerGen {
static void printUsage() {
System.out.print("Usage:\tjava -cp <classpath> org.apache.zookeeper."
- + "version.util.VerGen maj.min.micro rev buildDate");
+ + "version.util.VerGen maj.min.micro[-qualifier] rev buildDate");
System.exit(1);
}
- static void generateFile(File outputDir, int maj, int min, int micro, int rev,
- String buildDate) {
+ public static void generateFile(File outputDir, Version version, int rev, String buildDate)
+ {
String path = PACKAGE_NAME.replaceAll("\\.", "/");
File pkgdir = new File(outputDir, path);
if (!pkgdir.exists()) {
@@ -74,9 +76,13 @@ 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=" + maj + ";\n");
- w.write(" public static final int MINOR=" + min + ";\n");
- w.write(" public static final int MICRO=" + micro + ";\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="
+ + (version.qualifier == null ? null :
+ "\"" + version.qualifier + "\"")
+ + ";\n");
if (rev < 0) {
System.out.println("Unknown REVISION number, using " + rev);
}
@@ -100,18 +106,46 @@ public class VerGen {
}
}
+ public static class Version {
+ public int maj;
+ public int min;
+ public int micro;
+ public String qualifier;
+ }
+
+ public static Version parseVersionString(String input) {
+ Version result = new Version();
+
+ Pattern p = Pattern.compile("^(\\d+).(\\d+).(\\d+)(-(.+))?$");
+ Matcher m = p.matcher(input);
+
+ if (!m.matches()) {
+ return null;
+ }
+ result.maj = Integer.parseInt(m.group(1));
+ result.min = Integer.parseInt(m.group(2));
+ result.micro = Integer.parseInt(m.group(3));
+ if (m.groupCount() == 5) {
+ result.qualifier = m.group(5);
+ } else {
+ result.qualifier = null;
+ }
+ return result;
+ }
+
/**
* Emits a org.apache.zookeeper.version.Info interface file with version and
* revision information constants set to the values passed in as command
* line parameters. The file is created in the current directory. <br>
- * Usage: java org.apache.zookeeper.version.util.VerGen maj.min.micro rev
- * buildDate
+ * Usage: java org.apache.zookeeper.version.util.VerGen maj.min.micro[-qualifier]
+ * rev buildDate
*
* @param args
* <ul>
* <li>maj - major version number
* <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>buildDate - date the build
* </ul>
@@ -120,25 +154,22 @@ public class VerGen {
if (args.length != 3)
printUsage();
try {
- String[] v = args[0].split("\\.");
- if (v.length != 3) {
- System.err
- .println("Invalid version number format, must be \"x.y.z\"");
+ Version version = parseVersionString(args[0]);
+ if (version == null) {
+ System.err.println(
+ "Invalid version number format, must be \"x.y.z(-.*)?\"");
System.exit(1);
}
- int maj = Integer.parseInt(v[0]);
- int min = Integer.parseInt(v[1]);
- int micro = Integer.parseInt(v[2]);
int rev;
try {
rev = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
rev = -1;
}
- generateFile(new File("."), maj, min, micro, rev, args[2]);
+ generateFile(new File("."), version, rev, args[2]);
} catch (NumberFormatException e) {
- System.err
- .println("All version-related parameters must be valid integers!");
+ System.err.println(
+ "All version-related parameters must be valid integers!");
throw e;
}
}
Added: zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/VerGenTest.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/VerGenTest.java?rev=1064014&view=auto
==============================================================================
--- zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/VerGenTest.java (added)
+++ zookeeper/branches/branch-3.3/src/java/test/org/apache/zookeeper/VerGenTest.java Thu Jan
27 07:44:32 2011
@@ -0,0 +1,77 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zookeeper;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.apache.zookeeper.test.ClientBase;
+import org.apache.zookeeper.version.util.VerGen;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+
+/**
+ * Test VerGen, used during the build.
+ *
+ */
+@RunWith(Parameterized.class)
+public class VerGenTest extends TestCase {
+ @Parameters
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ {"1.2.3", new Object[] {1, 2, 3, null}},
+ {"1.2.3-dev", new Object[] {1, 2, 3, "dev"}},
+ {"1.2.3-SNAPSHOT", new Object[] {1, 2, 3, "SNAPSHOT"}},
+ {"1.2.3-foo-bar+123", new Object[] {1, 2, 3, "foo-bar+123"}}
+ });
+ }
+
+ private String input;
+
+ private Object[] expected;
+
+ public VerGenTest(String input, Object[] expected) {
+ this.input = input;
+ this.expected = expected;
+ }
+
+ @Test
+ public void testParser() {
+ VerGen.Version v = VerGen.parseVersionString(input);
+ Assert.assertEquals(expected[0], v.maj);
+ Assert.assertEquals(expected[1], v.min);
+ Assert.assertEquals(expected[2], v.micro);
+ Assert.assertEquals(expected[3], v.qualifier);
+ }
+
+ @Test
+ public void testGenFile() throws Exception {
+ VerGen.Version v = VerGen.parseVersionString(input);
+ File outputDir = ClientBase.createTmpDir();
+ VerGen.generateFile(outputDir, v, 1, "Nov1");
+ ClientBase.recursiveDelete(outputDir);
+ }
+}
|