Class ModuleDependencyUtil

java.lang.Object
eu.cloudnetservice.driver.impl.module.ModuleDependencyUtil

public final class ModuleDependencyUtil extends Object
Utility to find dependencies of a module, ensure that they are loaded and that there is no circular dependency.
Since:
4.0
See Also:
  • ModuleDependency
  • ModuleWrapper
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final Pattern
    A regex to match semver versions.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Creating an instance of this helper class is not allowed, results in UnsupportedOperationException.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static @NonNull eu.cloudnetservice.driver.module.ModuleWrapper
    associatedModuleWrapper(@NonNull eu.cloudnetservice.driver.module.ModuleDependency dependency, @NonNull eu.cloudnetservice.driver.module.ModuleProvider provider, @NonNull eu.cloudnetservice.driver.module.ModuleWrapper dependencyHolder)
    Gets the associated module wrapper to a module dependency or throws an exception if the wrapper is not present.
    private static void
    checkDependencyVersion(@NonNull eu.cloudnetservice.driver.module.ModuleWrapper requiringModule, @NonNull eu.cloudnetservice.driver.module.ModuleDependency dependency, @NonNull Matcher dependencyVersion, @NonNull Matcher moduleVersion)
    Validates that the dependency of the module is compatible with the actual running module.
    static @NonNull Set<eu.cloudnetservice.driver.module.ModuleWrapper>
    collectDependencies(@NonNull eu.cloudnetservice.driver.module.ModuleWrapper caller, @NonNull eu.cloudnetservice.driver.module.ModuleProvider moduleProvider)
    Collects all first-level module dependencies of a module.
    private static void
    visitDependencies(@NonNull Deque<eu.cloudnetservice.driver.module.ModuleWrapper> visitedNodes, @NonNull Collection<eu.cloudnetservice.driver.module.ModuleDependency> dependencies, @NonNull eu.cloudnetservice.driver.module.ModuleWrapper originalSource, @NonNull eu.cloudnetservice.driver.module.ModuleWrapper dependencyHolder, @NonNull eu.cloudnetservice.driver.module.ModuleProvider moduleProvider)
    Visits all dependencies of a module and ensures that there is no circular dependency to the root calling module.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SEMVER_PATTERN

      private static final Pattern SEMVER_PATTERN
      A regex to match semver versions. See here for testing.
  • Constructor Details

  • Method Details

    • collectDependencies

      @NonNull public static @NonNull Set<eu.cloudnetservice.driver.module.ModuleWrapper> collectDependencies(@NonNull @NonNull eu.cloudnetservice.driver.module.ModuleWrapper caller, @NonNull @NonNull eu.cloudnetservice.driver.module.ModuleProvider moduleProvider)
      Collects all first-level module dependencies of a module.
      Parameters:
      caller - the module that needs its dependencies collected.
      moduleProvider - the provider which loaded the calling module.
      Returns:
      a set of all dependencies which need to be enabled before the caller can be enabled.
      Throws:
      eu.cloudnetservice.driver.module.ModuleDependencyNotFoundException - if a module dependency is missing.
      eu.cloudnetservice.driver.module.ModuleDependencyOutdatedException - if the running module can not provide the minimum required version.
      NullPointerException - if caller or moduleProvider is null.
    • visitDependencies

      private static void visitDependencies(@NonNull @NonNull Deque<eu.cloudnetservice.driver.module.ModuleWrapper> visitedNodes, @NonNull @NonNull Collection<eu.cloudnetservice.driver.module.ModuleDependency> dependencies, @NonNull @NonNull eu.cloudnetservice.driver.module.ModuleWrapper originalSource, @NonNull @NonNull eu.cloudnetservice.driver.module.ModuleWrapper dependencyHolder, @NonNull @NonNull eu.cloudnetservice.driver.module.ModuleProvider moduleProvider)
      Visits all dependencies of a module and ensures that there is no circular dependency to the root calling module.
      Parameters:
      visitedNodes - all yet visited modules.
      dependencies - all dependencies to check.
      originalSource - the original caller which requested the check-
      dependencyHolder - the module of which the dependencies are checked currently.
      moduleProvider - the module provider which originally loaded the dependencies.
      Throws:
      eu.cloudnetservice.driver.module.ModuleDependencyNotFoundException - if a module dependency is missing.
      eu.cloudnetservice.driver.module.ModuleDependencyOutdatedException - if the running module can not provide the minimum required version.
      NullPointerException - if visitedNodes, dependencies, originalSource, dependencyHolder or moduleProvider is null.
    • associatedModuleWrapper

      @NonNull private static @NonNull eu.cloudnetservice.driver.module.ModuleWrapper associatedModuleWrapper(@NonNull @NonNull eu.cloudnetservice.driver.module.ModuleDependency dependency, @NonNull @NonNull eu.cloudnetservice.driver.module.ModuleProvider provider, @NonNull @NonNull eu.cloudnetservice.driver.module.ModuleWrapper dependencyHolder)
      Gets the associated module wrapper to a module dependency or throws an exception if the wrapper is not present.
      Parameters:
      dependency - the dependency to get the associated wrapper with.
      provider - the module provider from which the requesting module came.
      dependencyHolder - the holder which needs the dependency to be present.
      Returns:
      the associated module wrapper with the given module dependency.
      Throws:
      eu.cloudnetservice.driver.module.ModuleDependencyNotFoundException - if a module dependency is missing.
      eu.cloudnetservice.driver.module.ModuleDependencyOutdatedException - if the running module can not provide the minimum required version.
      NullPointerException - if dependency, provider or dependencyHolder is null.
    • checkDependencyVersion

      private static void checkDependencyVersion(@NonNull @NonNull eu.cloudnetservice.driver.module.ModuleWrapper requiringModule, @NonNull @NonNull eu.cloudnetservice.driver.module.ModuleDependency dependency, @NonNull @NonNull Matcher dependencyVersion, @NonNull @NonNull Matcher moduleVersion)
      Validates that the dependency of the module is compatible with the actual running module. This only checks for the major and minor version of the module as a patch version should only patch bugs not add new features nor contain breaking changes.
      Parameters:
      requiringModule - the module which holds the dependency.
      dependency - the dependency which gets checked.
      dependencyVersion - a matcher for the semver versioning of the dependency.
      moduleVersion - a matcher for the semver versioning of the running module.
      Throws:
      eu.cloudnetservice.driver.module.ModuleDependencyOutdatedException - if the running module can not provide the minimum required version.
      NullPointerException - if requiringModule, dependency, dependencyVersion or moduleVersion is null.