Package com.technicjelle
Class UpdateChecker
- java.lang.Object
-
- com.technicjelle.UpdateChecker
-
public class UpdateChecker extends Object
Checks for updates on a GitHub repository
-
-
Constructor Summary
Constructors Constructor Description UpdateChecker(@NotNull String author, @NotNull String repoName, @NotNull String currentVersion)
Start the program with-Dtechnicjelle.updatechecker.disabled
to disable the update checker
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
check()
Checks for updates from a GitHub repository's releases
This method blocks the thread it is called fromvoid
checkAsync()
Checks for updates from a GitHub repository's releases
This method does not block the thread it is called fromString
getCurrentVersion()
Gets the current version of the program.
Useful in case you want to log a custom message.
Does not actually check for updatesString
getLatestVersion()
Checks if necessary and returns the latest available versionOptional<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 ownLogger
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/latestString
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 updatesboolean
isUpdateAvailable()
Checks if necessary and returns whether an update is available or notvoid
logUpdateMessage(@NotNull Logger logger)
This method logs a message to the console if an update is availablevoid
logUpdateMessageAsync(@NotNull Logger logger)
This method logs a message to the console if an update is available, asynchronously
-
-
-
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 UsernamerepoName
- GitHub Repository NamecurrentVersion
- 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 orfalse
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 ownLogger
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
-
-