Class CKEditorPluginDependencies

java.lang.Object
com.wontlost.ckeditor.CKEditorPluginDependencies

public final class CKEditorPluginDependencies extends Object
Plugin dependencies management for CKEditor 5.

This class manages the dependency relationships between CKEditor 5 plugins, ensuring that when a plugin is added, all its required dependencies are also included. Dependencies are gathered from the official CKEditor 5 documentation.

Usage example:

Set<CKEditorPlugin> plugins = new HashSet<>();
plugins.add(CKEditorPlugin.IMAGE_CAPTION);
plugins.add(CKEditorPlugin.TABLE_TOOLBAR);

// Automatically resolve all dependencies
Set<CKEditorPlugin> resolvedPlugins = CKEditorPluginDependencies.resolve(plugins);
// resolvedPlugins now includes IMAGE, TABLE, ESSENTIALS, PARAGRAPH, etc.
See Also:
  • Method Details

    • getDependencies

      public static Set<CKEditorPlugin> getDependencies(CKEditorPlugin plugin)
      Get the direct dependencies for a plugin.
      Parameters:
      plugin - the plugin to get dependencies for
      Returns:
      set of direct dependencies (never null, may be empty)
    • getRecommended

      public static Set<CKEditorPlugin> getRecommended(CKEditorPlugin plugin)
      Get the recommended plugins for a plugin. These are not required but enhance the functionality.
      Parameters:
      plugin - the plugin to get recommendations for
      Returns:
      set of recommended plugins (never null, may be empty)
    • hasDependencies

      public static boolean hasDependencies(CKEditorPlugin plugin)
      Check if a plugin has dependencies.
      Parameters:
      plugin - the plugin to check
      Returns:
      true if the plugin has dependencies
    • resolve

      public static Set<CKEditorPlugin> resolve(Set<CKEditorPlugin> plugins)
      Resolve all dependencies for a set of plugins. This method transitively resolves all dependencies, ensuring that if plugin A depends on B, and B depends on C, all three are included.

      Core plugins (ESSENTIALS and PARAGRAPH) are always included.

      Parameters:
      plugins - the initial set of plugins
      Returns:
      a new set containing all plugins with their dependencies resolved
    • resolve

      public static Set<CKEditorPlugin> resolve(Set<CKEditorPlugin> plugins, boolean includeCorePlugins)
      Resolve all dependencies for a set of plugins.
      Parameters:
      plugins - the initial set of plugins
      includeCorePlugins - whether to automatically include ESSENTIALS and PARAGRAPH
      Returns:
      a new set containing all plugins with their dependencies resolved
    • resolveWithRecommended

      public static Set<CKEditorPlugin> resolveWithRecommended(Set<CKEditorPlugin> plugins)
      Resolve all dependencies including recommended plugins.
      Parameters:
      plugins - the initial set of plugins
      Returns:
      a new set containing all plugins with dependencies and recommendations
    • getDependents

      public static Set<CKEditorPlugin> getDependents(CKEditorPlugin plugin)
      Get all plugins that depend on the specified plugin.
      Parameters:
      plugin - the plugin to find dependents for
      Returns:
      set of plugins that depend on the given plugin
    • checkRemovalImpact

      public static Set<CKEditorPlugin> checkRemovalImpact(CKEditorPlugin plugin, Set<CKEditorPlugin> currentPlugins)
      Check if removing a plugin would break any dependencies.
      Parameters:
      plugin - the plugin to check
      currentPlugins - the current set of plugins
      Returns:
      set of plugins that would be broken if the plugin is removed
    • validateDependencies

      public static Map<CKEditorPlugin, Set<CKEditorPlugin>> validateDependencies(Set<CKEditorPlugin> plugins)
      Validate that all dependencies are satisfied for a set of plugins.
      Parameters:
      plugins - the plugins to validate
      Returns:
      map of plugins to their missing dependencies (empty if all satisfied)
    • topologicalSort

      public static List<CKEditorPlugin> topologicalSort(Set<CKEditorPlugin> plugins)
      Get a topologically sorted list of plugins. Dependencies are listed before the plugins that depend on them.
      Parameters:
      plugins - the plugins to sort
      Returns:
      list of plugins in dependency order
    • getDependencyTree

      public static String getDependencyTree(CKEditorPlugin plugin)
      Get a human-readable dependency tree for a plugin.
      Parameters:
      plugin - the plugin to get the tree for
      Returns:
      formatted string showing the dependency tree
    • getLoadOrder

      public static List<CKEditorPlugin> getLoadOrder(Set<CKEditorPlugin> plugins)
      Get all plugins in dependency order suitable for loading. This is a convenience method that resolves and sorts plugins.
      Parameters:
      plugins - the plugins to process
      Returns:
      list of all required plugins in load order
    • getPremiumDependencies

      public static Set<CKEditorPlugin> getPremiumDependencies(String premiumPluginName)
      Get the dependencies for a premium plugin by its JS name.
      Parameters:
      premiumPluginName - the JavaScript name of the premium plugin (e.g., "ExportPdf")
      Returns:
      set of required CKEditorPlugin dependencies (never null, may be empty)
    • requiresCloudServices

      public static boolean requiresCloudServices(String premiumPluginName)
      Check if a premium plugin requires CloudServices.
      Parameters:
      premiumPluginName - the JavaScript name of the premium plugin
      Returns:
      true if the plugin requires CloudServices
    • hasPremiumDependencies

      public static boolean hasPremiumDependencies(String premiumPluginName)
      Check if a premium plugin has dependencies.
      Parameters:
      premiumPluginName - the JavaScript name of the premium plugin
      Returns:
      true if the plugin has dependencies
    • resolveWithPremium

      public static Set<CKEditorPlugin> resolveWithPremium(Set<CKEditorPlugin> plugins, Collection<CustomPlugin> customPlugins)
      Resolve all dependencies for a set of plugins, including premium plugin dependencies. This method handles both CKEditorPlugin enum members and CustomPlugin instances.
      Parameters:
      plugins - the initial set of CKEditorPlugin plugins
      customPlugins - collection of custom plugins (including premium)
      Returns:
      a new set containing all plugins with their dependencies resolved
    • resolveWithPremium

      public static Set<CKEditorPlugin> resolveWithPremium(Set<CKEditorPlugin> plugins, Collection<CustomPlugin> customPlugins, boolean includeCorePlugins)
      Resolve all dependencies for a set of plugins, including premium plugin dependencies.
      Parameters:
      plugins - the initial set of CKEditorPlugin plugins
      customPlugins - collection of custom plugins (including premium)
      includeCorePlugins - whether to automatically include ESSENTIALS and PARAGRAPH
      Returns:
      a new set containing all plugins with their dependencies resolved
    • getPremiumDependents

      public static Set<String> getPremiumDependents(CKEditorPlugin plugin, Set<String> premiumPluginNames)
      Get all premium plugins that would be affected if a base plugin is removed.
      Parameters:
      plugin - the base plugin to check
      premiumPluginNames - names of premium plugins currently in use
      Returns:
      set of premium plugin names that depend on the given plugin
    • validatePremiumDependencies

      public static Map<String, Set<CKEditorPlugin>> validatePremiumDependencies(Set<CKEditorPlugin> plugins, Collection<CustomPlugin> customPlugins)
      Validate that all premium plugin dependencies are satisfied.
      Parameters:
      plugins - the current set of CKEditorPlugin plugins
      customPlugins - collection of custom plugins to validate
      Returns:
      map of premium plugin names to their missing dependencies (empty if all satisfied)
    • getKnownPremiumPlugins

      public static Set<String> getKnownPremiumPlugins()
      Get all known premium plugin names that have dependencies defined.
      Returns:
      unmodifiable set of premium plugin names
    • getCloudServicesRequiredPlugins

      public static Set<String> getCloudServicesRequiredPlugins()
      Get all premium plugins that require CloudServices.
      Returns:
      unmodifiable set of premium plugin names requiring CloudServices