├── .gitignore
├── .script
└── upload-javadoc.sh
├── .travis.yml
├── Bukkit
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── inventivetalent
│ └── update
│ └── spiget
│ └── SpigetUpdate.java
├── Bungee
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── inventivetalent
│ └── update
│ └── spiget
│ └── SpigetUpdate.java
├── Core
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── inventivetalent
│ │ └── update
│ │ └── spiget
│ │ ├── ResourceFile.java
│ │ ├── ResourceInfo.java
│ │ ├── ResourceVersion.java
│ │ ├── SpigetUpdateAbstract.java
│ │ ├── UpdateCallback.java
│ │ ├── comparator
│ │ └── VersionComparator.java
│ │ └── download
│ │ ├── DownloadCallback.java
│ │ └── UpdateDownloader.java
│ └── test
│ └── java
│ └── org
│ └── inventivetalent
│ └── update
│ └── spiget
│ └── test
│ ├── ComparatorTest.java
│ └── UpdateTest.java
├── LICENSE
├── README.MD
├── pom.xml
├── renovate.json
└── settings.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Maven template
2 | target/
3 | pom.xml.tag
4 | pom.xml.releaseBackup
5 | pom.xml.versionsBackup
6 | pom.xml.next
7 | release.properties
8 | dependency-reduced-pom.xml
9 | buildNumber.properties
10 | .mvn/timing.properties
11 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar
12 | .mvn/wrapper/maven-wrapper.jar
13 |
14 | ### JetBrains template
15 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
16 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
17 |
18 | .idea/
19 | *.iml
20 | *.ipr
21 |
22 | # CMake
23 | cmake-build-*/
24 |
25 | # File-based project format
26 | *.iws
27 |
28 | # IntelliJ
29 | out/
30 |
31 | # mpeltonen/sbt-idea plugin
32 | .idea_modules/
33 |
34 | # JIRA plugin
35 | atlassian-ide-plugin.xml
36 |
37 | # Crashlytics plugin (for Android Studio and IntelliJ)
38 | com_crashlytics_export_strings.xml
39 | crashlytics.properties
40 | crashlytics-build.properties
41 | fabric.properties
42 |
--------------------------------------------------------------------------------
/.script/upload-javadoc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo -e "Uploading Javadoc...\n"
3 |
4 | cd $HOME
5 | git config --global user.email "git-bot@inventivetalent.org"
6 | git config --global user.name "InventiveBot"
7 | git clone --quiet --branch=gh-pages https://${GITHUB_TOKEN}@github.com/InventivetalentDev/SpigetUpdater gh-pages > /dev/null
8 |
9 | cd gh-pages
10 | git rm -rf .
11 | cp -Rf $TRAVIS_BUILD_DIR/target/site/apidocs .
12 | git add -f .
13 | git commit -m "Javadoc for #$TRAVIS_BUILD_NUMBER"
14 | git push -fq origin gh-pages > /dev/null
15 |
16 | echo -e "Uploaded Javadoc\n"
17 |
18 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 |
5 | script: "mvn javadoc:aggregate deploy --settings settings.xml"
6 | before_script:
7 | - "chmod +x .script/upload-javadoc.sh"
8 | after_success: ".script/upload-javadoc.sh"
9 | env:
10 | global:
11 | - secure: "KZmkrF5X0P+rVc25Y2P7RUXgTfwHqjPbw8Zfcod/4KQDMzWtAPpsGlE8kulr1ry0ozRgqyAqTrzf1yRR5YxWgJQOy1rEpWsJ0Jfy1zv7nejsAZX4pT1YsiNrZBJNT9fDdOPOYQm9Fm4C2s0tJPamOgCHbbWJs9EscdcKlnHKyU0bKRT7NIlDraCOBMDiw7S1BG8YCZQJ4Au6jhXyJuGYF8+HNg07cPspI9g/VUEFSmBMisDnB/4zLXy55VMMbH7OcMU4c362JGtwYPQjX5HnbR4JsxtxxI0lOBoUDkY77MwsWlQmruwsPn8e00jO1xNkcuFYohzZklUTRZZDENVFtOeA++DXiaeJzRhZBX56eAZopFe0dPWGfYNRkC+dN4g4GY96aInK/Jxpkg9R/DRwBlhTNoJXFoMVkbIPTn/sEXaa7Ea5S475iQpzhuPFR06Tr26JT39e0ycVB37QIprRsL2mQIJ3pMlK8HcZNnDmg6usESLCHPmgSpfkH9KDGrM14fJ6u0Hl6jmAmvV/iqQWynIA0Be3fIjGQ1fyRhBghj+5SUO1Ux28z5TP+B5yXTssf3zK2dCIac6IRHW43math9hY+lS+6bpcsfhyOF7olbKZB1C5PJT7cRByK6PmPC2hQzn9pyYSQbgvHeZaL5KrxCSpNqNPfbYOprake2nobH4="
12 | - secure: "mnEM2tBdQjDwEBud/3UGpuD6uuma9ytXaL3YWc44ThwjCa5fgs16gh6TXriJ7ZuPJHtwUaTwB93nFJcwPon9/iofGuY5P5aYAbPvSxPvA8qFSwL3hOziQaf7SxePjRPHctlPrBEGYDVEN9NXkdK/nSqRL7ZljYCp6FtiIzEu8QxDSZm0Us6m7QHzGHpAvCaeDpYAoq/6oKtr3Rgf8sQzCDSdvMvFnDGxVc1sM9kULhzSqBubUZkHYg1VrtJ/KjuwQsDFh8iXuXvPqki3hWBtjaXie2vXBlAH1xiKlX1YgycoBeoQMknGrm6WaB3v0IDEGCAzPAlRdgshuWIhXhaNhSVt1YV2LsXCTWSq3MFI0DWrGj134Kw1LVvbTmN8+JRFrzY9a0+zP91Vpi12hKprmf+qWV6zmfTZe47+L8E7zQFI2zCM/VEWKb9HLJZMrZBJqjR13I3rbwA6nrtuv5ZNcrQ3re5xy807U8LkM+2LQzgqNsb6ihkZhPycNqWKEWtjk/TCzsTBPghk6/Krap8XvVOU/MHOpLDIGe3GCfGfG7GFfu3V/iE74TpcO0nbwp3wIfh1qk/JNENpv1/Pc5qx0CZ84ly7gRmmYVtP9ff+9dRk1FzZtQhR/oiMPrqbJxwnP140vrarXQJZIOCJtILjEosi9xSddibTkKRgTu6XGd4="
13 | - secure: "AhSYOwdwz4hhsopVCYyTyfwni4Hnu4CbLY2BVN6mYnKj/gGLPh+215cv4CQUSGhu8VEBz5AXs7zw/NrbXY0M7D7zCngiqAUSWAG2cvspKIMgwwiKMAn8hheNmwlmdFuiR4kRujoRByoaCp+yvHbYviggTKm6RZXN3jdqbp5kO4dgZD8qZM8JGKk0CA6bein0FrFWVeRNygAISFBn54vEFxeOWZTI3c0XzouaHsYJYfVt0fwOlIaexP0rZXOckXoCku9KzCcmEdeWMov2D5Cm9tJxp02FyK63HD2AuB+fKs62mrRwvmBgQoQx/LLsuKegPbCkj1ym9/y5hS6gLBA8C6q/ZadiRO6mmS7u8QNvM+bZCDeN8p3H81+P5dhUL8LJu91tDMlZo8e+AQyTbOvfQUIqDXCZQMAd20qjuNaucH6P4zXHCaYSTC4E4uPhAvGsZ6op0/Zg0vS6Yg4F+GnGEUMA/JKGLwXU3w7ZE3NXIf2MoM6urXgwU9x5Pt4Twjsc4Q33bs9VAlSvoUSzH0aStBmZ+G0E9NyxNg4LyEDtJtpZ/6te683c3sNCOFft/PfrFh0na0njPpEnSanrHXCrr0IlLfyXimXFkODUtD4BYpH+arlWWCaZgaNGmTsTq8/LQhlo40SRVA+z5dXJ6ckcDfBm7ROwc4NcFndGz0bhcPs="
14 | before_deploy:
15 | - export BUKKIT_RELASE_FILE=$(find . -name bukkit-*.jar)
16 | - export BUNGEE_RELASE_FILE=$(find . -name bungee-*.jar)
17 | deploy:
18 | provider: releases
19 | api_key:
20 | secure: "eic3KobDkmWVoKQI9KjWgjrhw2aK6xJOnpUP7eKY2C7x5ZGvwZmZZ8PmgT2M07WFuklq/rn87fOJs7FvkpG1jkpF4aGO90wi1zy4LxVKLd4sHSwp1mHBbNAejL3ph+ff7tIKkyTENFKOX5YusXOM7ZRc162ySH4+UpkKLQwtItQ8qKkwcOzI4B9tiiLrq6vAO163/AiIo3lZCFNoeOc5kHnHVoDFRthhcSuFgi+gDk7au4ndA64/mrABuhtfQKJz32/GjybV+8Ah+ZYcGcGm9TuVi2itJ2UiTgnrVkJKWlJNgkuvtgZx6J5lZvHk1gjoiXJl3kojbHgV9rXqrTsKxN+NQPFwaak/S0c6iqRCqu3AzlKL0Xmh3aqA403cxpKI20PiXi5bXUOTBmIwANU/jHyIP9VRZJRpi2/dGLM5p2wPGO9CmsdOlthcreIYvnHXqlL3I/vnyjfxv0eJuRsfJ/hrC2NdI95UjF+AxaCtPsOWbKtdS9STtA0HpQzyCOCNT8Nu2dg/u1Wss6qe0XfzaShG54vBwM9b/bcSi9wh+8ivpEOKEF3RWfZ1dYaiEbeJ/Eu9UYWeVIeFvboUkETz4ZCyB8hoxdJwZ3VJbD5nQbZFqbOlfCa4jmBwGKkOYe/+FBr/iMDhlRwjjmqDC8OCC6k4jT4VDAIeE6ey5YsbLk8="
21 | file_glob: true
22 | file:
23 | - "Bukkit/target/bukkit-*.jar"
24 | - "Bungee/target/bungee-*.jar"
25 | skip_cleanup: true
26 | on:
27 | tags: true
28 |
--------------------------------------------------------------------------------
/Bukkit/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
36 | * Use {@link SpigetUpdateAbstract#getLatestResourceInfo()} to get all resource details
37 | *
38 | * @param newVersion the new version's name
39 | * @param downloadUrl URL to download the update
40 | * @param canAutoDownload whether this update can be downloaded automatically
41 | */
42 | void updateAvailable(String newVersion, String downloadUrl, boolean canAutoDownload);
43 |
44 | /**
45 | * Called when no update was found
46 | */
47 | void upToDate();
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/Core/src/main/java/org/inventivetalent/update/spiget/comparator/VersionComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.update.spiget.comparator;
30 |
31 | import java.util.Arrays;
32 |
33 | public abstract class VersionComparator {
34 |
35 | /**
36 | * Compares versions by checking if the version strings are equal
37 | */
38 | public static final VersionComparator EQUAL = new VersionComparator() {
39 | @Override
40 | public boolean isNewer(String currentVersion, String checkVersion) {
41 | return !currentVersion.equals(checkVersion);
42 | }
43 | };
44 |
45 | /**
46 | * Compares versions by their Semantic Version (Major.Minor.Patch
, semver.org).
47 | * Parses major, minor and patch and goes down from major till patch to decide whether a version is newer.
48 | * Also supports longer variations like x.x.x.x or x.x. These cases will be handled properly.
49 | */
50 | public static final VersionComparator SEM_VER = new VersionComparator() {
51 | @Override
52 | public boolean isNewer(String currentVersion, String checkVersion) {
53 | try {
54 | int[] currentVersionData = Arrays.stream(currentVersion.split("\\."))
55 | .mapToInt(Integer::parseInt).toArray();
56 | int[] checkVersionData = Arrays.stream(checkVersion.split("\\."))
57 | .mapToInt(Integer::parseInt).toArray();
58 |
59 | int i = 0;
60 | for (int version : checkVersionData) {
61 | if (i == currentVersionData.length) {
62 | return true;
63 | }
64 |
65 | if (version > currentVersionData[i]) {
66 | return true;
67 | } else if (version < currentVersionData[i]) {
68 | return false;
69 | }
70 |
71 | i++;
72 | }
73 | } catch (NumberFormatException e) {
74 | System.err.println("[SpigetUpdate] Invalid SemVer versions specified [" + currentVersion + "] [" + checkVersion + "]");
75 | }
76 | return false;
77 | }
78 | };
79 |
80 | /**
81 | * Same as {@link VersionComparator#SEM_VER}, but supports version names with '-SNAPSHOT' suffixes
82 | */
83 | public static final VersionComparator SEM_VER_SNAPSHOT = new VersionComparator() {
84 | @Override
85 | public boolean isNewer(String currentVersion, String checkVersion) {
86 | currentVersion = currentVersion.replace("-SNAPSHOT", "");
87 | checkVersion = checkVersion.replace("-SNAPSHOT", "");
88 |
89 | return SEM_VER.isNewer(currentVersion, checkVersion);
90 | }
91 | };
92 |
93 | /**
94 | * Called to check if a version is newer
95 | *
96 | * @param currentVersion Current version of the plugin
97 | * @param checkVersion Version to check
98 | * @return true
if the checked version is newer
99 | */
100 | public abstract boolean isNewer(String currentVersion, String checkVersion);
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/Core/src/main/java/org/inventivetalent/update/spiget/download/DownloadCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.update.spiget.download;
30 |
31 | public interface DownloadCallback {
32 |
33 | void finished();
34 |
35 | void error(Exception exception);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/Core/src/main/java/org/inventivetalent/update/spiget/download/UpdateDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 inventivetalent. All rights reserved.
3 | *
4 | * Redistribution and use in source and binary forms, with or without modification, are
5 | * permitted provided that the following conditions are met:
6 | *
7 | * 1. Redistributions of source code must retain the above copyright notice, this list of
8 | * conditions and the following disclaimer.
9 | *
10 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 | * of conditions and the following disclaimer in the documentation and/or other materials
12 | * provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 | *
24 | * The views and conclusions contained in the software and documentation are those of the
25 | * authors and contributors and should not be interpreted as representing official policies,
26 | * either expressed or implied, of anybody else.
27 | */
28 |
29 | package org.inventivetalent.update.spiget.download;
30 |
31 | import org.inventivetalent.update.spiget.ResourceInfo;
32 |
33 | import java.io.File;
34 | import java.io.FileOutputStream;
35 | import java.io.IOException;
36 | import java.net.HttpURLConnection;
37 | import java.net.URL;
38 | import java.nio.channels.Channels;
39 | import java.nio.channels.ReadableByteChannel;
40 |
41 | public class UpdateDownloader {
42 |
43 | public static final String RESOURCE_DOWNLOAD = "https://api.spiget.org/v2/resources/%s/download";
44 |
45 | public static Runnable downloadAsync(final ResourceInfo info, final File file, final String userAgent, final DownloadCallback callback) {
46 | return () -> {
47 | try {
48 | download(info, file, userAgent);
49 | callback.finished();
50 | } catch (Exception e) {
51 | callback.error(e);
52 | }
53 | };
54 | }
55 |
56 | public static void download(ResourceInfo info, File file, String userAgent) {
57 | if (info.external) { throw new IllegalArgumentException("Cannot download external resource #" + info.id); }
58 | ReadableByteChannel channel;
59 | try {
60 | //https://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java
61 | HttpURLConnection connection = (HttpURLConnection) new URL(String.format(RESOURCE_DOWNLOAD, info.id)).openConnection();
62 | connection.setRequestProperty("User-Agent", userAgent);
63 | connection.setInstanceFollowRedirects(true);
64 | if (connection.getResponseCode() != 200) {
65 | throw new RuntimeException("Download returned status #" + connection.getResponseCode());
66 | }
67 | channel = Channels.newChannel(connection.getInputStream());
68 | } catch (IOException e) {
69 | throw new RuntimeException("Download failed", e);
70 | }
71 | try {
72 | FileOutputStream output = new FileOutputStream(file);
73 | output.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
74 | output.flush();
75 | output.close();
76 | } catch (IOException e) {
77 | throw new RuntimeException("Could not save file", e);
78 | }
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/Core/src/test/java/org/inventivetalent/update/spiget/test/ComparatorTest.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.update.spiget.test;
2 |
3 | import org.inventivetalent.update.spiget.comparator.VersionComparator;
4 | import org.junit.Test;
5 | import static org.junit.Assert.*;
6 |
7 | public class ComparatorTest {
8 | @Test
9 | public void equalsTest() {
10 | String oldVersion = "1.0.0";
11 | String newVersion = "2.0.0";
12 |
13 | assertTrue(VersionComparator.EQUAL.isNewer(oldVersion, newVersion));
14 |
15 | // This is a case where the simple equals check doesn't shine.
16 | assertTrue(VersionComparator.EQUAL.isNewer(newVersion, oldVersion));
17 |
18 | assertFalse(VersionComparator.EQUAL.isNewer(oldVersion, oldVersion));
19 | }
20 |
21 | @Test
22 | public void semverTest() {
23 | String oldVersion = "1.0.0";
24 | String newVersion = "2.0.0";
25 |
26 | assertTrue(VersionComparator.SEM_VER.isNewer(oldVersion, newVersion));
27 | assertFalse(VersionComparator.SEM_VER.isNewer(newVersion, oldVersion));
28 | assertFalse(VersionComparator.SEM_VER.isNewer(oldVersion, oldVersion));
29 | }
30 |
31 | @Test
32 | public void longSemverTest() {
33 | String oldVersion = "1.0";
34 | String newVersion = "2.0.0.0.0.0";
35 |
36 | assertTrue(VersionComparator.SEM_VER.isNewer(oldVersion, newVersion));
37 | assertFalse(VersionComparator.SEM_VER.isNewer(newVersion, oldVersion));
38 | assertFalse(VersionComparator.SEM_VER.isNewer(oldVersion, oldVersion));
39 | }
40 |
41 | @Test
42 | public void longSemverTest2() {
43 | String oldVersion = "5.0.6.2.7";
44 | String newVersion = "6.0.7.3";
45 |
46 | assertTrue(VersionComparator.SEM_VER.isNewer(oldVersion, newVersion));
47 | assertFalse(VersionComparator.SEM_VER.isNewer(newVersion, oldVersion));
48 | assertFalse(VersionComparator.SEM_VER.isNewer(oldVersion, oldVersion));
49 | }
50 |
51 | @Test
52 | public void edgeSemverTest() {
53 | String oldVersion = "1.1.10";
54 | String newVersion = "1.2.0";
55 |
56 | assertTrue(VersionComparator.SEM_VER.isNewer(oldVersion, newVersion));
57 | assertFalse(VersionComparator.SEM_VER.isNewer(newVersion, oldVersion));
58 | assertFalse(VersionComparator.SEM_VER.isNewer(oldVersion, oldVersion));
59 | }
60 |
61 | @Test
62 | public void semverSnapshotTest() {
63 | String oldVersion = "1.0.0-SNAPSHOT";
64 | String newVersion = "2.0.0-SNAPSHOT";
65 |
66 | assertTrue(VersionComparator.SEM_VER_SNAPSHOT.isNewer(oldVersion, newVersion));
67 | assertFalse(VersionComparator.SEM_VER_SNAPSHOT.isNewer(newVersion, oldVersion));
68 | assertFalse(VersionComparator.SEM_VER_SNAPSHOT.isNewer(oldVersion, oldVersion));
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Core/src/test/java/org/inventivetalent/update/spiget/test/UpdateTest.java:
--------------------------------------------------------------------------------
1 | package org.inventivetalent.update.spiget.test;
2 |
3 | import org.inventivetalent.update.spiget.SpigetUpdateAbstract;
4 | import org.inventivetalent.update.spiget.UpdateCallback;
5 | import org.junit.Test;
6 |
7 | import java.util.logging.Logger;
8 |
9 | import static org.junit.Assert.*;
10 |
11 | public class UpdateTest {
12 |
13 | @Test
14 | public void updateTest() {
15 | SpigetUpdateAbstract updateCheck = new SpigetUpdateAbstract(5341/* NickNamer */, "1.0.0", Logger.getLogger("UpdateTest")) {
16 | @Override
17 | protected void dispatch(Runnable runnable) {
18 | runnable.run();
19 | }
20 | };
21 | updateCheck.checkForUpdate(new UpdateCallback() {
22 | @Override
23 | public void updateAvailable(String newVersion, String downloadUrl, boolean canAutoDownload) {
24 | System.out.println("newVersion = [" + newVersion + "], downloadUrl = [" + downloadUrl + "], canAutoDownload = [" + canAutoDownload + "]");
25 |
26 | assertTrue(downloadUrl.startsWith("https://spigotmc.org/resources/nicknamer-integrated-api.5341/download"));
27 | assertFalse(canAutoDownload);
28 | }
29 |
30 | @Override
31 | public void upToDate() {
32 | System.out.println("up-to-date");
33 |
34 | fail("Resource is up-to-date, but should have an update");
35 | }
36 | });
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Haylee Schäfer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/InventivetalentDev/SpigetUpdater)
2 | [](https://github.com/InventivetalentDev/SpigetUpdater)
3 |
4 |
5 | Spigot & Bungeecord updater API which uses [spiget.org](https://spiget.org) to check for new versions
6 |
7 | ## Usage
8 |
9 | ### Check for new versions
10 |
11 | ```Java
12 | SpigetUpdate updater = new SpigetUpdate(this, 12345);
13 |
14 | // This compares versions just by checking if they are equal
15 | // This means that older versions will also be treated as updates
16 | updater.setVersionComparator(VersionComparator.EQUAL);
17 |
18 | // This converts a semantic version to an integer and checks if the updated version is greater
19 | updater.setVersionComparator(VersionComparator.SEM_VER);
20 |
21 | updater.checkForUpdate(new UpdateCallback() {
22 | @Override
23 | public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
24 | //// A new version is available
25 | // newVersion - the latest version
26 | // downloadUrl - URL to the download
27 | // hasDirectDownload - whether the update is available for a direct download on spiget.org
28 | }
29 |
30 | @Override
31 | public void upToDate() {
32 | //// Plugin is up-to-date
33 | }
34 | });
35 | ```
36 |
37 |
38 | ### Download updates (Bukkit/Spigot)
39 | ```Java
40 | final SpigetUpdate updater = new SpigetUpdate(this, 12345);
41 | updater.checkForUpdate(new UpdateCallback() {
42 | @Override
43 | public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
44 | // First check if there is a direct download available
45 | // (Either the resources is hosted on spigotmc.org, or Spiget has a cached version to download)
46 | // external downloads won't work if they are disabled (by default) in spiget.properties
47 | if (hasDirectDownload) {
48 | if (updater.downloadUpdate()) {
49 | // Update downloaded, will be loaded when the server restarts
50 | } else {
51 | // Update failed
52 | getLogger().warning("Update download failed, reason is " + updater.getFailReason());
53 | }
54 | }
55 | }
56 |
57 | @Override
58 | public void upToDate() {
59 | }
60 | });
61 | ```
62 |
63 | ## Maven
64 | ```xml
65 |