How can I set descriptions on snapshots and baselines programmatically with the JAVA API
![]()
In the GUI is is possible to set and modify a description for snapshots and baselines. However, our team automates everything. We need to set and/or modify descriptions for snapshots and baselines to mark them after we create and perform operations on them. I know that descriptions can be done through the GUI, but that is useless to us. (i.e. can't be automated.) SCM doesn't have this function on any of the subcommands. So, the API seems our only route.
I didn't see a simple method for doing this in the API, nor did I find any info in the forums after searching around quite a while. I'm probably overlooking something obvious. I somebody could point me in the right direction, I'd really appreciate it. Thanks. |
Accepted answer
![]()
Ralph Schoon (62.3k●3●36●43)
| answered Nov 28 '12, 12:02 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Nov 28 '12, 12:02 p.m.
Mike,
If you have the SDK set up, open the baseline properties (where you can rename the baseline) for example and Plug-In Spy the dialog. Use the Eclipse Java Search to find the dialog class and then look into it. The client code to change the properties looks like this: final boolean result[] = { true }; BusyIndicator.showWhile(null, new Runnable() { public void run() { RepositoryOperation op = new RepositoryOperation() { public void repositoryRun(IProgressMonitor monitor, IStatusCollector problems) throws TeamRepositoryException { SubMonitor progress = SubMonitor.convert(monitor, 4); ITeamRepository repo = ClientRepositoryUtil.getRepository(baseline); repo.login(progress.newChild(1)); IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo); IBaselineConnection connection = wm.getBaselineConnection(baseline, progress.newChild(1)); if (!NullUtil.equals(baseline.getName(), newName)) { connection.setName(newName, progress.newChild(1)); } if (!NullUtil.equals(baseline.getComment(), newComment)) { connection.setComment(newComment, progress.newChild(1)); } } }; try { getShell().setEnabled(false); WorkbenchUtil.runBackgroundSave(TempHelper.MONITOR, op, Messages.BaselinePropertyPage_0); } catch (CoreException e) { Mike Philpot selected this answer as the correct answer
Comments ![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
PS: Please be aware that there are several API's. There are a lot of other frameworks involved such as Eclipse.
Yep. I agree with you completely. Our group started on this stuff last year and I started this summer. It's a bit daunting. We've managed to figure out how to code up most stuff, but its still easy to get lost. :-)
Now that I've seen how the GUI is doing things, I think setting the description fields boils down to something like the following:
![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please consider to accept one of the answers, it makes it easier to understand questions are closed. (And it adds reputation to whoever answered the question)
Will definitely do that. Just wanted to try out the above in code first to confirm. Should have something today of all goes well.
I was able to test these out and they worked great. Thanks again for all the help.
showing 5 of 6
show 1 more comments
|
2 other answers
![]()
Ralph Schoon (62.3k●3●36●43)
| answered Nov 28 '12, 6:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Nov 28 '12, 6:51 a.m.
Hi Mike,
I would suggest to read Robin Bobbitt's blog about the Plug In Spy. If you do want to extend RTC it is essential you can find the API by usage such as the new Snapshot Dialog yourself. If you use the Plug In Spy you can easily find the NewSnapshotDialog which is referenced by com.ibm.team.internal.filesystem.ui.actions.components.NewSnapshotAction where you can find this code: private void promptAndCreate(Shell shell, ITeamRepository repo, IWorkspace workspace) { NewSnapshotDialog dialog = new NewSnapshotDialog(shell, NLS.bind(Messages.NewSnapshotAction_0, workspace.getName()), repo, workspace); if (dialog.open() == IDialogConstants.OK_ID) { createSnapshot(repo, workspace, dialog.getName(), dialog.getComment(), dialog.getCreateNewBaselines(), dialog.getExcludedComponents()); } } private void createSnapshot(final ITeamRepository repo, final IWorkspace workspace, final String name, final String comment, final boolean createNewBaselines, final List excludedComponents) { getOperationRunner().enqueue(Messages.NewSnapshotAction_1, new RepositoryOperation(repo) { public void repositoryRun(IProgressMonitor monitor, IStatusCollector problems) throws TeamRepositoryException { SubMonitor progress = SubMonitor.convert(monitor, 100); IWorkspaceConnection connection = SCMPlatform.getWorkspaceManager(repo).getWorkspaceConnection(workspace, progress.newChild(10)); try { connection.createBaselineSet( excludedComponents, name, comment, createNewBaselines, progress.newChild(90)); final AbstractPlaceWrapper wrapper = AbstractPlaceWrapper.newWrapper(connection.getResolvedWorkspace()); SnapshotListView.openSearch(getContext().getDisplay(), wrapper); } catch (ConflictsProhibitOperationException e) { JFaceUtils.showMessage(Messages.NewSnapshotAction_2, Messages.NewSnapshotAction_3, IStatus.INFO); } } }); } I forgot to mention that the snippets that come with the Plain Java Client Library also contain interesting examples for example Snippet 2 is for SCM. At the end of it you can use workspace.createBaseline(component, "Baseline", "Desc", monitor); to create a baseline. Comments Thanks so much for the info.
So, at the moment, I'm still looking through the API. No joy so far...
![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The Plug in Spy needs the source (the RTC SDK) to be installed to see source. How this can be done is described in https://jazz.net/library/article/1000 (Lab 1) which is back referenced in my blog in various posts, where you might be able to find other useful API too.
![]() FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
As a side note, if you don't intent to run the whole workshop and just set up the SDK, just read lab 1, do the installs, but skip the setup and repotools import and start setting up Eclipse with the SDK at
Thanks for the info.
OK, found why I couldn't see the source. I needed to make the SDK active under Window -> Preferences -> Plug-in Development -> Target Platform.
showing 5 of 6
show 1 more comments
|
![]()
Just as a note to Philpot's response above:
connect(baselineHandle) essentially gets a baselineConnection and on that object one would call the setComment. To get a baselineConnection one would do: SCMPlatform.getWorkspaceManager (ITeamRepository).getBaselineConnection (baselineHandle, IProgressMonitor) This info. is for anybody else who might be needing the same functionality. |