It's all about the answers!

Ask a question

How to get full path of file in a CLIENT side plugin?


Makson Lee (41024241) | asked Jul 04 '13, 9:21 p.m.
 I Know the question about how to get full path of file had been asked many times, and there are samples showing how to do this, but i can't still get it done in a CLIENT side plugin.

In a SERVER side plugin example, you can get ServiceConfigurationProvider with the following code fragment,
public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object operationData = operation.getOperationData();
        if (!(operationData instanceof DeliverOperationData)) {
        return;
        }
DeliverOperationData data = (DeliverOperationData) operationData;
List<IChangeSetHandle> changeSetHandles = data.getChangeSetHandles();
IRepositoryItemService itemService = getService(IRepositoryItemService.class);
IScmService scmService = getService(IScmService.class);
IItemServiceIterator changeSetIterator = ItemServiceIteratorFactory.INSTANCE.createFetchItemsIterator(itemService, changeSetHandles.toArray(new IItemHandle[changeSetHandles.size()]), IRepositoryItemService.COMPLETE);

while (changeSetIterator.hasNext()) {
IChangeSet changeSet = (IChangeSet) changeSetIterator.next();
if (changeSet == null) {
continue;
}
for (IChange change : (List<IChange>) changeSet.changes()) {
if (change.kind() == IChange.DELETE) {
IVersionableHandle versionableHandle = change.beforeState();
ServiceConfigurationProvider configProvider = ServiceConfigurationProvider.FACTORY.create(
data.getDestWorkspace(), changeSet.getComponent());

But in a CLIENT side plugin which you can right click on a change set in Change Explorer view and then click on a customized menu item to export the change log details, how do you get a ServiceConfigurationProvider?

public class ExportChange extends AbstractActionDelegate {
public ExportChange {
}

@Override
public void run(Shell shell IWorkbenchPage page, IStructuredSelection selection) {

......

}



Comments
1
Surya Tripathi commented Jul 10 '13, 7:04 p.m.

Not sure exactly where would you want to get the full path, but could you try something like this -
- Get IConfiguration. You can get this from IWorkspaceConnection
- Call locateAncestors(). This will give you INameItemPair.
- You would be able to get the information you need from it.
Please let me know if this works for you.

One answer



permanent link
Makson Lee (41024241) | answered Jul 11 '13, 2:15 a.m.
Thanks for the comment, but all i got for now is change sets user selected in the Change Explorer view, i don't know how to get an IWorkspaceConnection with them.

public class ExportChange extends AbstractActionDelegate {
private SnapshotId selectedSnapshot;

public ExportChange() {
}

@Override
public void run(Shell shell, IWorkbenchPage page, IStructuredSelection selection) {  
        List<ChangeSetWrapper> changeSetWrappers = AdapterUtil.adaptList(selection.toList(), ChangeSetWrapper.class);        
        List<IActivitySource> sources = AdapterUtil.adaptList(selection.toList(), IActivitySource.class);  
                
        for (IActivitySource next : sources) {
            List<IRemoteActivity> activities = next.getActivities();            
            changeSetWrappers.addAll(RemoteActivityAdapter.convertToChangeSetWrappers(activities));
        }        
        
        if (!changeSetWrappers.isEmpty()) {
                 
        ITeamRepository repo = changeSetWrappers.get(0).getRepository();
        IScmService scmService = (IScmService) repo.getClientLibrary(IScmService.class);
        IWorkspaceManager workspaceManager = (IWorkspaceManager) repo.getClientLibrary(IWorkspaceManager.class);
       
        List<IChangeSet> changeSets = CollectionUtil.filterDupes(ChangeSetWrapper.getChangeSets(changeSetWrappers));
       
        for(IChangeSet changeSet : changeSets) {           
          for(IChange change : (List<IChange>)changeSet.changes()) {
            IVersionableHandle versionableHandle = change.beforeState();
            
            .............
            
          }
        }
        }        
        return;
}
}

Comments
1
Surya Tripathi commented Jul 11 '13, 5:21 p.m. | edited Jul 11 '13, 5:22 p.m.

I see. So, I guess you can use SCMPlatform to get the IWorkspaceConnection. SCMPlatform.getWorkspaceManager().createWorkspace() or 
SCMPlatform.getWorkspaceManager(repo).getWorkspaceConnection().


Makson Lee commented Jul 11 '13, 10:16 p.m.

So i still need that the login user should provide a workspace selection so that i can create a IWorkspaceConnection?


The changes shown in Change Explorer view already have the full path presented, there must be something i can reuse, right?


1
Surya Tripathi commented Jul 15 '13, 4:24 p.m.

If you do not have the workspace context, I think this can help -
IWorkspaceManager wsm= SCMPlatform.getWorkspaceManager(repo);
IVersionableManager vm = wsm.versionableManager();
IVersionable vn = vm.fetchCompleteState(versionableHandle, monitor );

From IVersionable you can then calculate the path. Let me know if it helps.


1
Surya Tripathi commented Jul 15 '13, 5:52 p.m.

I thought you may also want to check this question - https://jazz.net/forum/questions/49910/how-to-get-an-iconfiguration-from-ichangeset

And the work item - https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=152190
These two talk about how to get workspace using changeset.


Makson Lee commented Jul 15 '13, 9:39 p.m.

Thanks for your reply, i know that we must have a workspace/stream to calculate the full path of a file item, and there is no problem to show a dialog to let user to select it.


I am just wondering, if the Change Explorer view can already show the full path, there must be some IConfiguration instance used inside, then maybe we can reuse it instead of letting user to choose it again.



2
Surya Tripathi commented Jul 17 '13, 3:53 p.m.

I don't think Change Explorer stores the path in a way to make it available to someone writing an extension like you yourself.
You can also check out a few more posts -
https://jazz.net/forum/questions/8704/is-it-possible-to-get-the-full-path-name-of-a-ifileitem
https://jazz.net/forum/questions/93557/how-get-full-path-of-the-file-from-changeset-using-api


Makson Lee commented Jul 18 '13, 5:23 a.m.
An existed instance of IConfiguration would be good enough, we could then calculate the full path by ourselves.

Anyway, if that is not possible, i should now try to study the information you provided :-)
showing 5 of 7 show 2 more comments

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.