Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used better version comparison lib #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ public SpigetUpdate setUserAgent(String userAgent) {
return this;
}

/**
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*/
@Deprecated
@Override
public SpigetUpdate setVersionComparator(VersionComparator comparator) {
super.setVersionComparator(comparator);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ public SpigetUpdate setUserAgent(String userAgent) {
return this;
}

/**
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*/
@Deprecated
@Override
public SpigetUpdate setVersionComparator(VersionComparator comparator) {
super.setVersionComparator(comparator);
return this;
}

Expand Down
26 changes: 26 additions & 0 deletions Core/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>parent</artifactId>
<groupId>org.inventivetalent.spiget-update</groupId>
<version>parent</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>core</artifactId>
<version>${s-update.version}</version>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

6 changes: 6 additions & 0 deletions Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

<dependency>
<groupId>dev.aura.lib.version</groupId>
<artifactId>VersionLib</artifactId>
<version>1.1.0.79</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import com.google.gson.JsonParser;
import org.inventivetalent.update.spiget.comparator.VersionComparator;

import dev.aura.lib.version.Version;

import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
Expand All @@ -48,7 +50,6 @@ public abstract class SpigetUpdateAbstract {
protected final String currentVersion;
protected final Logger log;
protected String userAgent = "SpigetResourceUpdater";
protected VersionComparator versionComparator = VersionComparator.EQUAL;

protected ResourceInfo latestResourceInfo;

Expand All @@ -67,8 +68,11 @@ public String getUserAgent() {
return userAgent;
}

/**
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*/
@Deprecated
public SpigetUpdateAbstract setVersionComparator(VersionComparator comparator) {
this.versionComparator = comparator;
return this;
}

Expand All @@ -79,7 +83,7 @@ public ResourceInfo getLatestResourceInfo() {
protected abstract void dispatch(Runnable runnable);

public boolean isVersionNewer(String oldVersion, String newVersion) {
return versionComparator.isNewer(oldVersion, newVersion);
return (new Version(oldVersion)).compareTo(new Version(newVersion)) < 0;
}

public void checkForUpdate(final UpdateCallback callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,48 @@

package org.inventivetalent.update.spiget.comparator;

public abstract class VersionComparator {
/**
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*/
@Deprecated
public class VersionComparator {

/**
* Compares versions by checking if the version strings are equal
*
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*/
public static final VersionComparator EQUAL = new VersionComparator() {
@Override
public boolean isNewer(String currentVersion, String checkVersion) {
return !currentVersion.equals(checkVersion);
}
};
@Deprecated
public static final VersionComparator EQUAL = new VersionComparator();

/**
* Compares versions by their Sematic Version (<code>Major.Minor.Patch</code>, <a href="http://semver.org/">semver.org</a>). Removes dots and compares the resulting Integer values
*
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*/
public static final VersionComparator SEM_VER = new VersionComparator() {
@Override
public boolean isNewer(String currentVersion, String checkVersion) {
currentVersion = currentVersion.replace(".", "");
checkVersion = checkVersion.replace(".", "");

try {
int current = Integer.parseInt(currentVersion);
int check = Integer.parseInt(checkVersion);

return check > current;
} catch (NumberFormatException e) {
System.err.println("[SpigetUpdate] Invalid SemVer versions specified [" + currentVersion + "] [" + checkVersion + "]");
}
return false;
}
};
@Deprecated
public static final VersionComparator SEM_VER = new VersionComparator();

/**
* Same as {@link VersionComparator#SEM_VER}, but supports version names with '-SNAPSHOT' suffixes
*
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*/
public static final VersionComparator SEM_VER_SNAPSHOT = new VersionComparator() {
@Override
public boolean isNewer(String currentVersion, String checkVersion) {
currentVersion = currentVersion.replace("-SNAPSHOT", "");
checkVersion = checkVersion.replace("-SNAPSHOT", "");

return SEM_VER.isNewer(currentVersion, checkVersion);
}
};
@Deprecated
public static final VersionComparator SEM_VER_SNAPSHOT = new VersionComparator();

/**
* Called to check if a version is newer
*
* @deprecated in favor of VersionLib, which doesn't require a comparision mode.
*
* @param currentVersion Current version of the plugin
* @param checkVersion Version to check
* @return <code>true</code> if the checked version is newer
*/
public abstract boolean isNewer(String currentVersion, String checkVersion);
@Deprecated
public boolean isNewer(String currentVersion, String checkVersion) {
return false;
}

}
7 changes: 0 additions & 7 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ Spigot & Bungeecord updater API which uses [spiget.org](https://spiget.org) to c
```Java
SpigetUpdate updater = new SpigetUpdate(this, 12345);

// This compares versions just by checking if they are equal
// This means that older versions will also be treated as updates
updater.setVersionComparator(VersionComparator.EQUAL);

// This converts a semantic version to an integer and checks if the updated version is greater
updater.setVersionComparator(VersionComparator.SEM_VER);

updater.checkForUpdate(new UpdateCallback() {
@Override
public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@
<artifactSet>
<includes>
<include>org.inventivetalent.spiget-update:**</include>
<include>dev.aura.lib.version:VersionLib</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>dev.aura.lib.version</pattern>
<shadedPattern>org.inventivetalent.update.spiget.shade.dev.aura.lib.version</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
Expand All @@ -95,6 +102,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>AuraDevelopmentTeam</id>
<url>https://maven.project-creative.de/repository/auradev-releases/</url>
</repository>
</repositories>

<distributionManagement>
Expand Down