|
@@ -21,6 +21,8 @@ package org.apache.zookeeper.version.util;
|
|
|
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;
|
|
|
}
|
|
|
}
|