diff --git a/src/net/java/sip/communicator/impl/version/VersionImpl.java b/src/net/java/sip/communicator/impl/version/VersionImpl.java index cbb16c70b..abe4c9ee2 100644 --- a/src/net/java/sip/communicator/impl/version/VersionImpl.java +++ b/src/net/java/sip/communicator/impl/version/VersionImpl.java @@ -25,6 +25,11 @@ public class VersionImpl */ public static final int VERSION_MAJOR = 1; + /** + * The version major field. Default value is VERSION_MAJOR. + */ + private int versionMajor = VERSION_MAJOR; + /** * The version major of the current Jitsi version. In an * example 2.3.1 version string 2 is the version major. The version major @@ -33,6 +38,11 @@ public class VersionImpl */ public static final int VERSION_MINOR = 1; + /** + * The version minor field. Default value is VERSION_MINOR. + */ + private int versionMinor = VERSION_MINOR; + /** * Indicates whether this version represents a prerelease (i.e. a * non-complete release like an alpha, beta or release candidate version). @@ -51,6 +61,11 @@ public class VersionImpl */ public static final boolean IS_NIGHTLY_BUILD = true; + /** + * The nightly build id field. Default value is NightlyBuildID.BUILD_ID. + */ + private String nightlyBuildID = NightlyBuildID.BUILD_ID; + /** * The default name of this application. */ @@ -67,6 +82,28 @@ public class VersionImpl */ public static final VersionImpl CURRENT_VERSION = new VersionImpl(); + /** + * Creates version object with default (current) values. + */ + private VersionImpl() + {} + + /** + * Creates version object with custom major, minor and nightly build id. + * + * @param majorVersion the major version to use. + * @param minorVersion the minor version to use. + * @param nightlyBuildID the nightly build id value for new version object. + */ + private VersionImpl(int majorVersion, + int minorVersion, + String nightlyBuildID) + { + this.versionMajor = majorVersion; + this.versionMinor = minorVersion; + this.nightlyBuildID = nightlyBuildID; + } + /** * Returns the version major of the current Jitsi version. In an * example 2.3.1 version string 2 is the version major. The version major @@ -77,7 +114,7 @@ public class VersionImpl */ public int getVersionMajor() { - return VERSION_MAJOR; + return versionMajor; } /** @@ -90,7 +127,7 @@ public int getVersionMajor() */ public int getVersionMinor() { - return VERSION_MINOR; + return versionMinor; } /** @@ -118,7 +155,7 @@ public String getNightlyBuildID() if(!isNightly()) return null; - return NightlyBuildID.BUILD_ID; + return nightlyBuildID; } /** @@ -160,11 +197,16 @@ public String getPreReleaseID() */ public int compareTo(Version version) { - //our versioning system is built to produce lexicographically ordered - //names so we could simply return the comparison of the version strings. - return toString().compareTo( (version == null) - ? "null" - : version.toString()); + if(version == null) + return -1; + + if(getVersionMajor() != version.getVersionMajor()) + return getVersionMajor() - version.getVersionMajor(); + + if(getVersionMinor() != version.getVersionMinor()) + return getVersionMinor() - version.getVersionMinor(); + + return getNightlyBuildID().compareTo(version.getNightlyBuildID()); } /** @@ -230,6 +272,24 @@ public static final VersionImpl currentVersion() return CURRENT_VERSION; } + /** + * Returns the VersionImpl instance describing the version with the + * parameters supplied. + * + * @param majorVersion the major version to use. + * @param minorVersion the minor version to use. + * @param nightlyBuildID the nightly build id value for new version object. + * @return the VersionImpl instance describing the version with parameters + * supplied. + */ + public static final VersionImpl customVersion( + int majorVersion, + int minorVersion, + String nightlyBuildID) + { + return new VersionImpl(majorVersion, minorVersion, nightlyBuildID); + } + /** * Returns the name of the application that we're currently running. Default * MUST be Jitsi. diff --git a/src/net/java/sip/communicator/impl/version/VersionServiceImpl.java b/src/net/java/sip/communicator/impl/version/VersionServiceImpl.java index db0ea7e8a..d18ca996a 100644 --- a/src/net/java/sip/communicator/impl/version/VersionServiceImpl.java +++ b/src/net/java/sip/communicator/impl/version/VersionServiceImpl.java @@ -8,8 +8,10 @@ import org.jitsi.service.version.*; +import java.util.regex.*; + /** - * The version service keeps track of the SIP Communicator version that we are + * The version service keeps track of the Jitsi version that we are * currently running. Other modules (such as a Help->About dialog) query and * use this service in order to show the current application version. *
@@ -21,13 +23,18 @@ public class VersionServiceImpl implements VersionService { + /** + * The pattern that will parse strings to version object. + */ + private static final Pattern PARSE_VERSION_STRING_PATTERN = + Pattern.compile("(\\d+)\\.(\\d+)\\.([\\d\\.]+)"); /** * Returns a Version object containing version details of the - * SIP Communicator version that we're currently running. + * Jitsi version that we're currently running. * * @return a Version object containing version details of the - * SIP Communicator version that we're currently running. + * Jitsi version that we're currently running. */ public Version getCurrentVersion() { @@ -41,11 +48,20 @@ public Version getCurrentVersion() * @param version a version String that we have obtained by calling a * Version.toString() method. * @return the Version object corresponding to the - * version string. + * version string. Or null if we cannot parse the string. */ public Version parseVersionString(String version) { - /** @todo implement parseVersionString() */ + Matcher matcher = PARSE_VERSION_STRING_PATTERN.matcher(version); + + if(matcher.matches() && matcher.groupCount() == 3) + { + return VersionImpl.customVersion( + Integer.parseInt(matcher.group(1)), + Integer.parseInt(matcher.group(2)), + matcher.group(3)); + } + return null; } }