Package com.install4j.api.update
Class UpdateChecker
java.lang.Object
com.install4j.api.update.UpdateChecker
Utility class to download an update descriptor programmatically from a given URL. In an installer
application, it is recommended to use the "Check for update" action instead. This class is mainly
intended for checking for updates in your application.
In order to use this class in your application, please include resource/i4jruntime.jar from your
install4j installation into your class path. You do not need to distribute this file
along with your application, install4j will do this automatically for you.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexecuteScheduledUpdate(List<String> updaterArguments, boolean restartLauncher, Runnable shutdownRunnable) If an update is scheduled for installation, execute the update installer and shutdown the current launcher.static voidexecuteScheduledUpdate(List<String> updaterArguments, boolean restartLauncher, List<String> launcherArguments, Runnable shutdownRunnable) If an update is scheduled for installation, execute the update installer and shutdown the current launcher.static UpdateDescriptorgetUpdateDescriptor(UpdateCheckRequest updateCheckRequest) Download anupdates.xmlfile programatically from a given URL and returns anUpdateDescriptorinstance.static UpdateDescriptorgetUpdateDescriptor(String urlSpec, ApplicationDisplayMode displayMode) Convenience method forgetUpdateDescriptor(UpdateCheckRequest).static UpdateDescriptorgetUpdateDescriptor(String urlSpec, ApplicationDisplayMode displayMode, ErrorHandlingCallback errorHandlingCallback) Convenience method forgetUpdateDescriptor(UpdateCheckRequest).static booleanChecks if the "Schedule update installation" action has registered a downloaded update for installation.static booleanisVersionGreaterThan(String expectedHigherVersion, String expectedLowerVersion) Compares two version strings and checks if the first version is greater than the second version.static booleanisVersionLessThanOrEqual(String expectedLowerVersion, String expectedHigherVersion) Compares two version strings and checks if the first version is lower or equal than the second version.
-
Constructor Details
-
UpdateChecker
public UpdateChecker()
-
-
Method Details
-
getUpdateDescriptor
public static UpdateDescriptor getUpdateDescriptor(String urlSpec, ApplicationDisplayMode displayMode) throws UserCanceledException, IOException Convenience method forgetUpdateDescriptor(UpdateCheckRequest).- Parameters:
urlSpec- seeUpdateCheckRequest.urlSpec(String)displayMode- seeUpdateCheckRequest.applicationDisplayMode(ApplicationDisplayMode)- Throws:
UserCanceledException- if the user cancels the proxy dialogIOException- if the download fails
-
getUpdateDescriptor
public static UpdateDescriptor getUpdateDescriptor(String urlSpec, ApplicationDisplayMode displayMode, ErrorHandlingCallback errorHandlingCallback) throws UserCanceledException, IOException Convenience method forgetUpdateDescriptor(UpdateCheckRequest).- Parameters:
urlSpec- seeUpdateCheckRequest.urlSpec(String)displayMode- seeUpdateCheckRequest.applicationDisplayMode(ApplicationDisplayMode)errorHandlingCallback- seeUpdateCheckRequest.errorHandlingCallback(ErrorHandlingCallback)- Throws:
UserCanceledException- if the user cancels the proxy dialogIOException- if the download fails
-
getUpdateDescriptor
public static UpdateDescriptor getUpdateDescriptor(UpdateCheckRequest updateCheckRequest) throws UserCanceledException, IOException Download anupdates.xmlfile programatically from a given URL and returns anUpdateDescriptorinstance. TheUpdateCheckRequestspecifies the URL and other connection options.- Parameters:
updateCheckRequest- the update check request- Returns:
- the update descriptor
- Throws:
UserCanceledException- if the user cancels the proxy dialogIOException- if the download fails
-
isUpdateScheduled
public static boolean isUpdateScheduled()Checks if the "Schedule update installation" action has registered a downloaded update for installation. This method returnsfalseif the update won't be currently executed because of a failed previous installation or because the installer is currently running. If an update fails or is canceled, it will be rescheduled after 24 hours. The number of times the rescheduling happens can be configured with the "Schedule update installation" action.- Returns:
trueif scheduled and ready to be executed
-
executeScheduledUpdate
public static void executeScheduledUpdate(List<String> updaterArguments, boolean restartLauncher, Runnable shutdownRunnable) If an update is scheduled for installation, execute the update installer and shutdown the current launcher.Equivalent to calling
executeScheduledUpdate(List, boolean, List, Runnable)withnullfor thelauncherArgumentsparameter- Parameters:
updaterArguments- updaterArguments to be passed to the updater.restartLauncher- iftruea GUI or a console launcher will be restarted after the installation. If called from a service launcher, the installer must take care of starting the service again. It can usecontext.getBooleanVariable("sys.automaticUpdate")if restart should be done conditionally.shutdownRunnable- if you want to invoke a custom routine for shutting down the current JVM, you can pass in aRunnable. Otherwise,System.exit(0)will be called. If you pass in a Runnable, you must callSystem.exitat the end of your shutdown procedure.
-
executeScheduledUpdate
public static void executeScheduledUpdate(List<String> updaterArguments, boolean restartLauncher, List<String> launcherArguments, Runnable shutdownRunnable) If an update is scheduled for installation, execute the update installer and shutdown the current launcher.- Parameters:
updaterArguments- updaterArguments to be passed to the updater.restartLauncher- iftruea GUI or a console launcher will be restarted after the installation. If called from a service launcher, the installer must take care of starting the service again. It can usecontext.getBooleanVariable("sys.automaticUpdate")if restart should be done conditionally.launcherArguments- ifrestartLauncheristrueand this method is called within a GUI or a console launcher, the given arguments will be passed to the restarted launchershutdownRunnable- if you want to invoke a custom routine for shutting down the current JVM, you can pass in aRunnable. Otherwise,System.exit(0)will be called. If you pass in a Runnable, you must callSystem.exitat the end of your shutdown procedure.
-
isVersionLessThanOrEqual
public static boolean isVersionLessThanOrEqual(String expectedLowerVersion, String expectedHigherVersion) Compares two version strings and checks if the first version is lower or equal than the second version. This implementation is used byUpdateDescriptor.getPossibleUpdateEntry()andUpdateDescriptorEntry.checkVersionCompatible(String)to check the compliance with the range of minimum and maximum updatable version.- Parameters:
expectedLowerVersion- the version that is expected to be lower or equalexpectedHigherVersion- the version that is expected to be higher or equal- Returns:
trueifexpectedHigherVersionis higher or equal thanexpectedLowerVersion
-
isVersionGreaterThan
public static boolean isVersionGreaterThan(String expectedHigherVersion, String expectedLowerVersion) Compares two version strings and checks if the first version is greater than the second version. This implementation is used byUpdateDescriptor.getPossibleUpdateEntry()andUpdateDescriptorEntry.checkVersionCompatible(String)to check if a new version is greater than the installed version.- Parameters:
expectedHigherVersion- the version that is expected to be higherexpectedLowerVersion- the version that is expected to be lower- Returns:
trueifexpectedHigherVersionis higher thaninstalledVersion
-