How to delete repository workspace directly?
My code:
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IWorkspaceConnection repoWorkspace = null;
repoWorkspace = wm.createWorkspace(repo.loggedInContributor(), workspaceName,workspaceDesc, monitor);
.//operation with the repoWorkspace .....
IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY.newInstance().setExactName(workspaceName);
List<IWorkspaceHandle> workspaceHandles= wm.findWorkspaces(criteria, Integer.MAX_VALUE, null);
wm.deleteWorkspace(workspaceHandles.get(0), null);
Now my question:
In my code, I have use criteria to find it first, then delete it. And I think it's not very good.So how can i delete it directly?
One answer
Comments
I mean, I don't lost the object, all the code i post in one function, so I think the "find" operation is useless. BUT, I don't know how to delelte it without to find it again.
Sorry, but all you need in your code above is the IWorkspaceConnectionHandle, or the IWorkspaeConnection. If you have the IWorkspaceConnection - which you have, that should also implement or provide the IWorkspaceConnectionHandle (most objects implement or make the handle aavailable) you need for delete. So you can just pass
wm.deleteWorkspace(repoWorkspace , null);
in your code above to the IWorkspaceManager wm.
if use wm.delelteWorkspace(repoWorkspace, null); it shows an error that "repoWorkspace" is not "IWorkspaceHandle", and also can not do cast.
Have a look at IWorkspaceConnection and look for a getter such ad getItemHandle or the like.
so far, I don't get the method to get the IWorkspaceHandle.
In your Development environment set up as described in the Extensions Workshop and in https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ Open the declaration for IWorkspaceManager, locate the delete function you want to use. Do a Java search fir the references of said method and browse the references in the SDK.
You will then find that you need to use the getResolvedWorkspace to get the latest version
wm.deleteWorkspace(repoWorkspace.getResolvedWorkspace(), monitor);