It's all about the answers!

Ask a question

How do I get all changed files for a Component using Java API?

Anh Tu Le (1325) | asked Sep 24 '15, 10:15 p.m.
edited Sep 24 '15, 10:15 p.m.

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.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

permanent link
Andrew Niefer (7135) | answered Sep 25 '15, 12:01 p.m.
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.
Anh Tu Le selected this answer as the correct answer

Anh Tu Le commented Oct 08 '15, 6:03 a.m. | edited Oct 08 '15, 6:04 a.m.

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 at

Here is my code: List<iancestorreport> ancestorReports = configuration.locateAncestors(iVersionableHandles, monitor);

Andrew Niefer commented Oct 08 '15, 8:14 a.m.

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)

Anh Tu Le commented Oct 09 '15, 10:22 p.m. | edited Oct 09 '15, 11:22 p.m.

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.

Albert Yao commented Aug 01 '18, 12:22 a.m. | edited Aug 05 '18, 5:47 p.m.

@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.

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.