SudokuFX
Loading...
Searching...
No Matches
fr.softsf.sudokufx.service.external.VersionService Class Reference

Service for checking if the application version is up to date by querying GitHub. More...

+ Collaboration diagram for fr.softsf.sudokufx.service.external.VersionService:

Public Member Functions

 VersionService (HttpClient httpClient, ObjectMapper objectMapper)
 Initializes the VersionService with the provided HttpClient.
 
Task< Boolean > checkLatestVersion ()
 Checks if the current application version is up-to-date by querying the GitHub API.
 

Private Member Functions

int compareVersions (final String version1, final String version2)
 Compares two version strings in the format MAJOR.MINOR.PATCH (e.g., "1.2.3").
 
boolean parseResponse (String json)
 Parses the JSON response from the GitHub API to extract the latest published version.
 

Private Attributes

final HttpClient httpClient
 
final ObjectMapper objectMapper
 

Static Private Attributes

static final String CURRENT_VERSION
 
static final int HTTP_STATUS_OK = 200
 
static final Logger LOG = LoggerFactory.getLogger(VersionService.class)
 

Detailed Description

Service for checking if the application version is up to date by querying GitHub.

It retrieves the latest release tag from the GitHub API and compares it with the current version. If an update is available, the result can be used to notify the user.

All method parameters and return values in this package are non-null by default, thanks to the @NonNullApi annotation at the package level.

Constructor & Destructor Documentation

◆ VersionService()

fr.softsf.sudokufx.service.external.VersionService.VersionService ( HttpClient httpClient,
ObjectMapper objectMapper )

Initializes the VersionService with the provided HttpClient.

This service is responsible for checking the latest version by making HTTP requests.

Parameters
httpClientthe HttpClient used to perform HTTP requests.

Member Function Documentation

◆ checkLatestVersion()

Task< Boolean > fr.softsf.sudokufx.service.external.VersionService.checkLatestVersion ( )

Checks if the current application version is up-to-date by querying the GitHub API.

This method runs in the background using a JavaFX Task to avoid blocking the UI thread. It retrieves the latest release version from the repository and compares it with the current application version. In case of errors (e.g., timeout, interruption, or network issues), it assumes the version is up-to-date and logs the exception details.

Returns
A Task<Boolean> that returns true if the version is up-to-date or if an error occurs, and false if an update is available.
+ Here is the call graph for this function:

◆ compareVersions()

int fr.softsf.sudokufx.service.external.VersionService.compareVersions ( final String version1,
final String version2 )
private

Compares two version strings in the format MAJOR.MINOR.PATCH (e.g., "1.2.3").

The comparison is done based on the numeric values of major, minor, and patch components.

Parameters
version1the first version string, non-null and non-blank.
version2the second version string, non-null and non-blank.
Returns
a negative integer if version1 is older, a positive integer if version1 is newer, or 0 if both versions are equal.
Exceptions
IllegalArgumentExceptionif either version string is null, empty, or blank.
NumberFormatExceptionif the version strings are not properly formatted (e.g., not "X.Y.Z").

◆ parseResponse()

boolean fr.softsf.sudokufx.service.external.VersionService.parseResponse ( String json)
private

Parses the JSON response from the GitHub API to extract the latest published version.

Validates the input, extracts the first tag, checks its format, and compares it with the current application version.

Parameters
jsonThe non-null, non-blank JSON response from the GitHub API.
Returns
true if the current version is up to date or if the response is invalid or an error occurs; false if a newer version is available.
Exceptions
IllegalArgumentExceptionif the JSON is null, empty or blank.
+ Here is the call graph for this function:

Member Data Documentation

◆ CURRENT_VERSION

final String fr.softsf.sudokufx.service.external.VersionService.CURRENT_VERSION
staticprivate
Initial value:
=
JVMApplicationProperties.INSTANCE.getAppVersion().isEmpty()
? ""
: JVMApplicationProperties.INSTANCE.getAppVersion().substring(1)
Utility enum for managing JVM application properties.
Definition JVMApplicationProperties.java:17
INSTANCE
Definition JVMApplicationProperties.java:18

◆ HTTP_STATUS_OK

final int fr.softsf.sudokufx.service.external.VersionService.HTTP_STATUS_OK = 200
staticprivate

◆ httpClient

final HttpClient fr.softsf.sudokufx.service.external.VersionService.httpClient
private

◆ LOG

final Logger fr.softsf.sudokufx.service.external.VersionService.LOG = LoggerFactory.getLogger(VersionService.class)
staticprivate

◆ objectMapper

final ObjectMapper fr.softsf.sudokufx.service.external.VersionService.objectMapper
private

The documentation for this class was generated from the following file: