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.
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
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) {
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) {
Comments
showing 5 of 6
show 1 more comments
2 other answers
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.
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
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.
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.