Class CmsModuleManager


  • public class CmsModuleManager
    extends java.lang.Object
    Manages the modules of an OpenCms installation.

    Since:
    6.0.0
    • Constructor Summary

      Constructors 
      Constructor Description
      CmsModuleManager​(java.util.List<CmsModule> configuredModules)
      Basic constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addModule​(CmsObject cms, CmsModule module)
      Adds a new module to the module manager.
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> buildDepsForAllModules​(java.lang.String rfsAbsPath, boolean mode)
      Returns a map of dependencies.
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> buildDepsForModulelist​(java.util.List<java.lang.String> moduleNames, java.lang.String rfsAbsPath, boolean mode)
      Returns a map of dependencies between the given modules.
      java.util.List<CmsModuleDependency> checkDependencies​(CmsModule module, int mode)
      Checks if a modules dependencies are fulfilled.
      void checkModuleSelectionList​(java.util.List<java.lang.String> moduleNames, java.lang.String rfsAbsPath, boolean forDeletion)
      Checks the module selection list for consistency, that means that if a module is selected, all its dependencies are also selected.
      void deleteModule​(CmsObject cms, java.lang.String moduleName, boolean replace, boolean preserveLibs, I_CmsReport report)
      Deletes a module from the configuration.
      void deleteModule​(CmsObject cms, java.lang.String moduleName, boolean replace, I_CmsReport report)
      Deletes a module from the configuration.
      java.util.List<CmsModule> getAllInstalledModules()
      Returns a list of installed modules.
      static java.util.Map<CmsModule,​java.lang.String> getAllModulesFromPath​(java.lang.String rfsAbsPath)
      Returns a map of modules found in the given RFS absolute path.
      java.util.Set<CmsExportPoint> getExportPoints()
      Returns the (immutable) list of configured module export points.
      CmsModuleImportExportRepository getImportExportRepository()
      Returns the importExportRepository.
      CmsModule getModule​(java.lang.String name)
      Returns the module with the given module name, or null if no module with the given name is configured.
      java.util.Set<java.lang.String> getModuleNames()
      Returns the set of names of all the installed modules.
      boolean hasModule​(java.lang.String name)
      Checks if this module manager has a module with the given name installed.
      void initialize​(CmsObject cms, CmsConfigurationManager configurationManager)
      Initializes all module instance classes managed in this module manager.
      CmsReplaceModuleInfo replaceModule​(CmsObject cms, java.lang.String importFile, I_CmsReport report)
      Replaces an existing module with the one read from an import ZIP file.
      void setModuleUpdateEnabled​(boolean enabled)
      Enables / disables incremental module updates, for testing purposes.
      void shutDown()
      Shuts down all module instance classes managed in this module manager.
      static java.util.List<java.lang.String> topologicalSort​(java.util.List<java.lang.String> moduleNames, java.lang.String rfsAbsPath)
      Sorts a given list of module names by dependencies, so that the resulting list can be imported in that given order, that means modules without dependencies first.
      void updateModule​(CmsObject cms, CmsModule module)
      Updates a already configured module with new values.
      void updateModuleConfiguration()
      Updates the module configuration.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CmsModuleManager

        public CmsModuleManager​(java.util.List<CmsModule> configuredModules)
        Basic constructor.

        Parameters:
        configuredModules - the list of configured modules
    • Method Detail

      • buildDepsForAllModules

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> buildDepsForAllModules​(java.lang.String rfsAbsPath,
                                                                                                                    boolean mode)
                                                                                                             throws CmsConfigurationException
        Returns a map of dependencies.

        The module dependencies are get from the installed modules or from the module manifest.xml files found in the given FRS path.

        Two types of dependency lists can be generated:

        • Forward dependency lists: a list of modules that depends on a module
        • Backward dependency lists: a list of modules that a module depends on
        Parameters:
        rfsAbsPath - a RFS absolute path to search for modules, or null to use the installed modules
        mode - if true a list of forward dependency is build, is not a list of backward dependency
        Returns:
        a Map of module names as keys and a list of dependency names as values
        Throws:
        CmsConfigurationException - if something goes wrong
      • buildDepsForModulelist

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> buildDepsForModulelist​(java.util.List<java.lang.String> moduleNames,
                                                                                                                    java.lang.String rfsAbsPath,
                                                                                                                    boolean mode)
                                                                                                             throws CmsConfigurationException
        Returns a map of dependencies between the given modules.

        The module dependencies are get from the installed modules or from the module manifest.xml files found in the given FRS path.

        Two types of dependency lists can be generated:

        • Forward dependency lists: a list of modules that depends on a module
        • Backward dependency lists: a list of modules that a module depends on
        Parameters:
        moduleNames - a list of module names
        rfsAbsPath - a RFS absolute path to search for modules, or null to use the installed modules
        mode - if true a list of forward dependency is build, is not a list of backward dependency
        Returns:
        a Map of module names as keys and a list of dependency names as values
        Throws:
        CmsConfigurationException - if something goes wrong
      • topologicalSort

        public static java.util.List<java.lang.String> topologicalSort​(java.util.List<java.lang.String> moduleNames,
                                                                       java.lang.String rfsAbsPath)
                                                                throws CmsConfigurationException
        Sorts a given list of module names by dependencies, so that the resulting list can be imported in that given order, that means modules without dependencies first.

        The module dependencies are get from the installed modules or from the module manifest.xml files found in the given FRS path.

        Parameters:
        moduleNames - a list of module names
        rfsAbsPath - a RFS absolute path to search for modules, or null to use the installed modules
        Returns:
        a sorted list of module names
        Throws:
        CmsConfigurationException - if something goes wrong
      • checkDependencies

        public java.util.List<CmsModuleDependencycheckDependencies​(CmsModule module,
                                                                     int mode)
        Checks if a modules dependencies are fulfilled.

        The possible values for the mode parameter are:

        DEPENDENCY_MODE_DELETE
        Check for module deleting, i.e. are other modules dependent on the given module?
        DEPENDENCY_MODE_IMPORT
        Check for module importing, i.e. are all dependencies required by the given module available?
        Parameters:
        module - the module to check the dependencies for
        mode - the dependency check mode
        Returns:
        a list of dependencies that are not fulfilled, if empty all dependencies are fulfilled
      • checkModuleSelectionList

        public void checkModuleSelectionList​(java.util.List<java.lang.String> moduleNames,
                                             java.lang.String rfsAbsPath,
                                             boolean forDeletion)
                                      throws CmsIllegalArgumentException,
                                             CmsConfigurationException
        Checks the module selection list for consistency, that means that if a module is selected, all its dependencies are also selected.

        The module dependencies are get from the installed modules or from the module manifest.xml files found in the given FRS path.

        Parameters:
        moduleNames - a list of module names
        rfsAbsPath - a RFS absolute path to search for modules, or null to use the installed modules
        forDeletion - there are two modes, one for installation of modules, and one for deletion.
        Throws:
        CmsIllegalArgumentException - if the module list is not consistent
        CmsConfigurationException - if something goes wrong
      • deleteModule

        public void deleteModule​(CmsObject cms,
                                 java.lang.String moduleName,
                                 boolean replace,
                                 boolean preserveLibs,
                                 I_CmsReport report)
                          throws CmsRoleViolationException,
                                 CmsConfigurationException,
                                 CmsLockException
        Deletes a module from the configuration.

        Parameters:
        cms - must be initialized with "Admin" permissions
        moduleName - the name of the module to delete
        replace - indicates if the module is replaced (true) or finally deleted (false)
        preserveLibs - true to keep any exported file exported into the WEB-INF lib folder
        report - the report to print progress messages to
        Throws:
        CmsRoleViolationException - if the required module manager role permissions are not available
        CmsConfigurationException - if a module with this name is not available for deleting
        CmsLockException - if the module resources can not be locked
      • getExportPoints

        public java.util.Set<CmsExportPointgetExportPoints()
        Returns the (immutable) list of configured module export points.

        Returns:
        the (immutable) list of configured module export points
        See Also:
        CmsExportPoint
      • getModule

        public CmsModule getModule​(java.lang.String name)
        Returns the module with the given module name, or null if no module with the given name is configured.

        Parameters:
        name - the name of the module to return
        Returns:
        the module with the given module name
      • getModuleNames

        public java.util.Set<java.lang.String> getModuleNames()
        Returns the set of names of all the installed modules.

        Returns:
        the set of names of all the installed modules
      • hasModule

        public boolean hasModule​(java.lang.String name)
        Checks if this module manager has a module with the given name installed.

        Parameters:
        name - the name of the module to check
        Returns:
        true if this module manager has a module with the given name installed
      • initialize

        public void initialize​(CmsObject cms,
                               CmsConfigurationManager configurationManager)
                        throws CmsRoleViolationException
        Initializes all module instance classes managed in this module manager.

        Parameters:
        cms - an initialized CmsObject with "manage modules" role permissions
        configurationManager - the initialized OpenCms configuration manager
        Throws:
        CmsRoleViolationException - if the provided OpenCms context does not have "manage modules" role permissions
      • replaceModule

        public CmsReplaceModuleInfo replaceModule​(CmsObject cms,
                                                  java.lang.String importFile,
                                                  I_CmsReport report)
                                           throws CmsException
        Replaces an existing module with the one read from an import ZIP file.

        If there is not already a module with the same name installed, then the module will just be imported normally.

        Parameters:
        cms - the CMS context
        importFile - the import file
        report - the report
        Returns:
        the module replacement status
        Throws:
        CmsException - if something goes wrong
      • setModuleUpdateEnabled

        public void setModuleUpdateEnabled​(boolean enabled)
        Enables / disables incremental module updates, for testing purposes.
        Parameters:
        enabled - if incremental module updating should be enabled
      • shutDown

        public void shutDown()
        Shuts down all module instance classes managed in this module manager.