Class AnahataUcUtils

java.lang.Object
uno.anahata.asi.nb.uc.AnahataUcUtils

public final class AnahataUcUtils extends Object
Universal utility class for managing NetBeans version detection, Anahata ASI Update Centers (Universal, Stable, and Dev Snapshot), URL connectivity checks, legacy update center cleanup, and automated installation of Anahata ASI Studio and JavaFX runtimes.
Author:
anahata
  • Field Details

    • LOG

      private static final Logger LOG
      Logger instance for update center operations.
    • PROVIDER_CODENAME_UNIVERSAL

      public static final String PROVIDER_CODENAME_UNIVERSAL
      Unique provider code name for the universal cross-version update center.
      See Also:
    • PROVIDER_CODENAME_STABLE

      public static final String PROVIDER_CODENAME_STABLE
      Unique internal provider code name for the official stable update center.
      See Also:
    • PROVIDER_CODENAME_DEV

      public static final String PROVIDER_CODENAME_DEV
      Unique internal provider code name for the development snapshot update center.
      See Also:
    • ICON_BASE

      public static final String ICON_BASE
      Resource path on classpath for the Anahata 16x16 icon displayed in the Plugins manager.
      See Also:
    • CATEGORY_DISPLAY_NAME

      public static final String CATEGORY_DISPLAY_NAME
      Category display name rendered for the provider sources.
      See Also:
    • CATEGORY_DEV_DISPLAY_NAME

      public static final String CATEGORY_DEV_DISPLAY_NAME
      Category display name rendered for the development snapshot provider source.
      See Also:
    • STUDIO_CODE_NAME

      public static final String STUDIO_CODE_NAME
      Code name base for the core NetBeans plugin module.
      See Also:
    • UC_CODE_NAME

      public static final String UC_CODE_NAME
      Code name base for the standalone update center plugin module.
      See Also:
    • JAVAFX_KIT_CODE_NAME

      public static final String JAVAFX_KIT_CODE_NAME
      Code name base for JavaFX runtime kit module.
      See Also:
    • UNIVERSAL_UPDATE_URL

      public static final String UNIVERSAL_UPDATE_URL
      Universal update center catalog URL.
      See Also:
    • MAVEN_STUDIO_URL

      public static final String MAVEN_STUDIO_URL
      Maven Central search URL for Anahata ASI Studio NetBeans module.
      See Also:
    • MAVEN_UC_URL

      public static final String MAVEN_UC_URL
      Maven Central search URL for Anahata ASI Update Center module.
      See Also:
  • Constructor Details

    • AnahataUcUtils

      private AnahataUcUtils()
      Private constructor to prevent direct instantiation.
  • Method Details

    • getNetBeansMajorVersion

      public static String getNetBeansMajorVersion()
      Detects the active NetBeans IDE major version (e.g., "30", "31") using a robust multi-tiered detection strategy.
      Returns:
      The detected major NetBeans version string (e.g. "30"), or null if running in an unrecognized environment.
    • getUpdateCenterUrl

      public static String getUpdateCenterUrl(AnahataUcUtils.UpdateCenterType type)
      Resolves the catalog URL for the given update center type.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      Returns:
      The URL string.
    • getUpdateCenterDisplayName

      public static String getUpdateCenterDisplayName(AnahataUcUtils.UpdateCenterType type)
      Resolves the default display name for the given update center type.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      Returns:
      The display name string.
    • getUpdateCenterCodeName

      public static String getUpdateCenterCodeName(AnahataUcUtils.UpdateCenterType type)
      Resolves the internal provider code name for the given update center type.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      Returns:
      The code name string.
    • getUpdateCenterDescription

      public static String getUpdateCenterDescription(AnahataUcUtils.UpdateCenterType type)
      Resolves the description for the given update center type.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      Returns:
      The descriptive text.
    • registerDefaultUpdateCenters

      public static void registerDefaultUpdateCenters()
      Registers all standard Anahata Update Centers in NetBeans if not already registered.

      - Universal Update Center: Registered and enabled by default. - Stable Update Center: Registered and enabled by default. - Dev Snapshot Update Center: Registered in a disabled state by default.

    • findProvider

      public static org.netbeans.api.autoupdate.UpdateUnitProvider findProvider(List<org.netbeans.api.autoupdate.UpdateUnitProvider> providers, String codeName, String urlStr)
      Searches a list of update unit providers for a matching code name or URL.
      Parameters:
      providers - The list of providers to search.
      codeName - The provider code name to look for.
      urlStr - The provider URL string to look for.
      Returns:
      The matching provider, or null if not found.
    • getUpdateUnitProvider

      public static org.netbeans.api.autoupdate.UpdateUnitProvider getUpdateUnitProvider(AnahataUcUtils.UpdateCenterType type)
      Retrieves the specified Anahata UpdateUnitProvider if registered.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      Returns:
      The registered UpdateUnitProvider, or null if not registered.
    • getLegacyAnahataProviders

      public static List<org.netbeans.api.autoupdate.UpdateUnitProvider> getLegacyAnahataProviders()
      Detects any legacy/obsolete Anahata update unit providers registered from previous or different NetBeans major versions that can be safely cleaned up.
      Returns:
      A list of legacy UpdateUnitProvider instances.
    • removeProvider

      public static void removeProvider(org.netbeans.api.autoupdate.UpdateUnitProvider provider)
      Removes an UpdateUnitProvider from NetBeans Autoupdate.
      Parameters:
      provider - The provider to remove.
    • isUpdateCenterRegistered

      public static boolean isUpdateCenterRegistered(AnahataUcUtils.UpdateCenterType type)
      Checks whether the specified Anahata Update Center is registered in the IDE.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      Returns:
      true if registered, false otherwise.
    • isUpdateCenterEnabled

      public static boolean isUpdateCenterEnabled(AnahataUcUtils.UpdateCenterType type)
      Checks whether the specified Anahata Update Center is registered and enabled.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      Returns:
      true if enabled, false otherwise.
    • setUpdateCenterEnabled

      public static void setUpdateCenterEnabled(AnahataUcUtils.UpdateCenterType type, boolean enabled)
      Sets the enabled state of the specified Anahata Update Center.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      enabled - The desired enabled state.
    • setUpdateCenterTrusted

      public static void setUpdateCenterTrusted(AnahataUcUtils.UpdateCenterType type, boolean trusted)
      Sets the trusted state of the specified Anahata Update Center.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType.
      trusted - The desired trusted state.
    • checkUrlConnectivity

      public static String checkUrlConnectivity(String urlStr)
      Performs a lightweight HTTP network connectivity check against a remote URL.
      Parameters:
      urlStr - The URL to check.
      Returns:
      A status description (e.g., "Online", "Offline (404 Not Found)", "Offline (Timeout)").
    • getInstalledStudioDetails

      public static AnahataUcUtils.InstalledModuleDetails getInstalledStudioDetails()
      Retrieves detailed version metadata for the installed Anahata ASI Studio module.
      Returns:
      The AnahataUcUtils.InstalledModuleDetails, or null if not installed on disk.
    • getInstalledUcDetails

      public static AnahataUcUtils.InstalledModuleDetails getInstalledUcDetails()
      Retrieves detailed version metadata for the standalone Anahata Update Center module itself.
      Returns:
      The AnahataUcUtils.InstalledModuleDetails, or null if not found.
    • formatDownloadSize

      public static String formatDownloadSize(int bytes)
      Formats a byte size into a human-readable string (e.g. "137.0 MB" or "450 KB").
      Parameters:
      bytes - The size in bytes.
      Returns:
      The formatted string, or null if size is zero or unknown.
    • getInstalledStudioVersion

      public static String getInstalledStudioVersion()
      Gets the installed specification version of the Anahata ASI Studio plugin.
      Returns:
      The version string (e.g., "1.1.2"), or null if not installed.
    • isStudioInstalled

      public static boolean isStudioInstalled()
      Checks whether the Anahata ASI Studio plugin is installed on disk.
      Returns:
      true if installed, false otherwise.
    • isStudioEnabled

      public static boolean isStudioEnabled()
      Checks whether the Anahata ASI Studio plugin is installed and enabled.
      Returns:
      true if installed and active, false otherwise.
    • getAvailableStudioElementForProvider

      public static org.netbeans.api.autoupdate.UpdateElement getAvailableStudioElementForProvider(AnahataUcUtils.UpdateCenterType type)
      Locates any available update or install element for the Anahata ASI Studio plugin that originates from a specific update center provider.
      Parameters:
      type - The AnahataUcUtils.UpdateCenterType to check.
      Returns:
      The matching UpdateElement, or null if none found in this provider.
    • getAvailableStudioElement

      public static org.netbeans.api.autoupdate.UpdateElement getAvailableStudioElement()
      Locates the newest available UpdateElement for the Anahata ASI Studio plugin across all active update centers.
      Returns:
      The latest update element, or null if no updates/install elements are available.
    • refreshAnahataProviders

      public static void refreshAnahataProviders()
      Refreshes all active Anahata update unit providers against remote catalogs.
    • installOrUpdateStudio

      public static String installOrUpdateStudio(org.netbeans.api.autoupdate.UpdateElement element) throws Exception
      Installs or updates the Anahata ASI Studio module using NetBeans Autoupdate API.
      Parameters:
      element - The UpdateElement to install.
      Returns:
      A status message describing the outcome of the operation.
      Throws:
      Exception - if installation fails.
    • getJavaPlatformDescription

      public static String getJavaPlatformDescription()
      Retrieves a comprehensive, human-readable description of the host Java runtime platform.
      Returns:
      The formatted Java platform string (e.g. "OpenJDK Runtime Environment 26.0.1 (Eclipse Adoptium)").
    • getJavaFxFormattedStatus

      public static String getJavaFxFormattedStatus()
      Resolves the formatted JavaFX status string for NetBeans environment display.

      Returns "Version (JDK)" if provided by the host JVM, "Version (NB Module)" if provided by a NetBeans module, or "Not available" if absent.

      Returns:
      The formatted JavaFX status string.
    • isSystemJdkJavaFx

      public static boolean isSystemJdkJavaFx()
      Checks whether JavaFX is bundled directly in the host system JDK (e.g., Liberica Full JDK or Azul Zulu FX).

      Because this module does not declare a module dependency on NetBeans' JavaFX module, standard Class.forName("javafx.application.Platform") will ONLY find JavaFX if it is provided by the underlying JDK.

      Returns:
      true if JavaFX classes are available directly from the host JDK.
    • getSystemJdkJavaFxVersion

      private static String getSystemJdkJavaFxVersion()
      Resolves the version of JavaFX if bundled in the host JDK.
      Returns:
      The JavaFX version string, or null if not found.
    • isNetBeansJavaFxModuleActive

      public static boolean isNetBeansJavaFxModuleActive()
      Checks whether JavaFX runtime support is installed and enabled in NetBeans via plugin modules.
      Returns:
      true if a NetBeans module providing org.openide.modules.jre.JavaFX is active.
    • isJavaFxActive

      public static boolean isJavaFxActive()
      Checks whether JavaFX runtime support is active anywhere in the runtime (System JDK or NetBeans Module).
      Returns:
      true if active, false otherwise.
    • getJavaFxVersion

      public static String getJavaFxVersion()
      Gets the JavaFX version string and origin descriptor if available.
      Returns:
      The JavaFX version (e.g., "21.0.9 (System JDK)" or "21.0.9 (org.netbeans.modules.javafx2.kit)"), or null.
    • installOrActivateJavaFx

      public static String installOrActivateJavaFx() throws Exception
      Installs or activates the NetBeans JavaFX runtime support module.
      Returns:
      The outcome status message.
      Throws:
      Exception - if activation fails.