Class PluginInstallUtils

java.lang.Object
com.ultikits.ultitools.utils.PluginInstallUtils

public class PluginInstallUtils extends Object
Utility class for plugin installation and management operations. Provides methods to download, install, and uninstall UltiTools plugins from the remote plugin repository.
插件安装和管理操作的实用工具类。 提供从远程插件仓库下载、安装和卸载UltiTools插件的方法。
Since:
6.0.0
Author:
wisdomme
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • GSON

      private static final com.google.gson.Gson GSON
    • baseUrl

      private static volatile String baseUrl
    • customBaseUrl

      private static String customBaseUrl
  • Constructor Details

    • PluginInstallUtils

      public PluginInstallUtils()
  • Method Details

    • getBaseUrl

      static String getBaseUrl()
      Get the base URL for API calls. Uses lazy initialization to avoid requiring UltiTools at class loading time.
      获取API调用的基础URL。 使用延迟初始化以避免在类加载时需要UltiTools。
      Returns:
      the base URL
    • setBaseUrlForTesting

      static void setBaseUrlForTesting(String url)
      Set a custom base URL for testing purposes. This should only be used in unit tests.
      设置自定义的基础URL,仅用于测试目的。
      Parameters:
      url - the custom base URL, or null to reset to default
    • resetBaseUrl

      static void resetBaseUrl()
      Reset the base URL to force re-initialization. This should only be used in unit tests.
      重置基础URL以强制重新初始化,仅用于测试目的。
    • normalizeIdentifyString

      private static String normalizeIdentifyString(String idString)
    • encodeQueryValue

      private static String encodeQueryValue(String value)
    • encodePathSegment

      private static String encodePathSegment(String value)
    • installedJarName

      static String installedJarName(String idString, String version)
    • unwrapData

      private static <T> T unwrapData(String body, Class<T> clazz)
      Extract the "data" field from a backend API envelope response. The backend wraps responses as {"code":"200","msg":"Success","data":...}.
      从后端API信封响应中提取"data"字段。
      Type Parameters:
      T - the target type
      Parameters:
      body - the raw JSON response body
      clazz - the class to deserialize the data field into
      Returns:
      the deserialized data, or null if absent or response indicates error
    • unwrapData

      private static <T> T unwrapData(String body, Type type)
      Extract the "data" field from a backend API envelope response (generic type version).
      从后端API信封响应中提取"data"字段(泛型版本)。
      Type Parameters:
      T - the target type
      Parameters:
      body - the raw JSON response body
      type - the Type to deserialize the data field into
      Returns:
      the deserialized data, or null if absent or response indicates error
    • unwrapStringData

      private static String unwrapStringData(String body)
      Extract a String value from the "data" field of a backend API envelope response. Handles both quoted JSON strings and primitive values.
      从后端API信封响应的"data"字段中提取字符串值。
      Parameters:
      body - the raw JSON response body
      Returns:
      the data as a String, or null if absent or response indicates error
    • getPluginList

      public static List<PluginEntity> getPluginList(int page, int pageSize)
      Get plugin list online.
      在线获取插件列表。
      Parameters:
      page - 页数
      pageSize - 每页数量
      Returns:
      插件列表
    • getPluginVersionDownloadLink

      public static String getPluginVersionDownloadLink(String idString, String version)
      Get plugin download link.
      获取插件下载链接。
      Parameters:
      idString - 插件ID
      version - 版本
      Returns:
      插件下载链接
    • getPluginVersions

      public static List<String> getPluginVersions(String idString)
      Get plugin versions.
      获取插件版本列表。
      Parameters:
      idString - 插件ID
      Returns:
      插件版本列表
    • getPluginLatestVersion

      public static String getPluginLatestVersion(String idString)
      Get plugin latest version.
      获取插件最新版本。
      Parameters:
      idString - 插件ID
      Returns:
      插件最新版本
    • getPluginLatestDownloadLink

      public static String getPluginLatestDownloadLink(String idString)
      Get plugin latest version download link.
      获取插件最新版本下载链接。
      Parameters:
      idString - Plugin identify string
      插件ID
      Returns:
      Download link for latest version
      插件最新版本下载链接
    • getPlugin

      public static PluginEntity getPlugin(String idString)
      Get plugin information by identify string.
      通过标识字符串获取插件信息。
      Parameters:
      idString - Plugin identify string
      插件ID
      Returns:
      Plugin entity or null if not found
      插件信息,未找到返回null
    • installLatestPlugin

      public static boolean installLatestPlugin(String idString)
      Install latest plugin.
      安装最新插件。
      Parameters:
      idString - 插件ID
      Returns:
      是否安装成功
    • installPlugin

      public static boolean installPlugin(String idString, String version)
      Install plugin.
      安装插件。
      Parameters:
      idString - 插件ID
      version - 版本
      Returns:
      是否安装成功
    • findPluginJar

      public static File findPluginJar(File pluginsFolder, String identifyString)
      Find the JAR file for a plugin by its identify-string. Scans all JARs in the given directory, reads plugin.yml from each.
      通过identify-string查找插件的JAR文件。
      Parameters:
      pluginsFolder - the folder to scan
      identifyString - the identify-string to match
      Returns:
      the matching JAR file, or null if not found
    • updatePlugin

      public static boolean updatePlugin(String identifyString)
      Update a plugin module: download latest version and delete old JAR.
      更新插件模块:下载最新版本并删除旧JAR。
      Parameters:
      identifyString - the plugin identify string
      Returns:
      true if update succeeded
    • uninstallPlugin

      public static boolean uninstallPlugin(String name) throws IOException
      Uninstall plugin.
      卸载插件。
      Parameters:
      name - 插件名称
      Returns:
      是否卸载成功
      Throws:
      IOException - if an I/O error occurs