Class UpdateChecker


  • public class UpdateChecker
    extends Object
    Checks for updates on a GitHub repository
    • Constructor Detail

      • UpdateChecker

        public UpdateChecker​(@NotNull
                             @NotNull String author,
                             @NotNull
                             @NotNull String repoName,
                             @NotNull
                             @NotNull String currentVersion,
                             @NotNull
                             @NotNull Consumer<Throwable> onError)
        Start the program with -Dtechnicjelle.updatechecker.disabled to disable the update checker
        Parameters:
        author - GitHub Username
        repoName - GitHub Repository Name
        currentVersion - Current version of the program. This must be in the same format as the version tags on GitHub
        onError - Called when an internal error occurs. Use this to log the error using your logging system
    • Method Detail

      • check

        public void check()
        Checks for updates from a GitHub repository's releases
        This method blocks the thread it is called from
        See Also:
        checkAsync()
      • checkAsync

        public void checkAsync()
        Checks for updates from a GitHub repository's releases
        This method does not block the thread it is called from
        See Also:
        check()
      • getLatestVersion

        public String getLatestVersion()
        Checks if necessary and returns the latest available version
        Returns:
        the latest available version
      • isUpdateAvailable

        public boolean isUpdateAvailable()
        Checks if necessary and returns whether an update is available or not
        Returns:
        true if there is an update available or false otherwise.
      • getCurrentVersion

        public String getCurrentVersion()
        Gets the current version of the program.
        Useful in case you want to log a custom message.

        Does not actually check for updates
        Returns:
        The current version of the program
      • getUpdateURL

        public URL getUpdateURL()
        Gets the URL to the GitHub releases page, where the latest version can be downloaded.
        Useful in case you want to log a custom message.

        Does not actually check for updates
        Returns:
        The URL to the GitHub releases page
        See Also:
        getUpdateUrl()
      • getUpdateUrl

        public String getUpdateUrl()
        Gets the URL to the GitHub releases page, where the latest version can be downloaded.
        Useful in case you want to log a custom message.

        Does not actually check for updates
        Returns:
        The URL (as a String) to the GitHub releases page
        See Also:
        getUpdateURL()
      • trace

        @Contract(pure=true)
        @NotNull
        public static @NotNull String trace​(@NotNull
                                            @NotNull Throwable throwable)
        Convenience function to convert a Throwable to a String, including the stacktrace. Useful for when logging it.
        Parameters:
        throwable - The Throwable to convert to a String
        Returns:
        The converted String