It's all about the answers!

Ask a question

How to list the component baselines in a snapshot using Java API?

Ratheesh P (3546) | asked May 28 '14, 9:49 a.m.
edited Jul 26 '16, 10:34 a.m. by David Lafreniere (4.8k7)
How can I list the component baselines in a stream snapshot using plain java API's?
We could use the command line "lscm list components <snapshot alias/name/uuid> --snapshot" but how is same possible using java API?

Accepted answer

permanent link
Tim Mok (6.6k38) | answered May 28 '14, 4:28 p.m.
With your IBaselineSet that represents the snapshot, you can call #getBaselines().
David Lafreniere selected this answer as the correct answer

Pietro Bottino commented Jul 26 '16, 9:44 a.m. | edited Feb 01 '21, 3:15 p.m.

Good morning.

Incrementing the Tim's answer, try it this:

IComponentHandle componentHandle = changeSet.getComponent();
IComponent component = (IComponent) itemService.fetchItem(componentHandle, IRepositoryItemService.COMPLETE);
ServiceHistoryProvider targetHistory = ServiceHistoryProvider.FACTORY.create(workspace, changeSet.getComponent());
BaselinesInHistoryResult baselinesInHistory = scmService.getBaselinesInHistory(targetHistory, Integer.MAX_VALUE, null, null);
List<IBaselineHandle> baselines = baselinesInHistory.getBaselines();
for (IBaselineHandle baselineHandle : baselines) {   
    IBaseline baseline = (IBaseline) itemService.fetchItem(baselineHandle,IRepositoryItemService.COMPLETE);

David Lafreniere commented Jul 26 '16, 10:41 a.m.

Just to make it clear for readers: This code shows how, on the server, one would fetch the baselines in the history of some workspace or stream. The question is asking how to get the baselines of a given snapshot, which would be IBaselineSet.getBaselines().

One other answer

permanent link
V D (133) | answered Jan 30 '21, 1:49 p.m.

  Hello Guys,

I am able to fetch the list of snapshots from a given stream programmatically but I am unable to fetch the list of components within a snapshot. I need to copy some files from one component in the snapshot to a component outside the snapshot(in another stream)...

Please help...

David Lafreniere commented Feb 01 '21, 7:18 a.m.

When you have a snapshot (IBaselineSet) you will need to fetch the full IBaseline objects (from the handles of IBaselineSet.getBaselines()). From there, you can get the component using IBaseline.getComponent().

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.