It's all about the answers!

Ask a question

Obtain a list of baselines for a component in a workspace


Patrick Leyman (3044) | asked Dec 02 '10, 4:08 a.m.
edited Jun 01 '16, 11:26 p.m. by David Lafreniere (4.8k7)
Hi,

I want to recover via the Java API a list of baselines of a component, but filtered for a specific workspace. I can obtain a list of baselines for a component but across all workspaces. I want this list filtered for just one specific workspace. I'm using the following code to get a complete list for a component but I don't know how to filter this for a given workspace(Handle)

IBaselineSearchCriteria crit = IBaselineSearchCriteria.FACTORY.newInstance();
crit.setComponentRequired(comp);
List baselines = workspaceManager.findBaselines(crit, Integer.MAX_VALUE, monitor);
for (Iterator b = baselines.iterator(); b.hasNext();) {
IBaselineHandle bl = (IBaselineHandle) b.next();
IBaseline baseline = (IBaseline) teamRepository.itemManager().fetchCompleteItem(bl, IItemManager.DEFAULT, monitor);
IBaselineConnection baseConnection = workspaceManager.getBaselineConnection(baseline,monitor);
System.out.println(baseline.getId() + " - " + baseline.getName());
}


Anyone knows how to filter this list further per workspace? Or do I need another approach to get this working?

Thanks in advance.

7 answers



permanent link
Lorena Cortés (2654) | answered Jun 23 '11, 4:55 p.m.
Hi..

Do you know how to resolve this problem now???

I have the same trouble....

thanks

permanent link
Patrick Leyman (3044) | answered Jun 24 '11, 2:05 a.m.
Hi..

Do you know how to resolve this problem now???

I have the same trouble....

thanks


As a matter of a fact, we found a solution yes. Via the WorkspaceConnection object you can use the getBaseLinesInHistory(comp, qty, monitor) method. This method returns a IHistoricBaselineIterator which contains a list of baselines. My method to recover the last baseline for a component in my workspace:

private IBaseline recoverLastBaseline(IWorkspaceConnection workspace, IComponent component) throws MojoFailureException {
try {
IHistoricBaselineIterator baseHist = workspace.getBaselinesInHistory(component, 1, getMonitor());
if (baseHist.getBaselines() == null || baseHist.getBaselines().size() < 1) {
throw new MojoFailureException("Couldn't find a useable baseline");
}
IBaseline baseline = (IBaseline) getItemManager().fetchCompleteItem(baseHist.getBaselines().get(0), IItemManager.DEFAULT, getMonitor());
getLog().debug("Baseline: " + baseline.getId() + " - " + baseline.getName());
return baseline;
} catch (TeamRepositoryException e) {
throw new MojoFailureException("Error while fetching last baseline for component " + component.getName() + " in workspace " + workspace.getName());
}
}


I hope it helps.
Regards,
Patrick

permanent link
Michele Pegoraro (1.8k14119103) | answered Feb 23 '12, 4:56 a.m.
Hi,
I've a similar problem. I'd like to compare the baseline automatically created by a build request with the previous one.

In this cas I've found that getBaselinesInHistory method does not return the same content I would have if I select "Show Baselines" in client but only the baseline in the history.

For example if I select show baselines on my repository workspace I obtain this list:
12: RI000_add_TestVari_20120223-0930, sa_RTC, 9.30.26 (1 ora fa)

9: pluto, es02046 Michele Pegoraro, 16-Feb-2012 17.33
11: RI000_add_TestVari_20120217-1115, sa_RTC, 17-Feb-2012 11.15
9: pluto, es02046 Michele Pegoraro, 16-Feb-2012 17.33
10: RI000_add_TestVari_20120216-1735, sa_RTC, 16-Feb-2012 17.35
9: pluto, es02046 Michele Pegoraro, 16-Feb-2012 17.33
8: RI000_add_TestVari_20120216-1730, sa_RTC, 16-Feb-2012 17.30
1: Initial Baseline, es02046 Michele Pegoraro, 13-Feb-2012 12.50


but if I run getBaselinesInHistory I only get
12: RI000_add_TestVari_20120223-0930, sa_RTC, 9.30.26 (1 ora fa)

9: pluto, es02046 Michele Pegoraro, 16-Feb-2012 17.33
1: Initial Baseline, es02046 Michele Pegoraro, 13-Feb-2012 12.50


What is the method I can call to obtain the same of show baselines command?

Thanks,
Michele.

permanent link
David Van Herzele (10121) | answered Feb 24 '12, 7:16 a.m.
Michele , the answer you seek is in the first post of this thread ;-)


IBaselineSearchCriteria crit = IBaselineSearchCriteria.FACTORY.newInstance();
crit.setComponentRequired(comp);
List baselines = workspaceManager.findBaselines(crit, Integer.MAX_VALUE, monitor);

permanent link
Michele Pegoraro (1.8k14119103) | answered Feb 27 '12, 4:46 a.m.
David,
thanks for you answer but this code does not work for me because I'm searching for baseline in a specific workspace.

I've just tried another method which works quite the way I need: getMergedBaselineHistory. This method has only a problem: it returns some duplicate line. This is ok if the duplicates are not subsequent (because of replace history) but it returns also, in some case, the same baseline two times one after the other.

I resolved removing subsequent duplicates and so I obtain the same list I have with client command.

Best regards,
Michele.

permanent link
VK L (8177157159) | answered Aug 15 '12, 11:41 p.m.
Hi Michele,
                    To automatically compare the baseline against the previous one, which operation is your plugin based on? I mean is it an Operation particpant and if yes, where is it configured in the operation behaviour?

Thanks.

permanent link
Stefano Antoniazzi (1701711) | answered May 24 '16, 8:54 a.m.
edited May 24 '16, 8:55 a.m.
 I think that the right answer is here link . If you want a list of the specific stream or workspace component baselines (like what you get from ui when you right click on the component of a workspace and then you select show > baselines) you've just to change the parameters from
wsConn.getComponentAuditTrail(compHandle, numBasisInHistory - 1, 1, new NullProgressMonitor());
	
	
to  
wsConn.getComponentAuditTrail(compHandle, 0, myMax, new NullProgressMonitor());

where myMax is the maximum number of baselines you want, paying attention that the list is from oldest to newest

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.