How do I get all changed files for a Component using Java API?
I have managed to get a reference of the IWorkspaceConnection representing the Stream and a list of IComponentHandle representing the Components of the Streams. But how can I get the history of the Component and all changed files for each Change Set?
IWorkspaceManager workspaceManager = (IWorkspaceManager) repo.getClientLibrary(IWorkspaceManager.class);
IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setExactName("`123444"); // stream name
List<IWorkspaceHandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, monitor);
for (int i = 0; i < workspaceHandles.size(); i++) {
WorkspaceHandleImpl iWorkspaceHandle = (WorkspaceHandleImpl) workspaceHandles.get(i);
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(iWorkspaceHandle, monitor);
List<IComponentHandle> componentHandles = workspaceConnection.getComponents();
//what should I do here to get the history of the Component?
}
Accepted answer
IChangeHistory changeHistory = workspaceConnection.changeHistory(component)
IChangeHistory.recent() returns a list of IChangeHistoryEntryChange which gives you the change sets. The most recent change is at the end of the list, the start of the list is the oldest.
The history is split into "eras" whose size depends on the version of RTC and your usage patterns. Once you've looked at all the change sets in the recent list, use IChangeHistory.previousHistory to get the previous era in history. If previousHistory returns null, then you've reached the start of history.
Comments
Thanks. I was able to get the changed files.But I ran into another problem. Whenever I get the changed files of a "Merge" change set, it always throws the following exception:
Exception in thread "main" java.lang.IllegalArgumentException
at com.ibm.team.scm.client.internal.ConnectionBasedClientConfigurationProxy.locateAncestors(ConnectionBasedClientConfigurationProxy.java:438)
at com.ibm.team.scm.client.internal.ConnectionBasedClientConfigurationProxy.locateAncestors(ConnectionBasedClientConfigurationProxy.java:419)
Here is my code:
List<iancestorreport> ancestorReports = configuration.locateAncestors(iVersionableHandles, monitor);
The IllegalArgumentException happens if one of the versionableHandles is null or not an instanceof IVersionableHandle.
ChangeSet.getChanges is a List<Change>. Change.getItem() should be a non-null IVersionableHandle. For a merge changeSet, Change.getMerges is a List<MergeState> and MergeState.getState() gives the merged in stateId, which may be null. (null here represents a deleted file)
I figured it out, one of the changed files had IChange.NONE kind. I edit my code to ignore all IChange.NONE files and the error does not occur anymore. Thanks for your help.
@Andrew, what does "The history is split into "eras" whose size depends on the version of RTC and your usage patterns" mean? My RTC has two release versions: 4.0.7 and 5.0.2.