Package com.ultikits.ultitools.manager
Class PluginDependencyResolver
java.lang.Object
com.ultikits.ultitools.manager.PluginDependencyResolver
Plugin dependency resolver using Kahn's algorithm for topological sorting.
Ensures plugins are loaded in the correct order based on their dependencies.
使用 Kahn 算法进行拓扑排序的插件依赖解析器。 确保插件根据其依赖关系以正确的顺序加载。
- Since:
- 6.2.0
- Author:
- wisdomme
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when circular dependencies are detected.static classException thrown when required dependencies are missing.static classRepresents a dependency graph node containing plugin class and its dependencies. -
Constructor Summary
ConstructorsConstructorDescriptionPluginDependencyResolver(Logger logger) Constructs a new PluginDependencyResolver. -
Method Summary
Modifier and TypeMethodDescriptionbuildAdjacencyList(Map<String, PluginDependencyResolver.PluginNode> nodes, Set<String> availablePlugins) Builds the adjacency list for the dependency graph.calculateInDegrees(Map<String, PluginDependencyResolver.PluginNode> nodes, Map<String, Set<String>> adjacencyList) Calculates in-degrees for all nodes.Performs Kahn's algorithm for topological sorting.List<Class<? extends UltiToolsPlugin>> resolve(List<Class<? extends UltiToolsPlugin>> pluginClasses) Resolves plugin load order using Kahn's algorithm for topological sorting.private voidvalidateHardDependencies(Map<String, PluginDependencyResolver.PluginNode> nodes, Set<String> availablePlugins) Validates that all hard dependencies exist.
-
Constructor Details
-
PluginDependencyResolver
Constructs a new PluginDependencyResolver.- Parameters:
logger- the logger to use for warnings and errors (reserved for future use)
-
-
Method Details
-
resolve
public List<Class<? extends UltiToolsPlugin>> resolve(List<Class<? extends UltiToolsPlugin>> pluginClasses) throws PluginDependencyResolver.CircularDependencyException, PluginDependencyResolver.MissingDependencyException Resolves plugin load order using Kahn's algorithm for topological sorting.使用 Kahn 算法解析插件加载顺序。
- Parameters:
pluginClasses- the list of plugin classes to sort- Returns:
- sorted list of plugin classes, or null if circular dependency detected
- Throws:
PluginDependencyResolver.CircularDependencyException- if circular dependencies are detectedPluginDependencyResolver.MissingDependencyException- if required dependencies are missing
-
validateHardDependencies
private void validateHardDependencies(Map<String, PluginDependencyResolver.PluginNode> nodes, Set<String> availablePlugins) throws PluginDependencyResolver.MissingDependencyExceptionValidates that all hard dependencies exist. -
buildAdjacencyList
private Map<String,Set<String>> buildAdjacencyList(Map<String, PluginDependencyResolver.PluginNode> nodes, Set<String> availablePlugins) Builds the adjacency list for the dependency graph. An edge from A to B means B depends on A (so A must load before B). -
calculateInDegrees
private Map<String,Integer> calculateInDegrees(Map<String, PluginDependencyResolver.PluginNode> nodes, Map<String, Set<String>> adjacencyList) Calculates in-degrees for all nodes. -
kahnSort
private List<String> kahnSort(Set<String> nodes, Map<String, Set<String>> adjacencyList, Map<String, Integer> inDegree) Performs Kahn's algorithm for topological sorting.
-