AbstractScmAdvisor - How do you read changed file content?
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:
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.
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
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.