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)
        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
    • 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.
      • getUpdateMessage

        public Optional<String> getUpdateMessage()
        Checks if necessary and returns a message if an update is available.
        The message will contain the latest version and a link to the GitHub releases page.
        Useful if you don't use Java's own Logger and you want to use your own.
        Example:
        New version available: v2.5 (current: v2.4)
        Download it at https://github.com/TechnicJelle/UpdateCheckerJava/releases/latest
        Returns:
        An optional containing the update message or an empty optional if there is no update available
      • 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 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 to the GitHub releases page
      • logUpdateMessage

        public void logUpdateMessage​(@NotNull
                                     @NotNull Logger logger)
        This method logs a message to the console if an update is available
        Parameters:
        logger - Logger to log a potential update notification to
      • logUpdateMessageAsync

        public void logUpdateMessageAsync​(@NotNull
                                          @NotNull Logger logger)
        This method logs a message to the console if an update is available, asynchronously
        Parameters:
        logger - Logger to log a potential update notification to