Package org.pf4j
Class DependencyResolver
- java.lang.Object
-
- org.pf4j.DependencyResolver
-
public class DependencyResolver extends java.lang.Object
This class builds a dependency graph for a list of plugins (descriptors). The entry point is theresolve(List)
method, method that returns aDependencyResolver.Result
object. TheResult
class 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) fromPluginDescriptor
are used in the process ofresolve
operation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DependencyResolver.CyclicDependencyException
It will be thrown if a cyclic dependency is detected.static class
DependencyResolver.DependenciesNotFoundException
Indicates that the dependencies required were not found.static class
DependencyResolver.DependenciesWrongVersionException
Indicates that some dependencies have wrong version.static class
DependencyResolver.Result
static class
DependencyResolver.WrongDependencyVersion
-
Field Summary
Fields Modifier and Type Field Description private DirectedGraph<java.lang.String>
dependenciesGraph
private DirectedGraph<java.lang.String>
dependentsGraph
private static org.slf4j.Logger
log
private boolean
resolved
private VersionManager
versionManager
-
Constructor Summary
Constructors Constructor Description DependencyResolver(VersionManager versionManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addPlugin(PluginDescriptor descriptor)
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).private void
checkResolved()
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.String
getDependencyVersionSupport(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.Result
resolve(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)
-
-