diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index ebed1392..21392124 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -363,6 +363,12 @@ 3.5.1 + + org.apache.maven + maven-artifact + 3.3.9 + + diff --git a/libresonic-main/src/main/java/org/libresonic/player/Logger.java b/libresonic-main/src/main/java/org/libresonic/player/Logger.java index d1ea567a..54ba379c 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/Logger.java +++ b/libresonic-main/src/main/java/org/libresonic/player/Logger.java @@ -115,7 +115,7 @@ public class Logger { return true; // versionService not yet available. } Version localVersion = versionService.getLocalVersion(); - debugEnabled = localVersion == null || localVersion.getBeta() != 0; + debugEnabled = localVersion == null || localVersion.isPreview(); } return debugEnabled; } diff --git a/libresonic-main/src/main/java/org/libresonic/player/domain/Version.java b/libresonic-main/src/main/java/org/libresonic/player/domain/Version.java index 8b105e28..9736c8e3 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/domain/Version.java +++ b/libresonic-main/src/main/java/org/libresonic/player/domain/Version.java @@ -19,6 +19,10 @@ */ package org.libresonic.player.domain; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; + /** * Represents the version number of Libresonic. * @@ -26,39 +30,22 @@ package org.libresonic.player.domain; * @version $Revision: 1.3 $ $Date: 2006/01/20 21:25:16 $ */ public class Version implements Comparable { - private int major; - private int minor; - private int beta; - private int bugfix; + private final DefaultArtifactVersion internalVersion; /** * Creates a new version instance by parsing the given string. * @param version A string of the format "1.27", "1.27.2" or "1.27.beta3". */ public Version(String version) { - String[] s = version.split("\\."); - major = Integer.valueOf(s[0]); - minor = Integer.valueOf(s[1]); - - if (s.length > 2) { - if (s[2].contains("beta")) { - beta = Integer.valueOf(s[2].replace("beta", "")); - } else { - bugfix = Integer.valueOf(s[2]); - } - } + this.internalVersion = new DefaultArtifactVersion(version); } public int getMajor() { - return major; + return internalVersion.getMajorVersion(); } public int getMinor() { - return minor; - } - - public int getBeta() { - return beta; + return internalVersion.getMinorVersion(); } /** @@ -67,15 +54,11 @@ public class Version implements Comparable { * @return Whether this object is equals to another. */ public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final Version version = (Version) o; - - if (beta != version.beta) return false; - if (bugfix != version.bugfix) return false; - if (major != version.major) return false; - return minor == version.minor; + if(o instanceof Version) { + return internalVersion.equals(((Version)o).internalVersion); + } else { + return false; + } } /** @@ -83,12 +66,7 @@ public class Version implements Comparable { * @return A hash code for this object. */ public int hashCode() { - int result; - result = major; - result = 29 * result + minor; - result = 29 * result + beta; - result = 29 * result + bugfix; - return result; + return internalVersion.hashCode(); } /** @@ -96,15 +74,7 @@ public class Version implements Comparable { * @return A string representation of the form "1.27", "1.27.2" or "1.27.beta3". */ public String toString() { - StringBuffer buf = new StringBuffer(); - buf.append(major).append('.').append(minor); - if (beta != 0) { - buf.append(".beta").append(beta); - } else if (bugfix != 0) { - buf.append('.').append(bugfix); - } - - return buf.toString(); + return internalVersion.toString(); } /** @@ -114,33 +84,11 @@ public class Version implements Comparable { * greater than the specified object. */ public int compareTo(Version version) { - if (major < version.major) { - return -1; - } else if (major > version.major) { - return 1; - } - - if (minor < version.minor) { - return -1; - } else if (minor > version.minor) { - return 1; - } - - if (bugfix < version.bugfix) { - return -1; - } else if (bugfix > version.bugfix) { - return 1; - } - - int thisBeta = beta == 0 ? Integer.MAX_VALUE : beta; - int otherBeta = version.beta == 0 ? Integer.MAX_VALUE : version.beta; - - if (thisBeta < otherBeta) { - return -1; - } else if (thisBeta > otherBeta) { - return 1; - } + return internalVersion.compareTo(version.internalVersion); + } - return 0; + public boolean isPreview() { + return StringUtils.isNotBlank(internalVersion.getQualifier()) && + !StringUtils.equalsIgnoreCase(internalVersion.getQualifier(), Artifact.RELEASE_VERSION); } } diff --git a/libresonic-main/src/test/java/org/libresonic/player/domain/VersionTestCase.java b/libresonic-main/src/test/java/org/libresonic/player/domain/VersionTestCase.java index 15db0783..7dc3edca 100644 --- a/libresonic-main/src/test/java/org/libresonic/player/domain/VersionTestCase.java +++ b/libresonic-main/src/test/java/org/libresonic/player/domain/VersionTestCase.java @@ -47,6 +47,22 @@ public class VersionTestCase extends TestCase { doTestVersion("1.5.beta1", "1.6"); doTestVersion("1.5.beta1", "1.5.beta2"); doTestVersion("1.5.beta2", "1.5.beta11"); + + doTestVersion("6.2-SNAPSHOT", "6.11-SNAPSHOT"); + } + + public void testIsPreview() { + Version version = new Version("1.6.0-SNAPSHOT"); + assertTrue("Version should be snapshot", version.isPreview()); + + version = new Version("1.6.0-beta2"); + assertTrue("Version should be snapshot", version.isPreview()); + + version = new Version("1.6.0"); + assertFalse("Version should not be snapshot", version.isPreview()); + + version = new Version("1.6.0-RELEASE"); + assertFalse("Version should not be snapshot", version.isPreview()); } /**