Problems with Change Sets in IOperationParticipant
Hi,
I am writing an IOperationParticipant as a follow-up action to Deliver Phase 2 (server) (com.ibm.team.scm.service.changehistory.modification) to automatically copyright file changes when a developer delivers to a configured stream.
The key API interactions are as follows:
1. Locate change sets and target workspace from IScmDeltaSource
2. Extract IVersionable's from change sets
3. Extract file content using IServerSideVersionedContentService and IFileContent
4. Test copyright date and if it requires update change as follows
5. Using the Web UI file update model by doing the following: IScmService.updateLocks to lock a file
6. Create a new change set via IScmService.createChangeSetForStream
7. Get IFileItem working copy from IVersionable
8. Create a new IFileContent and set in the IFileItem
9. Use IServerSideVersionedContentService.storeContentNoProperties to store the copyrighted content
10. Add the IFileItem to the change sets ICommitParameter
11. Now I use IScmService.deliverCombined to associate the change set to the stream
12. Unlock the file using IScmService.updateLocks
13. Exit the participant
All works well until deliverCombined is called at this point I get an ItemNotFoundException from RepositoryTransactionContext. The problem is that deliverCombined creates a new ScmTransactionContext to run the deliver. The deliver process proceeds and calls my participant again which is odd as I would have thought this would be the very last thing to be called. I use Thread Local Storage to detect this situation and immediately exit, but then ItemNotFoundException is raised as my created change set is only known in a different transactional context.
It is possible that if I called ScmServiceInternal.deliverCombined which expects the transaction to be in place the deliver would work. However, a problem exists in that I do not know how to access the current ScmTransactionContext to pass to the ScmServiceInternal constructor.
Can you advise as to how I can deliver the change set that has been created on the fly during the deliver process? Is what I am trying to achieve here so off-piste that it will not work? Having copyright's updated automatically at deliver time would save us so much time so any help you can provide would be most appreciated.
Regards,
Ian Hodges
I am writing an IOperationParticipant as a follow-up action to Deliver Phase 2 (server) (com.ibm.team.scm.service.changehistory.modification) to automatically copyright file changes when a developer delivers to a configured stream.
The key API interactions are as follows:
1. Locate change sets and target workspace from IScmDeltaSource
2. Extract IVersionable's from change sets
3. Extract file content using IServerSideVersionedContentService and IFileContent
4. Test copyright date and if it requires update change as follows
5. Using the Web UI file update model by doing the following: IScmService.updateLocks to lock a file
6. Create a new change set via IScmService.createChangeSetForStream
7. Get IFileItem working copy from IVersionable
8. Create a new IFileContent and set in the IFileItem
9. Use IServerSideVersionedContentService.storeContentNoProperties to store the copyrighted content
10. Add the IFileItem to the change sets ICommitParameter
11. Now I use IScmService.deliverCombined to associate the change set to the stream
12. Unlock the file using IScmService.updateLocks
13. Exit the participant
All works well until deliverCombined is called at this point I get an ItemNotFoundException from RepositoryTransactionContext. The problem is that deliverCombined creates a new ScmTransactionContext to run the deliver. The deliver process proceeds and calls my participant again which is odd as I would have thought this would be the very last thing to be called. I use Thread Local Storage to detect this situation and immediately exit, but then ItemNotFoundException is raised as my created change set is only known in a different transactional context.
It is possible that if I called ScmServiceInternal.deliverCombined which expects the transaction to be in place the deliver would work. However, a problem exists in that I do not know how to access the current ScmTransactionContext to pass to the ScmServiceInternal constructor.
Can you advise as to how I can deliver the change set that has been created on the fly during the deliver process? Is what I am trying to achieve here so off-piste that it will not work? Having copyright's updated automatically at deliver time would save us so much time so any help you can provide would be most appreciated.
Regards,
Ian Hodges
One answer
I'll defer to the SCM-API/followup-action-API experts, but I'd vote for "off-piste" (:-).
One issue I see is that all of the Deliver process (both pre-condition and follow-up actions) need to be run on your new changes. And then this can trigger another follow-up action that wants to make a different change. There are work item API's specifically designed to handle this case (by allowing you to detect when you are effectively being called recursively), but I don't think those kind of API's are available for SCM. In addition, the SCM case is more complex, because you have Client-Side preconditions and two phases of Server-Side preconditions that need to run.
One issue I see is that all of the Deliver process (both pre-condition and follow-up actions) need to be run on your new changes. And then this can trigger another follow-up action that wants to make a different change. There are work item API's specifically designed to handle this case (by allowing you to detect when you are effectively being called recursively), but I don't think those kind of API's are available for SCM. In addition, the SCM case is more complex, because you have Client-Side preconditions and two phases of Server-Side preconditions that need to run.