Class ApplicationCore
ApplicationCore class provides core utility methods for managing
and configuring applications. It includes functionality for processing
command-line arguments, detecting the operating system, retrieving application
metadata, and managing configuration files.
This class is designed to be a central hub for application-level operations, ensuring consistency and reusability across the application.
Key Features
- Processes CLI arguments using
CommandManager. - Detects the operating system type.
- Retrieves the latest application version based on GitHub release tags.
- Determines the application name based on the JAR file or package structure.
- Manages application configuration directories and files.
Usage
This class is intended to be used as a utility class with static methods, and therefore cannot be instantiated. For an example usage, please refer to the SwingGUIApplicationTemplate.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckCLIArgs(String[] args, CommandManager commandManager) Processes and executes CLI arguments using the providedCommandManager.static StringdetectOS()Detects the operating system and returns its general type.static StringgetApplicationConfigDirectory(Class<?> clazz, String developerName) Retrieves the configuration directory for the application within the developer's config folder.static StringgetApplicationName(Class<?> clazz) Determines the application name based on the JAR file or package structure.static StringgetLatestVersion(String remoteURL) Retrieves the latest version of the application from the remote's releases page using releases/latest tag redirect function.static StringgetLatestVersion(String remoteURL, String customPrefix) Retrieves the latest version of the application from the remote's releases page using releases/latest tag redirect function.static StringgetLatestVersion(String remoteURL, String customPrefix, String customSuffix) Retrieves the latest version of the application from the remote's releases page using releases/latest tag redirect function.static voidloadConfigFile(Class<?> clazz, String developerName) Loads aPreferencesnode from an XML file in the application's configuration directory.static voidsaveConfigFile(Class<?> clazz, String developerName, Preferences prefs) Saves aPreferencesnode as an XML file in the application's configuration directory.
-
Method Details
-
checkCLIArgs
Processes and executes CLI arguments using the providedCommandManager.- Parameters:
args- the array of CLI arguments to processcommandManager- CommandManager instance used to execute commands- See Also:
-
detectOS
Detects the operating system and returns its general type.- Returns:
- a string representing the OS type:
- "windows" for Windows-based systems
- "mac" for MacOS
- "unix" for Unix/Linux-based systems
- "unknown" if the OS cannot be determined
-
getLatestVersion
Retrieves the latest version of the application from the remote's releases page using releases/latest tag redirect function.Uses version tags in the format "X.Y.Z".
Defaults tag prefix to "v" without a suffix, (vX.Y.Z).
Example URL:
https://gitlab.example.com/namespace/project/-/releases/permalink/latesthttps://github.com/user/project/releases/latest- Parameters:
remoteURL- the URL of the latest releases page- Returns:
- the latest version as a string (ex: "1.2.1"), or
nullif no valid version is found - See Also:
-
getLatestVersion
Retrieves the latest version of the application from the remote's releases page using releases/latest tag redirect function.Uses version tags in the format "X.Y.Z".
Defaults to tag prefix without a suffix, (<your-prefix>X.Y.Z).
Example URL:
https://gitlab.example.com/namespace/project/-/releases/permalink/latesthttps://github.com/user/project/releases/latest- Parameters:
remoteURL- the URL of the latest releases pagecustomPrefix- the prefix of the version tag (ex: "v" or "release-")- Returns:
- the latest version as a string (ex: "1.2.1"), or
nullif no valid version is found - See Also:
-
getLatestVersion
Retrieves the latest version of the application from the remote's releases page using releases/latest tag redirect function.Uses version tags in the format "X.Y.Z".
Defaults to tag prefix without a suffix, (<your-prefix>X.Y.Z<your-suffix>).
Example URL:
https://gitlab.example.com/namespace/project/-/releases/permalink/latesthttps://github.com/user/project/releases/latest- Parameters:
remoteURL- the URL of the latest releases pagecustomPrefix- the prefix of the version tag (ex: "v" or "release-")customSuffix- the suffix of the version tag (ex: "-release" or "-stable")- Returns:
- the latest version as a string (ex: "1.2.1"), or
nullif no valid version is found - See Also:
-
getApplicationName
Determines the application name based on the JAR file or package structure.If running as a JAR, the name is derived from the JAR file name. Otherwise, it uses the package name 2 levels after
"com"(ex:"com.everdro1d.libs"becomes"libs").- Parameters:
clazz- themain()class of the application- Returns:
- the name of the application, (ex:
"dro1d-libs-java"or"libs"), or"UnknownApplication"if it cannot be determined.
-
getApplicationConfigDirectory
Retrieves the configuration directory for the application within the developer's config folder.- Parameters:
clazz- themain()class of the applicationdeveloperName- the name of the developer or vendor (ex:"dro1dDev")- Returns:
- the path to the application's configuration directory
-
saveConfigFile
Saves aPreferencesnode as an XML file in the application's configuration directory.Use this method alongside
loadConfigFile(Class, String)to maintain persistent application settings.- Parameters:
clazz- themain()class of the applicationdeveloperName- the name of the developer or vendor (ex:"dro1dDev")prefs- thePreferencesnode to save- See Also:
-
loadConfigFile
Loads aPreferencesnode from an XML file in the application's configuration directory.Use this method alongside
saveConfigFile(Class, String, Preferences)to restore application settings.- Parameters:
clazz- themain()class of the applicationdeveloperName- the name of the developer or vendor (ex:"dro1dDev")- See Also:
-