It's all about the answers!

Ask a question

AbstractScmAdvisor - How do you read changed file content?

Kevin Mayfield (4358) | asked Feb 12 '13, 1:18 p.m.
I have have looked at many references and have not been successful in getting the code to read the content in a IFileItem.  Many examples are for Client side libraries, and others don't seem to compile, or if they compile, they fail to get a service.

See References: (looks like client lib) (missing how to get IContentService). (server, but answer not complete) (client?)

I have the IScmService:

                 * Details about the files in the changeSets must be retrieved from the scm service..
                 * IMPORTANT:  This advisor must inherit from AbsctractScmAdvisor to have access to this.
                IScmService scmService = getService(IScmService.class);

And I can get each file out of the Change sets:

                // Process files....          
                for (IChange change : (List<IChange>) changeSet.changes()) {
                        IVersionableHandle versionableHandle = change.beforeState();
                        // No Before state?  Must be New file so get After State....
                        //        For new files, LocateAncestors returns none, so you only get the file name.
                        if (versionableHandle == null)
                        // versionableHandle has been class FileItemHandleImpl.
                        IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null);

                        FileItem fitem = (FileItem) item;                      
                        IFileContent content = fitem.getContent();

What do I use to read the content?

I did a toString() on the fitem and content, if that helps...

Tue Feb 12 11:57:15 CST 2013 (stateId: [UUID _8IzHFHUfEeKMMItjgYJ8DQ], itemId: [UUID _076poHUfEeKhtdx8PAwhYw], origin: <unset>, immutable: true) (contextId: [UUID _Dp6kMdwTEd2jUupDpQV1Rw], modified: 2013-02-12 08:24:41.566, workingCopy: <unset>) (name: anotherfile, parentId: [UUID _nyJPMG5JEeKMDqvDi_i1Bw]) (executable: false)
Tue Feb 12 11:57:18 CST 2013 (internalId: [UUID _8IzHEnUfEeKMMItjgYJ8DQ]) (stringHash: j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ, size: 2, predecessorHint: null) (characterEncoding: UTF-8, lineDelimiterSetting: 0)


Accepted answer

permanent link
Tim Mok (6.6k38) | answered Feb 13 '13, 11:43 a.m.
You can call FileSystemCore#getContentManager(ITeamRepository repo) to get the IFileContentManager. From there you can call IFileContentManager#retrieveContent(IFileItemHandle item, IFileContent content, OutputStream outStream, IProgressMonitor monitor) to get a stream for the content.
Kevin Mayfield selected this answer as the correct answer

Kevin Mayfield commented Feb 13 '13, 12:10 p.m.

From the Server API, where do you get the ITeamRepository object?

Tim Mok commented Feb 13 '13, 4:47 p.m.

It sounds like you're writing an advisor but I'm not sure what AbstractScmAdvisor is. From the server side, the IFileContentManager isn't what you want. You'll want the IServerSideVersionedContentService, which is the equivalent on the server. Your advisor is implementing IOperationAdvisor but should also extend AbstractService so you can get this service with the #getService(Class clazz) call.

Kevin Mayfield commented Feb 13 '13, 5:23 p.m. | edited Feb 13 '13, 5:25 p.m.


Checking the server logs...It said to check plugin.xml.

I needed to add the Interface class to the prerequisits list.

<requiredservice interface=""/>

After restarting the server, the following code no longer throws exception:


I should be able to read file content now.

Ralph Schoon commented Feb 14 '13, 2:04 a.m.

Not sure if it might help, if you also need to access work items during deliver see it cost me quite some time to understand how that works.

Your answer

Register or to post your answer.