It's all about the answers!

Ask a question

Delete a file using Java Plain API


Marc Bauer (111) | asked Jan 29 '18, 7:01 a.m.
edited Jan 22 '19, 1:56 p.m. by David Lafreniere (4.8k7)

How do I delete a file using Plain Java API?
I am able to get the files IVersionableHandle, but I don't know how to delete it.
(I want to remove a former checked in file from a stream.)

One answer



permanent link
David Lafreniere (4.8k7) | answered Jan 22 '19, 1:56 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
ITeamRepository repo = getRepo();
IWorkspaceHandle workspaceHandle = getWorkspace();
IVersionableHandle fileToDelete = getVersionable();
IChangeSetHandle changeSet = getChangeSet(); // Change set to check into
IWorkspaceManager wm = ScmPlatform.getWorkspaceManager(repo);
IWorkspaceConnection wc = wm.getWorkspaceConnection(workspaceHandle, monitor);

Collection ops = new ArrayList();
ops.add(wc.configurationOpFactory().delete(fileToDelete ));
IUpdateReport report = wc.commit(Collections.singletonList(changeSet ), Collections.singletonList(ops), monitor);


Comments
Gidi Gal commented Mar 31 '19, 11:18 a.m.

Is there a public API for deleting file\folder from sandbox without committing the local change to change-set ?


Shashikant Padur commented Apr 01 '19, 12:01 a.m.
JAZZ DEVELOPER
Did you mean undo the unresolved file changes? If so,
ILocalChangeManager lcm = FileSystemCore.getSharingManager().getLocalChangeManager();

You have to iterate over the changes to find your change:
ILocalChange[] localChanges = lscm.getPendingChanges(...);

Then call undo changes only for those changes you have to undo:
lscm.undoChanges(localChanges, ...);

Gidi Gal commented Apr 01 '19, 6:30 a.m.
Thanks for your reply, Shashikant.
No, the file in sandbox may be in sync with the stream. Up until now I used java.io.File.delete to delete the file and then I fetched the local changes with ILocalChangeManager in order to check-in them or check-in and deliver. java.io.File.delete returns sometimes false on failure with no documentation on the relevant error. I'm looking for a public RTC SDK client API to replace it.

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.