Class PluginManager

java.lang.Object
org.rapidcontext.app.plugin.PluginManager

public final class PluginManager extends Object
A plug-in manager. This singleton class contains the utility functions for managing the plug-in loading and unloading.
Version:
1.0
  • Field Details

    • SYSTEM_PLUGIN

      public static final String SYSTEM_PLUGIN
      The identifier of the system plug-in.
      See Also:
    • LOCAL_PLUGIN

      public static final String LOCAL_PLUGIN
      The identifier of the local plug-in.
      See Also:
    • builtinDir

      public File builtinDir
      The built-in plug-in directory. This is the base directory from which built-in plug-ins are loaded.
    • pluginDir

      public File pluginDir
      The plug-in directory. This is the base directory from which plug-ins are loaded.
    • storage

      public AppStorage storage
      The storage to use when loading and unloading plug-ins.
    • classLoader

      public PluginManager.PluginClassLoader classLoader
      The plug-in class loader.
  • Constructor Details

    • PluginManager

      public PluginManager(File builtinDir, File pluginDir, AppStorage storage)
      Creates a new plug-in storage.
      Parameters:
      builtinDir - the built-in plug-in directory
      pluginDir - the base plug-in directory
      storage - the storage to use for plug-ins
  • Method Details

    • isAvailable

      public boolean isAvailable(String pluginId)
      Checks if the specified plug-in is currently available, i.e. if it has been mounted to the plug-in storage.
      Parameters:
      pluginId - the unique plug-in id
      Returns:
      true if the plug-in was available, or false otherwise
    • isBuiltIn

      public boolean isBuiltIn(String pluginId)
      Checks if the specified plug-in is built-in (or installed). Note any plug-ins located in the built-in plug-in directory will be considered built-in.
      Parameters:
      pluginId - the unique plug-in id
      Returns:
      true if the plug-in exists and is built-in, or false otherwise
    • install

      public String install(File file) throws PluginException
      Installs a plug-in from the specified file. If an existing plug-in with the same id already exists, it will be replaced without warning. Note that the new plug-in will NOT be loaded.
      Parameters:
      file - the plug-in ZIP file
      Returns:
      the unique plug-in id
      Throws:
      PluginException - if the plug-in couldn't be installed correctly
    • uninstall

      public void uninstall(String pluginId) throws PluginException
      Uninstalls and removes a plug-in file. If the plug-in is loaded or mounted, it will first be unloaded and the associated storage will be destroyed.
      Parameters:
      pluginId - the unique plug-in id
      Throws:
      PluginException - if the plug-in removal failed
    • load

      public void load(String pluginId) throws PluginException
      Loads a plug-in. The plug-in file storage will be added to the root overlay and the plug-in configuration file will be used to initialize the plug-in Java class.
      Parameters:
      pluginId - the unique plug-in id
      Throws:
      PluginException - if the plug-in loading failed
    • unload

      public void unload(String pluginId) throws PluginException
      Unloads a plug-in. All plug-in classes will be destroyed and the plug-in file storage will be hidden from the root overlay.
      Parameters:
      pluginId - the unique plug-in id
      Throws:
      PluginException - if the plug-in unloading failed
    • unloadAll

      public void unloadAll()
      Unloads all plug-ins. All plug-in classes will be destroyed and the plug-in file storages will be hidden from the root overlay. Note that the built-in plug-ins will be unaffected by this.