Skip to content

Commit

Permalink
Add a "shouldUpdate" method which can be easily edited.
Browse files Browse the repository at this point in the history
Because of all the confusion regarding different versioning schemes and trying to use them to determine the "validity" of a file present on BukkitDev as a "new" version, Updater only does a string comparison to see if the newest file's version is different than the current version. If so, it will consider it a "valid" update.

I've added a new method that will allow anyone who has a specific, constant versioning scheme that they use in their plugins to more easily implement a mathematical comparison.
  • Loading branch information
gravitylow committed Jan 9, 2014
1 parent 54b4810 commit 69ef5ca
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/main/java/net/gravitydevelopment/updater/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ private boolean pluginFile(String name) {
*/
private boolean versionCheck(String title) {
if (this.type != UpdateType.NO_VERSION_CHECK) {
final String version = this.plugin.getDescription().getVersion();
final String localVersion = this.plugin.getDescription().getVersion();
if (title.split(delimiter).length == 2) {
final String remoteVersion = title.split(delimiter)[1].split(" ")[0]; // Get the newest file's version number

if (this.hasTag(version) || version.equalsIgnoreCase(remoteVersion)) {
if (this.hasTag(localVersion) || !this.shouldUpdate(localVersion, remoteVersion)) {
// We already have the latest version, or this build is tagged for no-update
this.result = Updater.UpdateResult.NO_UPDATE;
return false;
Expand All @@ -481,6 +481,37 @@ private boolean versionCheck(String title) {
return true;
}

/**
* <b>If you wish to run mathematical versioning checks, edit this method.</b>
* <p>
* With default behavior, Updater will NOT verify that a remote version available on BukkitDev
* which is not this version is indeed an "update".
* If a version is present on BukkitDev that is not the version that is currently running,
* Updater will assume that it is a newer version.
* This is because there is no standard versioning scheme, and creating a calculation that can
* determine whether a new update is actually an update is sometimes extremely complicated.
* </p>
* <p>
* Updater will call this method from {@link #versionCheck(String)} before deciding whether
* the remote version is actually an update.
* If you have a specific versioning scheme with which a mathematical determination can
* be reliably made to decide whether one version is higher than another, you may
* revise this method, using the local and remote version parameters, to execute the
* appropriate check.
* </p>
* <p>
* Returning a value of <b>false</b> will tell the update process that this is NOT a new version.
* Without revision, this method will always consider a remote version at all different from
* that of the local version a new update.
* </p>
* @param localVersion the current version
* @param remoteVersion the remote version
* @return true if Updater should consider the remote version an update, false if not.
*/
public boolean shouldUpdate(String localVersion, String remoteVersion) {
return !localVersion.equalsIgnoreCase(remoteVersion);
}

/**
* Evaluate whether the version number is marked showing that it should not be updated by this program.
*
Expand Down

0 comments on commit 69ef5ca

Please sign in to comment.