Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

 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) {

......

}


1 vote

Comments

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.

1 vote



One answer

Permanent link
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;
}
}

0 votes

Comments

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

1 vote

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?

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 vote

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.

1 vote

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.


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

2 votes

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 log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,927

Question asked: Jul 04 '13, 9:21 p.m.

Question was seen: 5,587 times

Last updated: Jul 18 '13, 5:23 a.m.

Confirmation Cancel Confirm