Class ProjectUtilities


  • @OpenApiAll
    public class ProjectUtilities
    extends java.lang.Object
    Project decomposition related utility class.
    • Field Detail

      • EXPORTER_DESCRIPTION

        public static final java.lang.String EXPORTER_DESCRIPTION
        Property for XmiExporterDescription
        See Also:
        Constant Field Values
      • REMOTE_ID_ENCODING

        protected static final java.lang.String REMOTE_ID_ENCODING
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProjectUtilities

        public ProjectUtilities()
    • Method Detail

      • createDefaultProjectAttachmentConfiguration

        public static ProjectAttachmentConfiguration createDefaultProjectAttachmentConfiguration​(org.eclipse.emf.common.util.URI uri)
        Create default project attachment configuration with default settings.
        Parameters:
        uri - uri
        Returns:
        attachment configuration
      • updateConfigurationWithDefaultValues

        public static void updateConfigurationWithDefaultValues​(ProjectAttachmentConfiguration configuration)
        Updates attachment configuration with default values
        Parameters:
        configuration - the configuration to update
      • isLoadIndex

        public static boolean isLoadIndex​(AbstractProjectAttachmentConfiguration configuration)
        Check if to load index.
        Parameters:
        configuration - attachment configuration.
        Returns:
        true if option is set to load index.
      • setLoadIndex

        public static void setLoadIndex​(AbstractProjectAttachmentConfiguration configuration,
                                        boolean loadIndex)
        Set if to load index.
        Parameters:
        configuration - attachment configuration.
        loadIndex - load index.
      • getAttachedProject

        @CheckReturnValue
        @CheckForNull
        public static IAttachedProject getAttachedProject​(@CheckForNull
                                                          org.eclipse.emf.ecore.EObject element)
        Find attached project (module) for a given element
        Parameters:
        element - element for which attached project will be returned
        Returns:
        project or null if element does not belong to any module
      • getFromCache

        @CheckForNull
        private static <K,​V> V getFromCache​(com.nomagic.utils.DisableableCacheMap<K,​V> map,
                                                  K key1)
      • putToCache

        private static <K,​V> void putToCache​(com.nomagic.utils.DisableableCacheMap<K,​V> map,
                                                   K key1,
                                                   V result)
      • getProjectFor

        @CheckForNull
        public static IProject getProjectFor​(@CheckForNull
                                             BaseElement element)
        Find IProject for a given element
        Parameters:
        element - element for which attached project will be returned
        Returns:
        project
      • findAttachedProjectByID

        @CheckForNull
        public static IAttachedProject findAttachedProjectByID​(Project project,
                                                               java.lang.String moduleID,
                                                               boolean recursively)
        Find attached project by given id in a given project
        Parameters:
        project - project to search in
        moduleID - module id
        recursively - search in primary project only or recursively in whole project
        Returns:
        found module
      • findAttachedProjectByID

        @CheckForNull
        public static IAttachedProject findAttachedProjectByID​(IProject project,
                                                               java.lang.String moduleID,
                                                               boolean recursively)
        Find attached project by given id in a given project
        Parameters:
        project - project to search in
        moduleID - module id
        recursively - search in primary project only or recursively in whole project
        Returns:
        found module
      • findAttachedProjectByProjectID

        @CheckForNull
        public static IAttachedProject findAttachedProjectByProjectID​(IProject project,
                                                                      java.lang.String projectID,
                                                                      boolean recursively)
        Find attached project by given project id
        Parameters:
        project - project to search in
        projectID - module id
        recursively - search in primary project only or recursively in whole project
        Returns:
        found module
      • findProjectByResourceID

        @CheckForNull
        public static IProject findProjectByResourceID​(IPrimaryProject primaryProject,
                                                       java.lang.String resourceId)
        Search for project with given resource ID
        Parameters:
        primaryProject - scope of searching
        resourceId - resource ID.
        Returns:
        found project or null.
      • findAttachedProjectByName

        @CheckForNull
        public static IAttachedProject findAttachedProjectByName​(Project project,
                                                                 java.lang.String name,
                                                                 boolean recursively)
        Find attached project by given name in a given project
        Parameters:
        project - project to search in
        name - module name
        recursively - search in primary project only or recursively in whole project
        Returns:
        found module
      • findAttachedProjectByName

        @CheckForNull
        private static IAttachedProject findAttachedProjectByName​(Project project,
                                                                  java.util.Collection<java.lang.String> names,
                                                                  boolean recursively)
        Find attached project by given names in a given project.
        Parameters:
        project - project to search in
        names - possible module names
        recursively - search in primary project only or recursively in whole project
        Returns:
        found module
      • findAttachedProjectByName

        @CheckForNull
        public static IAttachedProject findAttachedProjectByName​(Project project,
                                                                 java.lang.String name)
        Find attached project by given name in a given project. Does recursive search.
        Parameters:
        project - project to search in
        name - module name
        Returns:
        found module
      • findAttachedProjectByID

        @CheckForNull
        public static IAttachedProject findAttachedProjectByID​(Project project,
                                                               java.lang.String moduleID)
        Find attached project by given id in a given project. Does recursive search.
        Parameters:
        project - project to search in
        moduleID - module id
        Returns:
        found module
      • isAttachedProjectRoot

        public static boolean isAttachedProjectRoot​(@CheckForNull
                                                    Element element)
        Check if given element is a root of some module.
        Parameters:
        element - element
        Returns:
        true if given element is root for module.
      • isAttachedProjectRoot

        public static boolean isAttachedProjectRoot​(@CheckForNull
                                                    Element element,
                                                    IAttachedProject project)
        Check if given element is a root of given module.
        Parameters:
        element - element
        project - module
        Returns:
        true if given element is root for module
      • getSharedPackages

        public static java.util.Collection<Package> getSharedPackages​(IProject project)
        Return shared packages of a given project. Does not include re-shared packages.
        Parameters:
        project - project
        Returns:
        shared packages.
      • getSharedPackagesIncludingReshared

        public static java.util.Collection<Package> getSharedPackagesIncludingReshared​(IProject project)
        Return shared packages of a given project. Include also re-shared packages
        Parameters:
        project - project
        Returns:
        shared packages
      • getSharedPackagesIncludingResharedRecursively

        public static java.util.Collection<Package> getSharedPackagesIncludingResharedRecursively​(IProject project)
        Return shared packages of a given project. Include also re-shared packages. Takes direct packages and also from attached modules recursively of a given project. For ESI project returns module model.
        Parameters:
        project - project
        Returns:
        shared packages
      • collectSharedPackagesIncludingReshared

        static void collectSharedPackagesIncludingReshared​(IProject project,
                                                           java.util.Set<Package> result,
                                                           java.util.Set<IProject> checked,
                                                           boolean recursively)
      • isElementInAttachedProject

        public static boolean isElementInAttachedProject​(Element element)
        Check if given element belongs to some module
        Parameters:
        element - element
        Returns:
        true if element belongs to some module
      • getAllAttachedProjects

        public static java.util.Collection<IAttachedProject> getAllAttachedProjects​(Project project)
        Return all modules in a given project
        Parameters:
        project - project
        Returns:
        all modules in the Project
      • getAllProjects

        public static java.util.Collection<IProject> getAllProjects​(Project project)
        Return all modules and primary project in a given project
        Parameters:
        project - project
        Returns:
        all modules in the Project, collection is not modifiable
      • isSharedElement

        public static boolean isSharedElement​(IProject project,
                                              Element element)
        Check if given element belongs to some shared (or reshared) package in a given project
        Parameters:
        project - project
        element - element
        Returns:
        true if element belongs to shared package
      • getRemoteID

        @CheckForNull
        public static java.lang.String getRemoteID​(org.eclipse.emf.common.util.URI uri)
        Extract remote project id from a given uri.
        Parameters:
        uri - uri
        Returns:
        remote if or null
      • getRemoteID

        @CheckForNull
        public static java.lang.String getRemoteID​(IProject project)
        Return remote id for a given project
        Parameters:
        project - project
        Returns:
        remote id
      • versionToInt

        public static int versionToInt​(@CheckForNull
                                       java.lang.String version)
        Utility method to convert string representation of version into int
        Parameters:
        version - version
        Returns:
        version as int
      • versionToLong

        private static long versionToLong​(@CheckForNull
                                          java.lang.String version,
                                          long latestVersionValue)
        Utility method to convert string representation of version into long
        Parameters:
        version - version
        latestVersionValue - latest version
        Returns:
        version as long. return latest version if given version is null or empty
      • versionToString

        @CheckForNull
        public static java.lang.String versionToString​(int version)
        Utility method to convert int representation of version into string
        Parameters:
        version - version
        Returns:
        version as string
      • getResourceID

        public static java.lang.String getResourceID​(IProject project)
        Gets simplified resource id for given project. For remote project it returns project id, for local filename.
        Parameters:
        project - project descriptor
        Returns:
        filename or project id.
      • getResourceID

        public static java.lang.String getResourceID​(ProjectDescriptor pd)
        Gets simplified resource id for given project descriptor. For remote project it returns project id, for local filename.
        Parameters:
        pd - project descriptor
        Returns:
        filename or project id.
      • getResourceID

        public static java.lang.String getResourceID​(org.eclipse.emf.common.util.URI uri)
        Gets simplified resource id for given project location URI. For remote project it returns project id, for local filename.
        Parameters:
        uri - project location.
        Returns:
        filename or project id.
      • getAttachedProjects

        public static java.util.Collection<IAttachedProject> getAttachedProjects​(IProject project)
        Returns projects those are attached directly to a given project. Primary attached project is ignored.
        Parameters:
        project - project
        Returns:
        collection of attached projects
      • getAllAttachedProjects

        public static java.util.Collection<IAttachedProject> getAllAttachedProjects​(IProject project)
        Returns projects those are attached directly or indirectly to a given project. Primary attached project is ignored.
        Parameters:
        project - project
        Returns:
        collection of attached projects
      • getAllAttachedProjectsIncludingPrimary

        public static java.util.Collection<IProject> getAllAttachedProjectsIncludingPrimary​(IProject project)
        Returns projects those are attached directly or indirectly to a given project including primary project.
        Parameters:
        project - project
        Returns:
        collection of attached projects
      • getAllAttachedProjects

        public static java.util.Collection<IAttachedProject> getAllAttachedProjects​(java.util.Collection<IAttachedProject> projects)
        Returns projects those are attached directly or indirectly to a given project. Primary attached project is ignored.
        Parameters:
        projects - project projects
        Returns:
        collection of attached projects
      • getAttachedProjectsIncludingPrimary

        public static java.util.Collection<IProject> getAttachedProjectsIncludingPrimary​(IProject project)
        Returns projects those are attached directly to a given project.Primary attached project can be included also.
        Parameters:
        project - project
        Returns:
        collection of attached projects
      • getAutoLoadKind

        public static AutoLoadKind getAutoLoadKind​(IProject owner,
                                                   IProject project)
        Return load kind of given module in a given project
        Parameters:
        owner - project
        project - module
        Returns:
        load kind
      • getAutoLoadKind

        @Deprecated
        public static AutoLoadKind getAutoLoadKind​(ProjectAttachmentConfiguration attachment)
        Deprecated.
        use public static AutoLoadKind getAutoLoadKind( AbstractProjectAttachmentConfiguration attachment )
        Return load kind of module from given attachment
        Parameters:
        attachment - attachment
        Returns:
        load kind
      • getAttachingProject

        @CheckForNull
        public static IProject getAttachingProject​(IProject project)
        Return first project where given project is attached. Primary project has always priority.
        Parameters:
        project - given project
        Returns:
        first project where given module is attached.
      • getAttachingProjects

        public static java.util.Collection<IProject> getAttachingProjects​(IProject project)
        Return all projects where given project is attached.
        Parameters:
        project - given project.
        Returns:
        all projects where given module is attached.
      • getEMFURI

        public static org.eclipse.emf.common.util.URI getEMFURI​(java.net.URI uri)
        Convert java net URI to emf uri
        Parameters:
        uri - net uri
        Returns:
        emf uri
      • getAttachment

        @CheckForNull
        public static AbstractProjectAttachmentConfiguration getAttachment​(IProject parent,
                                                                           IProject child)
        Return configuration which is used to attach one project to another
        Parameters:
        parent - project which uses another project (directly)
        child - used directly project
        Returns:
        found ProjectAttachmentConfiguration (for local and teamwork projects) or EsiProjectAttachmentConfiguration (for Teamwork Cloud projects) or null if such not found.
      • getURI

        public static java.net.URI getURI​(org.eclipse.emf.common.util.URI emfUFI)
        Convert EMF uri to java.net.URI
        Parameters:
        emfUFI - emf uri
        Returns:
        java net uri
      • getVersion

        @CheckForNull
        public static IVersionDescriptor getVersion​(IProject project)
        Return version of given project.
        Parameters:
        project - project
        Returns:
        version or null if project has no version
      • isFromTeamworkServer

        public static boolean isFromTeamworkServer()
        Check if given project is from teamwork server.
        Returns:
        true if project is from server
      • isFromEsiServer

        public static boolean isFromEsiServer​(@CheckForNull
                                              IProject project)
        Check if given project is from ESI.
        Parameters:
        project - project
        Returns:
        true if project is from ESI
      • isRemote

        public static boolean isRemote​(@CheckForNull
                                       IProject project)
        Check if given project is remote - from teamwork server or ESI.
        Parameters:
        project - project
        Returns:
        true if project is from server
      • isFromStandardProfile

        public static boolean isFromStandardProfile​(Element element)
        Checks, if the given element is a part of the Standard Profile
        Parameters:
        element - element to check
        Returns:
        true, if the given element is a part of the Standard Profile
      • getProject

        @CheckForNull
        public static Project getProject​(@CheckForNull
                                         IProject iProject)
        Returns MagicDraw project for primary or attached project.
        Parameters:
        iProject - primary or attached project
        Returns:
        Project
      • getMountPoint

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

        @Deprecated
        @CheckForNull
        public static com.nomagic.ci.persistence.sharing.ISharePoint getSharePoint​(com.nomagic.ci.persistence.mounting.IMountPoint point)
        Deprecated.
        com.nomagic.ci.persistence.mounting.ISharePoint is not exposed into Open API
        Find share point corresponding given mount point
        Parameters:
        point - mount point
        Returns:
        share point
      • encodeTeamworkRemoteId

        public static java.lang.String encodeTeamworkRemoteId​(java.lang.String remoteId)
        Encodes Teamwork remote ID
        Parameters:
        remoteId - the raw (not encoded) remote ID
        Returns:
        encoded ID
      • decodeTeamworkRemoteId

        public static java.lang.String decodeTeamworkRemoteId​(java.lang.String remoteId)
        Decodes Teamwork remote ID
        Parameters:
        remoteId - the encoded remote ID
        Returns:
        decoded (raw) remote ID
      • isESIUri

        public static boolean isESIUri​(org.eclipse.emf.common.util.URI uri)
        Checks if given URI is ESI project URI
        Parameters:
        uri - the URI to check
        Returns:
        true if given URI is ESI, false otherwise
      • isESIUri

        public static boolean isESIUri​(java.net.URI uri)
        Checks if given URI is ESI project URI
        Parameters:
        uri - the URI to check
        Returns:
        true if given URI is ESI, false otherwise
      • isElementProxy

        public static boolean isElementProxy​(BaseElement element)
        Checks if given element is proxy or orphan proxy.
        Parameters:
        element - the element to check
        Returns:
        true if given element is proxy or orphan proxy, otherwise - false
      • getESIRemoteId

        @CheckForNull
        public static java.lang.String getESIRemoteId​(org.eclipse.emf.common.util.URI uri)
        Gets ESI remote ID
        Parameters:
        uri - the URI to get remote ID for
        Returns:
        the remote ID
      • getESIRemoteId

        @CheckForNull
        public static java.lang.String getESIRemoteId​(IProject project)
        Gets ESI remote ID for given project
        Parameters:
        project - the project
        Returns:
        the remote ID
      • getRemoteId

        @CheckReturnValue
        @CheckForNull
        public static java.lang.String getRemoteId​(org.eclipse.emf.common.util.URI uri)
        Retrieves project remote id from given uri.
        Parameters:
        uri - remote project uri to check.
        Returns:
        remote project id from project uri.
      • getMountPoints

        public static java.util.Collection<com.nomagic.ci.persistence.mounting.IMountPoint> getMountPoints​(IProject project)
        Gets all mount points in given project. Returns empty set if there are no mount points
        Parameters:
        project - project
        Returns:
        non-null set of all mount points
      • getMountPointsFor

        public static java.util.Set<com.nomagic.ci.persistence.mounting.IMountPoint> getMountPointsFor​(IProject owner,
                                                                                                       IProject attachedProject)
        Gets mount points for given project, i.e. returns all mount points that are mounted share points of given project. Returns empty set if there are no mount points to return.
        Parameters:
        owner - owner
        attachedProject - the project to get mount points for
        Returns:
        non-null set of mount points for specific project
      • getAllMountPoints

        @Deprecated
        public static java.util.Set<com.nomagic.ci.persistence.mounting.IMountPoint> getAllMountPoints​(IPrimaryProject project)
        Deprecated.
        IMountPoint is not exposed into Open API
        Return all mount points existing in given primary project (direct and not direct).
        Parameters:
        project - project
        Returns:
        all mount points from given project and from all attached
      • getProject

        @CheckForNull
        public static IProject getProject​(@CheckForNull
                                          org.eclipse.emf.ecore.EObject object)
        Return project in which object resists.
        Parameters:
        object - object
        Returns:
        found project or null
      • getProject

        @CheckForNull
        public static IProject getProject​(@CheckForNull
                                          org.eclipse.emf.ecore.resource.Resource resource)
        Return project for a resource.
        Parameters:
        resource - resource
        Returns:
        found project or null
      • compareVersions

        public static int compareVersions​(@CheckForNull
                                          IVersionDescriptor versionDescriptor1,
                                          @CheckForNull
                                          IVersionDescriptor versionDescriptor2)
        Compare given versions descriptors. The null descriptor is larger than not null.
        Parameters:
        versionDescriptor1 - first version descriptor (can be null).
        versionDescriptor2 - second version descriptor (can be null).
        Returns:
        the value 0 if versions are equal; a value less than 0 if first version is less then second; and a value greater than 0 if first version is greater then second.
      • compareVersionNumber

        public static int compareVersionNumber​(@CheckForNull
                                               java.lang.String versionNumber1,
                                               @CheckForNull
                                               java.lang.String versionNumber2)
        Compare given version numbers.
        Parameters:
        versionNumber1 - first version number.
        versionNumber2 - second version number.
        Returns:
        the value 0 if versions are equal; a value less than 0 if first version is less then second; and a value greater than 0 if first version is greater then second.
      • getAttachedProject

        @CheckForNull
        public static IAttachedProject getAttachedProject​(IProject project,
                                                          org.eclipse.emf.common.util.URI uri)
        Look for direct or not direct attached project in a primary project of a given project.
        Parameters:
        project - project
        uri - uri
        Returns:
        found module
      • getElementFor

        @CheckForNull
        public static Element getElementFor​(@CheckForNull
                                            BaseElement element)
        Return element for a given base element. Returned element can be passed into other utility methods as EObject if needed.
        Parameters:
        element - base element
        Returns:
        model element
      • isMountedPackage

        public static boolean isMountedPackage​(Package pck)
        Check if given package is a mounted(or is a shared root from some module)
        Parameters:
        pck - package
        Returns:
        true if package is mounted
      • getInternalVersion

        @CheckForNull
        public static java.lang.String getInternalVersion​(IProject project)
        Get internal version of project
        Parameters:
        project - project
        Returns:
        version
      • getCompatibleVersion

        @CheckForNull
        public static java.lang.String getCompatibleVersion​(IProject project)
        Get compatible version of the project
        Parameters:
        project - project
        Returns:
        compatible version
      • isStandardSystemProfile

        public static boolean isStandardSystemProfile​(IProject project)
        Check if given project is a standard system profile
        Parameters:
        project - project
        Returns:
        true if given project is a standard system profile
      • isStandardSystemProfile

        @Deprecated
        public static boolean isStandardSystemProfile​(DecompositionDescriptor project)
        Deprecated.
        DecompositionDescriptor is not exposed into Open API
        Check if given project is a standard system profile
        Parameters:
        project - project
        Returns:
        true if given project is a standard system profile
      • isLoaded

        public static boolean isLoaded​(IProject project)
        Checks if given project loaded.
        Parameters:
        project - project
        Returns:
        true if given project is loaded
      • isLoadedOrLoading

        public static boolean isLoadedOrLoading​(IProject project)
      • isModule

        @Deprecated
        public static boolean isModule​(DecompositionDescriptor r)
        Deprecated.
        DecompositionDescriptor is not exposed into Open API
        Returns true if given project has shared points.
        Parameters:
        r - project descriptor to evaluate
        Returns:
        true if given project descriptor represents a module.
      • isFromStandardProfile

        public static boolean isFromStandardProfile​(@CheckForNull
                                                    org.eclipse.emf.ecore.EObject element)
        Checks if element comes from standard profile
        Parameters:
        element - element to be checked
        Returns:
        true if element comes from standard profile.
      • getModifiedElements

        public static java.util.Set<Element> getModifiedElements​(Project project)
        Get modified elements.
        Parameters:
        project - project to get elements of.
        Returns:
        modified elements.
      • getExporterDescription

        @CheckForNull
        public static XmiExporterDescription getExporterDescription​(IProject project)
        Provide information about project version and required resources/plugins for that project.
        Parameters:
        project - project
        Returns:
        description of project
      • getSaveID

        @CheckForNull
        public static java.lang.String getSaveID​(IProject project)
        Gets current save/commit id for given project. The value of the Save ID is a randomly generated unique UUID.
        Parameters:
        project - project
        Returns:
        save id
      • addToCacheLoaded

        protected static void addToCacheLoaded​(IProject project,
                                               XmiExporterDescription xmiExporterDescription)
        Adds to cache just loaded modules/projects
        Parameters:
        project - project/module
        xmiExporterDescription - project/module descriptor
      • isModuleUsageNew

        public static boolean isModuleUsageNew​(IProject attachedProject)
        Check if attached project usage from primary project is new (not yet committed to server). This method does not support checking if the usage is new for Teamwork Server Project therefore it always returns false in that case.
        Parameters:
        attachedProject - the IProject of attached project
        Returns:
        true if the provided project is attached project and it is a Teamwork Cloud Project and if the usage from primary project to attached project exists and if it is new (as defined above). Return false otherwise
      • getVisibleURI

        public static java.lang.String getVisibleURI​(java.net.URI uri)
        Creates uri that can be shown in UI components
        Parameters:
        uri - project location uri
        Returns:
        visible uri
      • getVisibleURI

        public static java.lang.String getVisibleURI​(org.eclipse.emf.common.util.URI uri)
        Creates uri that can be shown in UI components
        Parameters:
        uri - project location uri
        Returns:
        visible uri
      • isProjectNameValid

        public static boolean isProjectNameValid​(java.lang.String projectName)
        Checks if given project name is valid. Checks if either the given project name is reserved or has invalid characters
        Parameters:
        projectName - the project name to check
        Returns:
        true if project name is valid, false otherwise