AbstractScmAdvisor - How do you read changed file content?
See References:
https://jazz.net/forum/questions/8246/read-content-of-specific-file-in-repository (looks like client lib)
https://jazz.net/forum/questions/896/problems-while-using-icontentservice (missing how to get IContentService).
https://jazz.net/forum/questions/69047/icontentserviceretrievecontent (server, but answer not complete)
https://jazz.net/forum/questions/80722/getting-ifilecontent-for-32kb-files (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=change.afterState();
// 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 com.ibm.team.filesystem.common.internal.impl.FileItemImpl@6e046e04 (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 com.ibm.team.filesystem.common.internal.impl.FileContentImpl@702c702c (internalId: [UUID _8IzHEnUfEeKMMItjgYJ8DQ]) (stringHash: j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ, size: 2, predecessorHint: null) (characterEncoding: UTF-8, lineDelimiterSetting: 0)
Thanks.
Accepted answer
Comments
From the Server API, where do you get the ITeamRepository object?
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.
Thanks...
Checking the server logs...It said to check plugin.xml.
I needed to add the Interface class to the prerequisits list.
<requiredservice interface="com.ibm.team.scm.service.IServerSideVersionedContentService"/>
After restarting the server, the following code no longer throws exception:
this.getService(com.ibm.team.scm.service.IServerSideVersionedContentService.class);
I should be able to read file content now.
Thanks.
Not sure if it might help, if you also need to access work items during deliver see http://rsjazz.wordpress.com/2012/11/01/restrict-delivery-of-changesets-to-workitem-types-advisordelivery-of-changesets-associated-to-wrong-work-item-types-advisor/ it cost me quite some time to understand how that works.