Class ApplicationCore

java.lang.Object
com.everdro1d.libs.core.ApplicationCore

public final class ApplicationCore extends Object
The 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 Details

    • checkCLIArgs

      public static void checkCLIArgs(String[] args, CommandManager commandManager)
      Processes and executes CLI arguments using the provided CommandManager.
      Parameters:
      args - the array of CLI arguments to process
      commandManager - CommandManager instance used to execute commands
      See Also:
    • detectOS

      public static String 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

      public static String getLatestVersion(String remoteURL)
      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/latest

      https://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 null if no valid version is found
      See Also:
    • getLatestVersion

      public static String getLatestVersion(String remoteURL, String customPrefix)
      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/latest

      https://github.com/user/project/releases/latest

      Parameters:
      remoteURL - the URL of the latest releases page
      customPrefix - the prefix of the version tag (ex: "v" or "release-")
      Returns:
      the latest version as a string (ex: "1.2.1"), or null if no valid version is found
      See Also:
    • getLatestVersion

      public static String getLatestVersion(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.

      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/latest

      https://github.com/user/project/releases/latest

      Parameters:
      remoteURL - the URL of the latest releases page
      customPrefix - 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 null if no valid version is found
      See Also:
    • getApplicationName

      public static String getApplicationName(Class<?> clazz)
      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 - the main() class of the application
      Returns:
      the name of the application, (ex: "dro1d-libs-java" or "libs"), or "UnknownApplication" if it cannot be determined.
    • getApplicationConfigDirectory

      public static String getApplicationConfigDirectory(Class<?> clazz, String developerName)
      Retrieves the configuration directory for the application within the developer's config folder.
      Parameters:
      clazz - the main() class of the application
      developerName - the name of the developer or vendor (ex: "dro1dDev")
      Returns:
      the path to the application's configuration directory
    • saveConfigFile

      public static void saveConfigFile(Class<?> clazz, String developerName, Preferences prefs)
      Saves a Preferences node as an XML file in the application's configuration directory.

      Use this method alongside loadConfigFile(Class, String) to maintain persistent application settings.

      Parameters:
      clazz - the main() class of the application
      developerName - the name of the developer or vendor (ex: "dro1dDev")
      prefs - the Preferences node to save
      See Also:
    • loadConfigFile

      public static void loadConfigFile(Class<?> clazz, String developerName)
      Loads a Preferences node from an XML file in the application's configuration directory.

      Use this method alongside saveConfigFile(Class, String, Preferences) to restore application settings.

      Parameters:
      clazz - the main() class of the application
      developerName - the name of the developer or vendor (ex: "dro1dDev")
      See Also: