public final class GrailsPluginSorter extends java.lang.Object
Canonical topological sort for Grails plugins based on loadAfter
and loadBefore declarations.
This class provides the single shared implementation of plugin ordering that
is used by both DefaultGrailsPluginManager (at runtime, operating on
GrailsPlugin instances) and
GrailsEnvironmentPostProcessor (early in the
lifecycle, operating on lightweight PluginInfo records before the
ApplicationContext is available).
The algorithm is a DFS-based topological sort:
loadAfter creates edges from a plugin to its
dependencies (the plugin must load after the named plugins).loadBefore creates reverse edges (the named plugin must
load after this plugin).Note: dependsOn is intentionally not used
for ordering. In the original DefaultGrailsPluginManager, dependsOn
is only used for dependency resolution (checking that required plugins
are present), not for determining load order. Load order is controlled exclusively
by loadAfter and loadBefore.
The sort is generic: callers provide accessor functions so the same algorithm works with any plugin representation (full GrailsPlugin objects, lightweight metadata records, etc.).
| Type Params | Return Type | Name and description |
|---|---|---|
<T> |
public static java.util.List<T> |
sort(java.util.List<T> plugins, java.util.function.Function<T, java.lang.String> nameExtractor, java.util.function.Function<T, java.lang.String> loadAfterExtractor, java.util.function.Function<T, java.lang.String> loadBeforeExtractor)Overload that builds the lookup function from the plugin list itself. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Overload that builds the lookup function from the plugin list itself.
This is convenient when there is no external registry (e.g., in the
EnvironmentPostProcessor where plugins are represented as lightweight
records rather than managed by a plugin manager).
T - the plugin typeplugins - the plugins to sortnameExtractor - extracts the logical plugin name from a pluginloadAfterExtractor - extracts the loadAfter namesloadBeforeExtractor - extracts the loadBefore names