Package org.pf4j
Class DependencyResolver
- java.lang.Object
-
- org.pf4j.DependencyResolver
-
public class DependencyResolver extends java.lang.ObjectThis class builds a dependency graph for a list of plugins (descriptors). The entry point is theresolve(List)method, method that returns aDependencyResolver.Resultobject. TheResultclass contains nice information about the result of resolve operation (if it's a cyclic dependency, they are not found dependencies, they are dependencies with wrong version). This class is very useful for if-else scenarios. Only some attributes (pluginId, dependencies and pluginVersion) fromPluginDescriptorare used in the process ofresolveoperation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDependencyResolver.CyclicDependencyExceptionIt will be thrown if a cyclic dependency is detected.static classDependencyResolver.DependenciesNotFoundExceptionIndicates that the dependencies required were not found.static classDependencyResolver.DependenciesWrongVersionExceptionIndicates that some dependencies have wrong version.static classDependencyResolver.Resultstatic classDependencyResolver.WrongDependencyVersion
-
Field Summary
Fields Modifier and Type Field Description private DirectedGraph<java.lang.String>dependenciesGraphprivate DirectedGraph<java.lang.String>dependentsGraphprivate static org.slf4j.Loggerlogprivate booleanresolvedprivate VersionManagerversionManager
-
Constructor Summary
Constructors Constructor Description DependencyResolver(VersionManager versionManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddPlugin(PluginDescriptor descriptor)protected booleancheckDependencyVersion(java.lang.String requiredVersion, java.lang.String existingVersion)Check if an existing version of dependency is compatible with the required version (from plugin descriptor).private voidcheckResolved()java.util.List<java.lang.String>getDependencies(java.lang.String pluginId)Retrieves the plugins ids that the given plugin id directly depends on.private java.lang.StringgetDependencyVersionSupport(PluginDescriptor dependent, java.lang.String dependencyId)java.util.List<java.lang.String>getDependents(java.lang.String pluginId)Retrieves the plugins ids that the given content is a direct dependency of.DependencyResolver.Resultresolve(java.util.List<PluginDescriptor> plugins)
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
versionManager
private VersionManager versionManager
-
dependenciesGraph
private DirectedGraph<java.lang.String> dependenciesGraph
-
dependentsGraph
private DirectedGraph<java.lang.String> dependentsGraph
-
resolved
private boolean resolved
-
-
Constructor Detail
-
DependencyResolver
public DependencyResolver(VersionManager versionManager)
-
-
Method Detail
-
resolve
public DependencyResolver.Result resolve(java.util.List<PluginDescriptor> plugins)
-
getDependencies
public java.util.List<java.lang.String> getDependencies(java.lang.String pluginId)
Retrieves the plugins ids that the given plugin id directly depends on.- Parameters:
pluginId- the unique plugin identifier, specified in its metadata- Returns:
-
getDependents
public java.util.List<java.lang.String> getDependents(java.lang.String pluginId)
Retrieves the plugins ids that the given content is a direct dependency of.- Parameters:
pluginId- the unique plugin identifier, specified in its metadata- Returns:
-
checkDependencyVersion
protected boolean checkDependencyVersion(java.lang.String requiredVersion, java.lang.String existingVersion)Check if an existing version of dependency is compatible with the required version (from plugin descriptor).- Parameters:
requiredVersion-existingVersion-- Returns:
-
addPlugin
private void addPlugin(PluginDescriptor descriptor)
-
checkResolved
private void checkResolved()
-
getDependencyVersionSupport
private java.lang.String getDependencyVersionSupport(PluginDescriptor dependent, java.lang.String dependencyId)
-
-