Class ModulesService


  • @OpenApiAll
    public class ModulesService
    extends java.lang.Object
    An utility class to work with modules (attached projects). This class provides set of utility methods to change decomposition state of project - attach, detach, load, unload or changed attachment properties of modules.
    • Constructor Detail

      • ModulesService

        public ModulesService()
    • Method Detail

      • attachModule

        @CheckForNull
        public static IAttachedProject attachModule​(IProject owner,
                                                    AbstractProjectAttachmentConfiguration configuration,
                                                    @CheckForNull
                                                    org.eclipse.core.runtime.IProgressMonitor monitor)
                                             throws com.nomagic.ci.persistence.PersistenceException
        Mounts module into current project. Default mount path is used.
        Parameters:
        owner - owner to attach module to
        configuration - configuration
        monitor - progress status
        Returns:
        module descriptor
        Throws:
        com.nomagic.ci.persistence.PersistenceException - in case of persistence problems
      • reMount

        public static void reMount​(IProject owner,
                                   IAttachedProject module,
                                   java.util.Collection<MountedPackageInfo> mountedPackagesInfo,
                                   org.eclipse.core.runtime.IProgressMonitor monitor)
        Re-mount given module on different mount points.
        Parameters:
        owner - module owner
        module - module to remount
        mountedPackagesInfo - new information about mount points
        monitor - progress monitor
      • reMountOnTask

        public static void reMountOnTask​(IProject owner,
                                         IAttachedProject module,
                                         java.util.Collection<MountedPackageInfo> mountedPackagesInfo)
        Change mount point location
        Parameters:
        owner - project
        module - module
        mountedPackagesInfo - new mounting information
      • detachModules

        public static boolean detachModules​(java.util.Collection<ModuleUsage> usages,
                                            @CheckForNull
                                            org.eclipse.core.runtime.IProgressMonitor monitor)
                                     throws java.lang.Exception
        Removes all given modules usages. If module is used more than one time only remove usage, in other case module data will be disposed.
        Parameters:
        usages - modules to remove
        monitor - monitor
        Returns:
        true if all modules were detached, false if user cancelled operation
        Throws:
        java.lang.Exception - if detach fails.
      • detachModulesAndRemoveUnreachable

        public static boolean detachModulesAndRemoveUnreachable​(java.util.Collection<ModuleUsage> usages,
                                                                org.eclipse.core.runtime.IProgressMonitor monitor)
                                                         throws java.lang.Exception
        Removes all given module usages. If new modules become manually unreachable during the operation - they will be removed too if possible
        Parameters:
        usages - the usages to remove
        monitor - the progress monitor for the operation
        Returns:
        true if all modules were detached, false if user cancelled operation
        Throws:
        java.lang.Exception
      • detachModulesAndRemoveUnreachable

        public static boolean detachModulesAndRemoveUnreachable​(java.util.Collection<ModuleUsage> usages,
                                                                @CheckForNull
                                                                IAttachedProjectRemoverCallback removeConfirmation,
                                                                org.eclipse.core.runtime.IProgressMonitor monitor)
                                                         throws java.lang.Exception
        Removes all given module usages. If new modules become manually unreachable during the operation - they will be removed too if possible
        Parameters:
        usages - the usages to remove
        removeConfirmation - remove confirmation
        monitor - the progress monitor for the operation
        Returns:
        true if all modules were detached, false if user cancelled operation
        Throws:
        java.lang.Exception
      • detachModulesAndRemoveUnreachableOnTask

        public static boolean detachModulesAndRemoveUnreachableOnTask​(java.util.Collection<ModuleUsage> usages)
        Removes all given module usages. If new modules become manually unreachable during the operation - they will be removed too if possible
        Parameters:
        usages - the usages to remove
        Returns:
        true if all modules were detached, false if user cancelled operation
      • detachModulesOnTask

        public static boolean detachModulesOnTask​(java.util.Collection<ModuleUsage> usages)
        Removes all given modules usages. If module is used more than one time only remove usage, in other case module data will be disposed.
        Parameters:
        usages - module usages to remove
        Returns:
        true if all modules were detached, false if user cancelled operation
      • doDetachModulesOnTask

        private static boolean doDetachModulesOnTask​(java.util.Collection<ModuleUsage> usages,
                                                     boolean removeNewUnreachableModules)
      • getModuleNameList

        private static java.lang.String getModuleNameList​(java.util.Set<IAttachedProject> selectedModules)
      • removeModulesOnTask

        public static void removeModulesOnTask​(java.util.Set<IAttachedProject> selectedModules,
                                               @CheckForNull
                                               IAttachedProjectRemoverCallback removeConfirmation)
        Removes the selected modules on task
        Parameters:
        selectedModules - the modules to remove
        removeConfirmation - the confirmation call back that will be used to confirm the remove
      • checkNotUsedViaAutoReadOnlyUsages

        private static void checkNotUsedViaAutoReadOnlyUsages​(java.util.Set<IAttachedProject> selectedModules,
                                                              IPrimaryProject primary,
                                                              com.nomagic.ci.persistence.local.decomposition.ProjectStructureEditorSimulator.SimulationEnvironment simulation)
                                                       throws ModulesService.UsedViaReadOnlyAutomaticUsageException
        Simulates removal of all read-only auto-usages. If it turns out that any of selected modules is removed from project graph due to removal of such usage, then it means that the module can not be removed
        Parameters:
        selectedModules - the modules to remove
        primary - the primary project
        simulation - the simulation environment
        Throws:
        ModulesService.UsedViaReadOnlyAutomaticUsageException
      • importModule

        public static void importModule​(IProject owner,
                                        IAttachedProject module,
                                        @CheckForNull
                                        org.eclipse.core.runtime.IProgressMonitor monitor)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • importModule

        public static void importModule​(IProject owner,
                                        IAttachedProject module,
                                        @CheckForNull
                                        org.eclipse.core.runtime.IProgressMonitor monitor,
                                        boolean regenerateElementIDs)
                                 throws java.lang.Exception
        Removes module descriptor and makes all its contents as it is local project content.
        Parameters:
        owner - module owner
        module - to import
        monitor - progress status
        regenerateElementIDs - if true module element id will be generated
        Throws:
        java.lang.Exception - exception is something goes wrong
      • importModuleWithComplexEventFire

        private static void importModuleWithComplexEventFire​(IProject owner,
                                                             IAttachedProject module,
                                                             @CheckForNull
                                                             org.eclipse.core.runtime.IProgressMonitor monitor,
                                                             boolean regenerateElementIDs,
                                                             java.util.concurrent.Callable<java.lang.Boolean> prepare,
                                                             @CheckForNull
                                                             java.util.Map<java.lang.String,​java.lang.Object> importOptions)
                                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • importModule

        private static void importModule​(IProject owner,
                                         IAttachedProject module,
                                         @CheckForNull
                                         org.eclipse.core.runtime.IProgressMonitor monitor,
                                         boolean regenerateElementIDs,
                                         java.util.concurrent.Callable<java.lang.Boolean> prepare,
                                         @CheckForNull
                                         java.util.Map<java.lang.String,​java.lang.Object> importOptions)
                                  throws java.lang.Exception
        Removes module descriptor and makes all its contents as it is local project content.
        Parameters:
        owner - module owner
        module - to import
        monitor - progress status
        regenerateElementIDs - if true module element id will be generated
        prepare - callable to execute before actual import. If returns false import is aborted.
        importOptions - implementation dependent import options
        Throws:
        java.lang.Exception - exception is something goes wrong
      • getMountPoint

        @CheckForNull
        public static com.nomagic.ci.persistence.mounting.IMountPoint getMountPoint​(java.util.Collection<com.nomagic.ci.persistence.mounting.IMountPoint> points,
                                                                                    Package element)
        Find mount point in a given collection which mounts a given package.
        Parameters:
        points - mount points
        element - package
        Returns:
        found mount point
      • checkPrecondition

        private static void checkPrecondition​(Project project,
                                              java.util.Collection<Element> roots,
                                              IAttachedProject importThis,
                                              java.util.function.BiFunction<Project,​IAttachedProject,​java.util.List<java.util.function.Predicate<Element>>> acceptanceFunction,
                                              boolean regenerateElementIDs)
                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createAcceptConditions

        private static java.util.List<java.util.function.Predicate<Element>> createAcceptConditions​(Project project,
                                                                                                    IAttachedProject importThis)
      • getPrimaryModel

        @CheckForNull
        private static Model getPrimaryModel​(IProject project)
      • importModuleOnTask

        public static void importModuleOnTask​(IProject owner,
                                              IAttachedProject module)
        Removes module descriptor and makes all its contents as it is local project content.
        Parameters:
        owner - module owner
        module - to import
      • importModuleOnTask

        public static void importModuleOnTask​(Project project,
                                              IProject owner,
                                              IAttachedProject module,
                                              boolean newIDs,
                                              boolean ignoreDirty,
                                              boolean checkModulePassword,
                                              @CheckForNull
                                              java.util.Map<java.lang.String,​java.lang.Object> importOptions,
                                              @CheckForNull
                                              ProgressStatus progress)
                                       throws java.lang.Exception
        Imports given module into given project using given configuration
        Parameters:
        project - the context project
        owner - the project to import to
        module - the module to import
        newIDs - true if element IDs should be changed
        ignoreDirty - true if project dirty state should be ignored
        checkModulePassword - true if module password should be checked, false if not
        importOptions - import implementation dependent options (passed to IProjectJoiningService.join(IAttachedProject, com.nomagic.ci.persistence.local.decomposition.IProjectJoiningFeatureProvider, Map, IProgressMonitor))
        progress - the progress to use (optional, will report to a separate progress if not provided)
        Throws:
        java.lang.Exception
      • updateTitles

        private static void updateTitles​(Project project)
      • executeWithProgress

        private static void executeWithProgress​(Task task,
                                                @CheckForNull
                                                ProgressStatus progress)
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • isLocal

        private static boolean isLocal​(IProject project)
      • processException

        public static boolean processException​(Project prj,
                                               java.lang.Exception e,
                                               java.lang.String failedOperationMessage)
      • handleFailedLocks

        private static boolean handleFailedLocks​(java.lang.String failedOperationMessage,
                                                 java.util.Collection<?> failedLocks)
      • handleDiagramNotLoadedException

        private static boolean handleDiagramNotLoadedException​(java.lang.String failedOperationMessage,
                                                               com.nomagic.magicdraw.uml.symbols.DiagramNotLoadedException diagramNotLoadedException)
      • objectToText

        private static java.lang.String objectToText​(java.lang.Object object)
        Convert object to string
        Parameters:
        object - object
        Returns:
        string representation of object
      • setReadOnly

        public static void setReadOnly​(java.util.Collection<ModuleUsage> usages,
                                       boolean readOnly,
                                       org.eclipse.core.runtime.IProgressMonitor monitor)
                                throws com.nomagic.ci.persistence.PersistenceException
        Make module usage readonly
        Parameters:
        usages - module usages
        readOnly - readonly flag
        monitor - monitor
        Throws:
        com.nomagic.ci.persistence.PersistenceException - in case of some persistence problem
      • setReadOnlyOnTask

        public static void setReadOnlyOnTask​(java.util.Collection<ModuleUsage> usages,
                                             boolean readOnly)
        Make module usage readonly
        Parameters:
        usages - module usages
        readOnly - readonly flag
      • setAutoLoadKind

        public static void setAutoLoadKind​(ProjectAttachmentConfiguration configuration,
                                           AutoLoadKind autoLoadKind)
        Set auto load kind for a given configuration.
        Parameters:
        configuration - configuration to change auto load.
        autoLoadKind - auto load kind
      • setAutoLoadKind

        public static void setAutoLoadKind​(IProject owner,
                                           ProjectAttachmentConfiguration configuration,
                                           AutoLoadKind kind,
                                           org.eclipse.core.runtime.IProgressMonitor monitor)
                                    throws com.nomagic.ci.persistence.PersistenceException
        Set module load kind
        Parameters:
        owner - module owner
        configuration - attachment configuration
        kind - load kind
        monitor - monitor
        Throws:
        com.nomagic.ci.persistence.PersistenceException - in case of some persistence problem
      • setAutoLoadKind

        public static void setAutoLoadKind​(IProject owner,
                                           ProjectAttachmentConfiguration configuration,
                                           AutoLoadKind kind)
        Set module load kind
        Parameters:
        owner - module owner
        configuration - attachment configuration
        kind - load kind
      • setAutoLoadKind

        public static void setAutoLoadKind​(IProject owner,
                                           IAttachedProject module,
                                           AutoLoadKind kind,
                                           org.eclipse.core.runtime.IProgressMonitor monitor)
                                    throws com.nomagic.ci.persistence.PersistenceException
        Set module load kind
        Parameters:
        owner - module owner
        module - module
        kind - load kind
        monitor - monitor
        Throws:
        com.nomagic.ci.persistence.PersistenceException - in case of some persistence problem
      • setAutoLoadKindOnTask

        public static void setAutoLoadKindOnTask​(IProject owner,
                                                 IAttachedProject module,
                                                 AutoLoadKind kind)
        Set module load kind
        Parameters:
        owner - module owner
        module - module
        kind - load kind
      • setReSharedOnTask

        public static void setReSharedOnTask​(IProject project,
                                             IProject module,
                                             boolean reShared)
        Reshare given module in a given project
        Parameters:
        project - project
        module - module
        reShared - add or remove re-sharing
      • setReShared

        public static void setReShared​(IProject project,
                                       IProject module,
                                       boolean reShared,
                                       @CheckForNull
                                       org.eclipse.core.runtime.IProgressMonitor monitor)
        Re-share given module in a given project
        Parameters:
        project - project
        module - module
        reShared - add ore remove re-sharing
        monitor - monitor
      • doAttachModule

        private static boolean doAttachModule​(IProject project,
                                              IProject module,
                                              org.eclipse.core.runtime.IProgressMonitor monitor)
                                       throws com.nomagic.ci.persistence.PersistenceException
        Throws:
        com.nomagic.ci.persistence.PersistenceException
      • shareOnTask

        public static com.nomagic.ci.persistence.sharing.ISharePoint shareOnTask​(IProject project,
                                                                                 Package pkg,
                                                                                 java.lang.String path)
        Share given package in a given project
        Parameters:
        project - project
        pkg - package to share
        path - preferred path for mounting
        Returns:
        share point
      • share

        public static com.nomagic.ci.persistence.sharing.ISharePoint share​(IProject project,
                                                                           Package pkg,
                                                                           java.lang.String path,
                                                                           org.eclipse.core.runtime.IProgressMonitor monitor)
                                                                    throws com.nomagic.ci.persistence.local.spi.InvalidProjectObjectException,
                                                                           com.nomagic.ci.persistence.LockAcquisitionException
        Share given package in a given project
        Parameters:
        project - project
        pkg - package to share
        path - preferred path for mounting
        monitor - monitor
        Returns:
        share point
        Throws:
        com.nomagic.ci.persistence.local.spi.InvalidProjectObjectException
        com.nomagic.ci.persistence.LockAcquisitionException - if locking required elements fails during the operation
      • setSharePreferredPathOnTask

        public static void setSharePreferredPathOnTask​(IProject project,
                                                       Package pkg,
                                                       java.lang.String path)
        Set preferred path for mounting for given shared package
        Parameters:
        project - project
        pkg - package
        path - preferred mounting path
      • setSharePreferredPath

        public static void setSharePreferredPath​(IProject project,
                                                 Package pkg,
                                                 java.lang.String path,
                                                 @CheckForNull
                                                 org.eclipse.core.runtime.IProgressMonitor monitor)
                                          throws com.nomagic.ci.persistence.local.spi.InvalidProjectObjectException
        Set preferred path for mounting for given shared package
        Parameters:
        project - project
        pkg - package
        path - preferred mounting path
        monitor - monitor
        Throws:
        com.nomagic.ci.persistence.local.spi.InvalidProjectObjectException
      • setStandardSystemProfile

        public static void setStandardSystemProfile​(IProject project,
                                                    boolean standard)
        Mark given project as "standard system profile".
        Parameters:
        project - project
        standard - mark as standard profile
      • setInternalVersion

        public static void setInternalVersion​(IProject project,
                                              java.lang.String version)
        Set internal version for a given project
        Parameters:
        project - project
        version - version
      • setCompatibleVersion

        public static void setCompatibleVersion​(IProject project,
                                                java.lang.String version)
        Set compatible version for a given project
        Parameters:
        project - project
        version - version
      • setUsedVersionOnTask

        public static void setUsedVersionOnTask​(IProject owner,
                                                IAttachedProject module,
                                                java.lang.String version)
        Set "used" version for a given module
        Parameters:
        owner - module owner
        module - module
        version - version
      • setUsedVersion

        public static void setUsedVersion​(IProject owner,
                                          IAttachedProject module,
                                          java.lang.String version,
                                          org.eclipse.core.runtime.IProgressMonitor monitor)
                                   throws com.nomagic.ci.persistence.PersistenceException
        Set "used" version for a given module.
        Parameters:
        owner - module owner
        module - module
        version - version
        monitor - monitor
        Throws:
        com.nomagic.ci.persistence.PersistenceException - if any persistence problem
      • unShare

        public static void unShare​(IProject project,
                                   Package pkg,
                                   org.eclipse.core.runtime.IProgressMonitor monitor)
                            throws com.nomagic.ci.persistence.local.spi.InvalidProjectObjectException,
                                   com.nomagic.ci.persistence.LockAcquisitionException
        Un-share given package from a given project
        Parameters:
        project - project
        pkg - package to un-share
        monitor - monitor
        Throws:
        com.nomagic.ci.persistence.local.spi.InvalidProjectObjectException
        com.nomagic.ci.persistence.LockAcquisitionException - if locking required elements fails during the operation
      • unShareOnTask

        public static void unShareOnTask​(IProject project,
                                         Package pkg)
        Un-share given package from a given project
        Parameters:
        project - project
        pkg - package to un-share
      • setStickyVersion

        public static void setStickyVersion​(java.util.Collection<ModuleUsage> usages,
                                            @CheckForNull
                                            IVersionDescriptor version,
                                            org.eclipse.core.runtime.IProgressMonitor monitor)
                                     throws com.nomagic.ci.persistence.PersistenceException
        Set sticky version for given modules usages.
        Parameters:
        usages - usages
        version - sticky version(null if no sticky version
        monitor - progress monitor
        Throws:
        com.nomagic.ci.persistence.PersistenceException - in case of some persistence problem
      • setStickyVersionOnTask

        public static void setStickyVersionOnTask​(java.util.Collection<ModuleUsage> usages,
                                                  @CheckForNull
                                                  IVersionDescriptor version)
        Set sticky version for given modules usages.
        Parameters:
        usages - usages
        version - sticky version(null if no sticky version
      • findOrLoadLocalModule

        @CheckForNull
        public static IAttachedProject findOrLoadLocalModule​(Project project,
                                                             java.lang.String filePath,
                                                             boolean allowUI)
        Attaches local module from given path into a given project. Does nothing if such module is already attached.
        Parameters:
        project - project
        filePath - full path to module file
        allowUI - allow to show error messages to user
        Returns:
        attached module
      • findOrLoadModule

        @CheckForNull
        public static IAttachedProject findOrLoadModule​(Project project,
                                                        ProjectDescriptor moduleLocation,
                                                        boolean allowUI)
        Looks for existing module in a given project. If found, attaches it directly in project. If module is not found, attaches and loads it.
        Parameters:
        project - project where module is searched of loaded.
        moduleLocation - module descriptor to load.
        allowUI - allow to show error messages to user
        Returns:
        found or loaded module. Null if failure.
      • findOrLoadModule

        @CheckForNull
        public static IAttachedProject findOrLoadModule​(Project project,
                                                        @CheckForNull
                                                        ProjectDescriptor moduleLocation,
                                                        @CheckForNull
                                                        org.eclipse.core.runtime.IProgressMonitor monitor,
                                                        boolean allowUI)
        Looks for already attached module in a given project. or attaches a new one. If such module is already attached not directly, attaches it directly in a given project. Activates given project if it is not active yet. If module is not found, attaches and loads it.
        Parameters:
        project - project where module is searched of loaded.
        moduleLocation - module descriptor to load.
        monitor - monitor where display status, if null new progress bar is shown.
        allowUI - allow to show error messages to user
        Returns:
        found or newly attached module. Null if failure.
      • loadInnerModulesRecursively

        static void loadInnerModulesRecursively​(IAttachedProject module,
                                                @CheckForNull
                                                org.eclipse.core.runtime.IProgressMonitor monitor)
                                         throws com.nomagic.ci.persistence.PersistenceException
        Load inner modules recursively
        Parameters:
        module - module
        monitor - monitor
        Throws:
        com.nomagic.ci.persistence.PersistenceException - in case of some persistence problem
      • detachModulesInternal

        private static boolean detachModulesInternal​(java.util.Collection<ModuleUsage> modules,
                                                     boolean removeNewUnreachableModules,
                                                     @CheckForNull
                                                     IAttachedProjectRemoverCallback removeConfirmation,
                                                     @CheckForNull
                                                     org.eclipse.core.runtime.IProgressMonitor monitor)
                                              throws java.lang.Exception
        Removes all given modules usages. If module is used more than one time only remove usage, in other case module data will be disposed.
        Parameters:
        modules - modules to remove.
        removeNewUnreachableModules - determines whether to try to remove module that will become manually unreachable due to the operation
        removeConfirmation - remove confirmation
        monitor - progress monitor
        Returns:
        true if all modules were detached, false if user cancelled operation
        Throws:
        java.lang.Exception - in case of some error
      • detachModulesInternal2

        private static boolean detachModulesInternal2​(java.util.Collection<ModuleUsage> modules,
                                                      boolean removeNewUnreachableModules,
                                                      @CheckForNull
                                                      IAttachedProjectRemoverCallback removeConfirmation,
                                                      org.eclipse.core.runtime.IProgressMonitor monitor)
                                               throws java.lang.Exception
        Throws:
        java.lang.Exception