Util Updater by ArsenArsen

Discussion in 'Resources' started by ArsenArsen, Aug 4, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    ArsenArsen

    Hello Bukkit community!

    I was working on this library, and I decided to make a updater for it, so I did, and I decided to share it with you guys

    I am so stubborn, should've just used gravit'ys updater

    Updater
    by ArsenArsen

    Sorry for the dramatic title
    This updater is nothing special, but here is a brief summary of it's features:
    • Can be used in a simple manner, or complex manner
    • Has callbacks
    • Can handle ZIP updates (needs testing)
    • Channel1 support
    • Tags support, example, if updates name ends with -DEV don't download it
    • Stores backups
    • Has javadocs
    • Handles moved resources
    • Open for suggestions
    About the last one, suggest here, just make sure to add the enhancement tag
    1 - Channels are release types

    Obtaining

    To get yourself updater you can add this repository and dependency
    Code:
    ...
    <repository>
        <id>arsens-repo</id>
        <url>https://repo.arsenarsen.com/content/repositories/snapshots/</url>
    </repository>
    ...
    <dependency>
       <groupId>com.arsenarsen</groupId>
       <artifactId>updater</artifactId>
       <version>1.1.8-R0.1-SNAPSHOT</version>
    </dependency>
    ...
    Orr, if you, like most people, don't use Maven you can go to my GitHub and get it there. Here is the link: link
    No offense for anyone using it, I use it too.
    Usage
    There is one pre-request: Your names must be in format: NAME vVERSION or NAME VERSION

    You can update your plugins with a simple line of code in your onEnable method, as shown in this snippet below:
    Code:
    Updater updater = new Updater(this, id, getConfig().getBoolean("update", true)[, callbacks]);
    Here is an explanation of what is going on:
    • this - Reference to your plugins main class
    • id - your plugins ID on BukkitDev and Curse
    • getConfig(... - Checks the update boolean in your config, to make your plugin policy compliant
    • [, callbacks] - Optional list of callbacks you want to be called after the update. Callbacks will hold a reference to the updater aswel as the update result.
    How does it work?
    who cares
    Inner workings of Updater look complex, but are veeeerrrry simple. Basically what happens is
    • Get a response from servermods
    • Get the last file in the response
    • Store files MD5, name and release type, as known as channel
    • If channels and tags are OK
    • We check if the name, without tags, matches .*\sv?[0-9.]*
    • If not, we say Cannot parse name and return
    • Get old and new version to the same length
    • Otherwise split it into version number and name using \sv? as the delimeter
    • Split that using \., which means just dot, as a delimeter
    • Go through gained strings and parse them to integers and save
    • Go through integers and compare them
    • If we encounter that new versions integer is bigger than the old ones, say that the update is needed and break
    • If update is needed
    • If tags arent ok, get the next file, and so on, and if we hit the end, there is no update.
    That was the update checking procedure, and here is the download one
    • Download it
    • If its MD5 is incorrect, check if line one says that it was moved
    • If it does repeat download for moved files URL
    • Otherwise download failed
    • If its not on the allowed channels list or has a skip tag, repeat the whole process for the next one

    Quick method summary
    Here is a list of methods, with explanations:
    • setID(int) - Sets the plugin ID
    • getID() - Gets the ID
    • registerCallback(UpdaterCallback) - Adds a new callback to be ran
    • update() - Attempts to update, failing silently if there is no updates
    • checkForUpdates([force]) - Checks for updates, overwriting cache if needed
    • isUpdated() - Checks if the last update ran successfully
    Well, thats about it, have a good day folks!

    P.S. Bug reports and suggestions are highly encouraged, at this link: link
    Changelog:
    • 1.0.0-SNAPSHOT - Initial
    • 1.0.0-R0.2-SNAPSHOT - Fix channel support
    • 1.1.0-R0.1-SNAPSHOT - Add callbacks
    • 1.1.1-R0.1-SNAPSHOT - Add tags support
    • 1.1.2-R0.1-SNAPSHOT - Add log, move all work to plugins/AUpdater
    • 1.1.3-R0.1-SNAPSHOT - Fix way updates are detected
    • 1.1.4-R0.1-SNAPSHOT - Add some more endpoints, unit testing, global config, and a DISABLED enum constant
    • 1.1.5-R0.1-SNAPSHOT - Try fixing #2
    • 1.1.6-R0.1-SNAPSHOT - BukkitDev update
    • 1.1.8-R0.1-SNAPSHOT - Code cleanup
    Somehow I skipped 1.1.7?????
    TODO:
    • Add global configuration
    • Add ability to filter updates, to check is it compatible with the Minecraft version used
     
    Last edited: Jul 2, 2017
    Zombie_Striker likes this.
  2. Offline

    ArsenArsen

    @bwfcwalshy sure, there are some in my git, let me get it.
    spoonefeeding
     
  3. Offline

    Zombie_Striker

    @ArsenArsen
    Will definitely use it. Just one question; How does it know when an updated version of a plugin has come out?
     
  4. Offline

    ArsenArsen

    Needs improvement, but if the last MD5 in the JSON array that is the servermods response is different than the file one, update. I think I should make it somehow get version numbers and compare them. Probably regexes.

    Also thanks for using it!

    EDIT: Also checks release types and tags
     
  5. You could parse:
    Code:
    "fileUrl":"http://www.curseforge.com/files/922048"
    When you upload a new file to your project the fileUrl number get's higher. The most recent is mostly at the end of the curseforge api servermods page
     
  6. Offline

    ArsenArsen

    @FisheyLP Interesting idea, but it is still sorted in the manner that the last is latest. So it does not matter :)

    But thanks for leaving feedback regardless, and if I miss understood you, correct me :)
     
  7. Offline

    Zombie_Striker

    @ArsenArsen
    Time to necro this thread.

    Since bukkitdev was updated, do you know if this updater still works? Last time I checked it still worked, but when I was reviewing the stats on other server, it says they they are still using the old versions of my plugin (even though they should have been updated months ago.)
     
  8. Offline

    ArsenArsen

    I have checked the API response from my phone as soon as the update happen, seemed right to me.. I'll test it tommorow.
     
  9. Offline

    I Al Istannen

    @ArsenArsen
    I made a bad one too, over here.

    How do you match the versions? I added a time matcher, which just uses the first and one that uses semantic versioning (and a user supplied regex for cleaning the name up).

    Also:

    THAT IS SO FREAKING DIRTY
    xD Check if the response code is a redirect (there are constants in the HTTPUrlConnection)
     
  10. Offline

    ArsenArsen

    Why fix something non broken? :p

    My unit tests passed though... http://i.imgur.com/dvoibrM.png
     
Thread Status:
Not open for further replies.

Share This Page