Allow IVersionableHandle path in RTC

How to get the path to a file that is not in the latest version, but is part of the previous list of changes in RTC scm .

All I could achieve is this:

 IFileItemHandle fileItemHandle = (IFileItemHandle) IFileItem.ITEM_TYPE.createItemHandle(change.afterState().getItemId(), change.afterState().getStateId()); file = versionableManager.fetchCompleteState(fileItemHandle, monitor); if (file instanceof IFolder) { IFolder folder = (IFolder) file; relativePath = getFilePath(file, workspaceConnection.configuration(changeSet.getComponent()), monitor); fileName = folder.getName(); } else { relativePath = getFilePath(file, workspaceConnection.configuration(changeSet.getComponent()), monitor); fileName = ((FileItem) file).getName(); } 

Where getFilePath :

 private String getFilePath(IVersionableHandle folder, IConfiguration config, IProgressMonitor monitor, Boolean searchInHistory) throws TeamRepositoryException { List lst = new ArrayList<IVersionableHandle>(), ancestors; lst.add(folder); if (searchInHistory) { ancestors = config.determineAncestorsInHistory(lst, monitor); } else { ancestors = config.locateAncestors(lst, monitor); } return getFullPath(ancestors); } private String getFullPath(List ancestor) throws TeamRepositoryException { String directoryPath = ""; for (Object ancestorObj : ancestor) { IAncestorReport ancestorImpl = (IAncestorReport) ancestorObj; for (Object nameItemPairObj : ancestorImpl.getNameItemPairs()) { INameItemPair nameItemPair = (INameItemPair) nameItemPairObj; String pathName = nameItemPair.getName(); if (pathName != null && !pathName.equals("")) { directoryPath = directoryPath + "\\" + pathName; } } } return directoryPath; } 

Unfortunately, this does not work perfectly. If the file name changes in the following change lists, for example, in this example:

 Changelist 1: add file: src/newFile.java Changelist 2: modify file: src/newFile.java Changelist 3: rename file: src/newFile.java -> src/newFile_rename.java 

The relative path allowed in the first list of changes will be as follows:

 src/newFile_rename.java 

instead

 src/newFile.java 

How to do it well?

+4
source share
1 answer

As long as the javadoc for IConfiguration.determineAncestorsInHistory does not indicate, the server side equivalent of IScmService.configurationDetermineAncestorsInHistory (which is ultimately called) says this in javadoc:

  * @param versionableItemHandles * a list of versionable items; only the item ids are needed; * must not be <code>null</code> 

Basically, defineAncestorsInHistory does not look for a state identifier in files, it only looks at the element identifier.

The specific state of the file to be considered is determined by the configuration. This happens mainly because until the state of the file in the change set tells you the name of this file, it will not tell you the name of the parent folder. This will depend on the state of the folder, which is present in the workspace at a certain time and may be different for different workspaces.

You basically need to get an IConfiguration representing your workspace when the change set has been accepted / created.

As I see it, I need to get IWorkspaceConnection.changeHistory(component) (this is actually defined in IFlowNodeConnection). You will need to go through the history by calling IChangeHistory.previousHistory(monitor) until you find the one that contains your IChangeHistory.recent(monitor) in IChangeHistory.recent(monitor) . When you find the appropriate IChangeHistory, use IChangeHistory.configuration() to call defineAncestorsInHistory.

Note that this configuration represents the state of the workspace at the end of this particular IChangeHistory, so to be completely accurate, you will need to check the changes that occur after the change in IChangeHistory.recent to see if any of them have changed your name file (or any of the file names with folder names).

(Another alternative is to use story 1 configuration, the previous story containing your changeset, and then view the effects of the changes that occurred before your change)

+1
source

Source: https://habr.com/ru/post/1479495/


All Articles