Browse Source

Add more javadoc, fix warnings

tags/release-3.11.0
Decebal Suiu 3 months ago
parent
commit
d351e52ab4
1 changed files with 33 additions and 13 deletions
  1. 33
    13
      pf4j/src/main/java/org/pf4j/DependencyResolver.java

+ 33
- 13
pf4j/src/main/java/org/pf4j/DependencyResolver.java View File

* The {@code Result} class contains nice information about the result of resolve operation (if it's a cyclic dependency, * The {@code Result} 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). * they are not found dependencies, they are dependencies with wrong version).
* This class is very useful for if-else scenarios. * This class is very useful for if-else scenarios.
*
* <p>
* Only some attributes (pluginId, dependencies and pluginVersion) from {@link PluginDescriptor} are used in * Only some attributes (pluginId, dependencies and pluginVersion) from {@link PluginDescriptor} are used in
* the process of {@code resolve} operation. * the process of {@code resolve} operation.
* *


private static final Logger log = LoggerFactory.getLogger(DependencyResolver.class); private static final Logger log = LoggerFactory.getLogger(DependencyResolver.class);


private VersionManager versionManager;
private final VersionManager versionManager;


private DirectedGraph<String> dependenciesGraph; // the value is 'pluginId' private DirectedGraph<String> dependenciesGraph; // the value is 'pluginId'
private DirectedGraph<String> dependentsGraph; // the value is 'pluginId' private DirectedGraph<String> dependentsGraph; // the value is 'pluginId'
this.versionManager = versionManager; this.versionManager = versionManager;
} }


/**
* Resolve the dependencies for the given plugins.
*
* @param plugins the list of plugins
* @return a {@link Result} object
*/
public Result resolve(List<PluginDescriptor> plugins) { public Result resolve(List<PluginDescriptor> plugins) {
// create graphs // create graphs
dependenciesGraph = new DirectedGraph<>(); dependenciesGraph = new DirectedGraph<>();
/** /**
* Check if an existing version of dependency is compatible with the required version (from plugin descriptor). * Check if an existing version of dependency is compatible with the required version (from plugin descriptor).
* *
* @param requiredVersion
* @param existingVersion
* @return
* @param requiredVersion the required version
* @param existingVersion the existing version
* @return {@code true} if the existing version is compatible with the required version, {@code false} otherwise
*/ */
protected boolean checkDependencyVersion(String requiredVersion, String existingVersion) { protected boolean checkDependencyVersion(String requiredVersion, String existingVersion) {
return versionManager.checkVersionConstraint(existingVersion, requiredVersion); return versionManager.checkVersionConstraint(existingVersion, requiredVersion);
"' for plugin '" + dependent.getPluginId() + "'"); "' for plugin '" + dependent.getPluginId() + "'");
} }


/**
* The result of the {@link #resolve(List)} operation.
*/
public static class Result { public static class Result {


private boolean cyclicDependency; private boolean cyclicDependency;
private List<String> notFoundDependencies; // value is "pluginId"
private List<String> sortedPlugins; // value is "pluginId"
private List<WrongDependencyVersion> wrongVersionDependencies;
private final List<String> notFoundDependencies; // value is "pluginId"
private final List<String> sortedPlugins; // value is "pluginId"
private final List<WrongDependencyVersion> wrongVersionDependencies;


Result(List<String> sortedPlugins) { Result(List<String> sortedPlugins) {
if (sortedPlugins == null) { if (sortedPlugins == null) {


/** /**
* Returns true is a cyclic dependency was detected. * Returns true is a cyclic dependency was detected.
*
* @return true is a cyclic dependency was detected
*/ */
public boolean hasCyclicDependency() { public boolean hasCyclicDependency() {
return cyclicDependency; return cyclicDependency;


/** /**
* Returns a list with dependencies required that were not found. * Returns a list with dependencies required that were not found.
*
* @return a list with dependencies required that were not found
*/ */
public List<String> getNotFoundDependencies() { public List<String> getNotFoundDependencies() {
return notFoundDependencies; return notFoundDependencies;


/** /**
* Returns a list with dependencies with wrong version. * Returns a list with dependencies with wrong version.
*
* @return a list with dependencies with wrong version
*/ */
public List<WrongDependencyVersion> getWrongVersionDependencies() { public List<WrongDependencyVersion> getWrongVersionDependencies() {
return wrongVersionDependencies; return wrongVersionDependencies;


/** /**
* Get the list of plugins in dependency sorted order. * Get the list of plugins in dependency sorted order.
*
* @return the list of plugins in dependency sorted order
*/ */
public List<String> getSortedPlugins() { public List<String> getSortedPlugins() {
return sortedPlugins; return sortedPlugins;


} }


/**
* Represents a wrong dependency version.
*/
public static class WrongDependencyVersion { public static class WrongDependencyVersion {


private String dependencyId; // value is "pluginId"
private String dependentId; // value is "pluginId"
private String existingVersion;
private String requiredVersion;
private final String dependencyId; // value is "pluginId"
private final String dependentId; // value is "pluginId"
private final String existingVersion;
private final String requiredVersion;


WrongDependencyVersion(String dependencyId, String dependentId, String existingVersion, String requiredVersion) { WrongDependencyVersion(String dependencyId, String dependentId, String existingVersion, String requiredVersion) {
this.dependencyId = dependencyId; this.dependencyId = dependencyId;
*/ */
public static class DependenciesNotFoundException extends PluginRuntimeException { public static class DependenciesNotFoundException extends PluginRuntimeException {


private List<String> dependencies;
private final List<String> dependencies;


public DependenciesNotFoundException(List<String> dependencies) { public DependenciesNotFoundException(List<String> dependencies) {
super("Dependencies '{}' not found", dependencies); super("Dependencies '{}' not found", dependencies);

Loading…
Cancel
Save