Getting file (versionable) history using Server Java API
(EDITED 2017-05-15 18:38 CET)
Hi,
I'm building a followup action to SaveChangeSetLink (IOperationParticipant).
Put simply I want to find the parent change set of a versionable (that is, a change set that includes the parent of my Versionable)
The end goal is to automatically create a "Blocked by" relation to other work items, that are linked to parent change sets. In this way, we can easily see what work items would create gaps in our stream, should we decide to promote these. It makes our deployment planning a lot easier.
I have tried this in two ways. Firstly I've tried to get the change set history of my versionable by using the following method:
ChangeHistoryEntry[] com.ibm.team.scm.common.IScmService.getHistoryForVersionable(ServiceHistoryProvider historyProvider, IVersionableHandle versionableHandle, int limit, boolean examineEras, ISynchronizationTimes[] syncTimes, IRepositoryProgressMonitorHandle monitor) throws TeamRepositoryException
But I'm getting the exception in the ccm.log:
java.lang.IllegalStateException: Illegal transaction in progress for service method call.
at com.ibm.team.repository.service.internal.PrimitiveTransactionService.checkValidTransaction(PrimitiveTransactionService.java:86)
at sun.reflect.GeneratedMethodAccessor312.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.invoke(ExportProxyServiceRecord.java:361)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.access$0(ExportProxyServiceRecord.java:347)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord$ExportedServiceInvocationHandler.invoke(ExportProxyServiceRecord.java:56)
at com.sun.proxy.$Proxy142.checkValidTransaction(Unknown Source)
at com.ibm.team.repository.service.AbstractService.checkValidTransaction(AbstractService.java:238)
at com.ibm.team.scm.service.internal.ScmService.getHistoryForVersionable(ScmService.java:2696)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.invoke(ExportProxyServiceRecord.java:361)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord.access$0(ExportProxyServiceRecord.java:347)
at org.eclipse.soda.sat.core.internal.record.ExportProxyServiceRecord$ExportedServiceInvocationHandler.invoke(ExportProxyServiceRecord.java:56)
at com.sun.proxy.$Proxy1292.getHistoryForVersionable(Unknown Source)
I can see in the documentation, that "You cannot call this method within a transaction", so I guess that is my problem. Does anyone know of any other method?
I've also tried to find the parent Versionable and then use the IScmQueryService to fire off a ChangeSetSearchCriteria, but I'm also getting the "transaction error" once again. I cannot call this service during a transaction.
Any ideas how I can go about this?
Thanks all,
/Morten.
Accepted answer
I settled for doing the following:
public static IChangeSet findVersionableStateChangeSet(IVersionableHandle version, IProjectAreaHandle projh, IRepositoryItemService rs, IScmService scms, IScmQueryService scmqs, IReportInfoCollector collector, String streamName) throws TeamRepositoryException
{
IWorkspaceHandle wsh = getStreamWorkspaceHandle(streamName, projh, rs, scmqs, collector);
IComponentHandle[] compHdls = scms.getComponentsContainingVersionable(wsh, version, null, null);
ServiceHistoryProvider historyProvider = ServiceHistoryProvider.FACTORY.create(wsh, compHdls[0]);
ChangeHistoryEntry[] historyEntries = scms.recentEntries(historyProvider, null, null);
IChangeSet foundChangeSet = searchForVersionableChangeSetInHistory(version, rs, historyEntries);
if (foundChangeSet != null)
return foundChangeSet; // change set located
ChangeHistoryHandle chHdl = scms.previousHistory(historyProvider, null, null);
int loopCount = 0;
while (chHdl != null && loopCount < 100 / infinite loop protection /)
{
historyProvider = ServiceHistoryProvider.FACTORY.create(chHdl);
historyEntries = scms.recentEntries(historyProvider, null, null);
foundChangeSet = searchForVersionableChangeSetInHistory(version, rs, historyEntries);
if (foundChangeSet != null)
return foundChangeSet;
chHdl =scms.previousHistory(historyProvider, null, null);
loopCount++;
}
return null; // no changeset with versionable found
}
private static IChangeSet searchForVersionableChangeSetInHistory(IVersionableHandle version, IRepositoryItemService rs, List<ChangeHistoryEntry> historyEntryList) throws TeamRepositoryException
{
// looping all change-sets
IChange change;
IChangeSetHandle csh;
IChangeSet cs;
for (ChangeHistoryEntry changeEntry : historyEntryList)
{
csh = changeEntry.getChangeSet();
cs = (IChangeSet) rs.fetchItem(csh, null);
// looping all changes (files) in each change-set
for (Object co : cs.changes())
{
change = (IChange) co;
if (change.afterState() != null && change.afterState().getStateId().equals(version.getStateId()))
{
return cs;
}
}
}
return null; // no results found
}
Comments
Morten Madsen
May 15 '17, 9:59 a.m.Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER May 15 '17, 12:17 p.m.Morten Madsen
May 15 '17, 12:27 p.m.Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER May 16 '17, 2:23 a.m.