Obtain a list of baselines for a component in a workspace
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)
Anyone knows how to filter this list further per workspace? Or do I need another approach to get this working?
Thanks in advance.
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
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
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:
but if I run getBaselinesInHistory I only get
What is the method I can call to obtain the same of show baselines command?
Thanks,
Michele.
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.
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.
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.
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