How to retrieve the project area of a java file?
Hi all!
I have implemented it with Jazz 1.x version. But in 2.0 version some of the interfaces have been changed, my former code doesn't work now.
Here is my former code.
In RTC 2.0, there is no getOwner() method. So, my plugin couldn't find out the project area of a java file.
Could anyone tell me how to modify the code to get the project area in RTC 2.0.
I have implemented it with Jazz 1.x version. But in 2.0 version some of the interfaces have been changed, my former code doesn't work now.
Here is my former code.
IProjectAreaHandle prjArea = null;
ISharingDescriptor shareDesc = shareable.getShare().getSharingDescriptor();
ITeamRepository repos = getTeamRepository(shareDesc);
IItemManager im = repos.itemManager();
IComponentHandle compRef = shareDesc.getComponent();
IComponent comp = (IComponent) im.fetchCompleteItem(compRef, IItemManager.DEFAULT, null);
// get owning team area & project area
IAuditableHandle compOwner = comp.getOwner();
if (compOwner instanceof ITeamAreaHandle) {
ITeamArea teamArea = (ITeamArea) im.fetchCompleteItem((ITeamAreaHandle)compOwner, IItemManager.DEFAULT, null);
prjArea = teamArea.getProjectArea();
}
IAuditableHandle compOwner = comp.getOwner();
In RTC 2.0, there is no getOwner() method. So, my plugin couldn't find out the project area of a java file.
Could anyone tell me how to modify the code to get the project area in RTC 2.0.
11 answers
The owner of a component wasn't necessarily the workspace in any case in 1.0 (e.g. it could have been the stream, or some other workspace).
ISharingDescriptor has:
public IContextHandle getConnectionHandle()
the result of which can be cast down to IWorkspaceHandle.
IBaselineHandle also extends IContextHandle, but we don't currently allow loading directly from a baseline or baseline set (aka snapshot).
This still doesn't give you the project area though. Workspaces aren't necessarily tied to a particular project area -- they're owned by individuals, and may load components from various streams. Streams are typically scoped to a project or team area, though. A workspace may flow to/from multiple streams, though, possibly in different project areas. A workspace may also have no flow targets.
It would help to know more about what you're trying to do.
Regards,
Nick Edgar
RTC Build component lead
ISharingDescriptor has:
public IContextHandle getConnectionHandle()
the result of which can be cast down to IWorkspaceHandle.
IBaselineHandle also extends IContextHandle, but we don't currently allow loading directly from a baseline or baseline set (aka snapshot).
This still doesn't give you the project area though. Workspaces aren't necessarily tied to a particular project area -- they're owned by individuals, and may load components from various streams. Streams are typically scoped to a project or team area, though. A workspace may flow to/from multiple streams, though, possibly in different project areas. A workspace may also have no flow targets.
It would help to know more about what you're trying to do.
Regards,
Nick Edgar
RTC Build component lead
The owner of a component wasn't necessarily the workspace in any case in 1.0 (e.g. it could have been the stream, or some other workspace).
ISharingDescriptor has:
public IContextHandle getConnectionHandle()
the result of which can be cast down to IWorkspaceHandle.
IBaselineHandle also extends IContextHandle, but we don't currently allow loading directly from a baseline or baseline set (aka snapshot).
This still doesn't give you the project area though. Workspaces aren't necessarily tied to a particular project area -- they're owned by individuals, and may load components from various streams. Streams are typically scoped to a project or team area, though. A workspace may flow to/from multiple streams, though, possibly in different project areas. A workspace may also have no flow targets.
It would help to know more about what you're trying to do.
Regards,
Nick Edgar
RTC Build component lead
What i am trying to do is to relate a source code file to a work item, just like the Jazz check-in & deliver. First of all, I am trying to get the file's related project area, so I can create work item in this area.
Can the IFile--IShareable--IWorkspace--Stream--IProjcetArea be a possible solution?
Best regards!
Yes, that's possible. But note that users may change their current flow target to some other stream than their main development stream (for example, someone in the release engineer role delivering changes to a weekly integration stream). Also, the current flow target may be another workspace, not a stream, or it may have no flow targets.
I have tried this way.
the getOwner() returns an IContributorHandle(not ITeamAreaHandle), so I still can't get the project area...
IWorkspaceHandle workspaceHandle = (IWorkspaceHandle)shareDesc.getConnectionHandle();
ITeamRepository repos = getTeamRepository(shareDesc);
IItemManager im = repos.itemManager();
IWorkspace workspace = (IWorkspace) im.fetchCompleteItem(workspaceHandle, IItemManager.DEFAULT, null);
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repos);
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandle, null);
IAuditableHandle compOwner = workspaceConnection.getOwner();
the getOwner() returns an IContributorHandle(not ITeamAreaHandle), so I still can't get the project area...
Have you tried with IWorkspace.getProcessAreaScope()?
It gives you an IAuditableHandle which I think could be a IProjectAreaHandle or an IProcessAreaHandle. In this case you can fetch the item and than use IProcessArea->getProjectArea().
The only thing is that you have to debug on the IAuditableHandle to see what it could be.
It gives you an IAuditableHandle which I think could be a IProjectAreaHandle or an IProcessAreaHandle. In this case you can fetch the item and than use IProcessArea->getProjectArea().
The only thing is that you have to debug on the IAuditableHandle to see what it could be.
Yaoben, in your code snippet you're fetching the owner of the workspace, which will always be an IContributorHandle. You should instead look up the current flow target from the workspace's flow table, check that the target is a stream, and get the owner from it.
Try:
Regards,
Nick Edgar
RTC Build component lead
Try:
IFlowEntry currentFlowEntry = workspaceConnection.getFlowTable().getCurrentDeliverFlow();
if (currentFlowEntry != null) {
IWorkspaceHandle targetHandle = (IWorkspaceHandle) currentFlowEntry.getFlowNode();
IWorkspaceConnection targetConnection = workspaceManager.getWorkspaceConnection(targetHandle, null);
if (targetConnection.isStream()) {
IAuditableHandle ownerHandle = workspaceConnection.getOwner();
...
}
}
Regards,
Nick Edgar
RTC Build component lead
It is really nice to see both of your replies. I have tried both ways you offered.
To Michele:
I have debuged on the IAuditable object, unfortunately I find it is null. So there is no way to get access to the project area via it. So I wonder if there is anything wrong with my invoking.
Anyway, I really appreciate you offer.
To Nick:
I copy your code into my code, right after
But the getOwner() still returns an IContributorHandle(). I am confused...
To Michele:
I have debuged on the IAuditable object, unfortunately I find it is null. So there is no way to get access to the project area via it. So I wonder if there is anything wrong with my invoking.
IWorkspace workspace = (IWorkspace) im.fetchCompleteItem(workspaceHandle, IItemManager.DEFAULT, null);
IAuditableHandle handle = workspace.getProcessAreaScope();
Anyway, I really appreciate you offer.
To Nick:
I copy your code into my code, right after
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandle, null);
But the getOwner() still returns an IContributorHandle(). I am confused...
We are trying to do a similar controll: we would check if the change-set was associated to a work-item of the same project area.
Our snippet code is:
ITeamRepository repo = ...
IWorkItemReferences wiReferences = ...
List<IReference> refList = wiReferences.getReferences(ILinkTypeRegistry.INSTANCE.getLinkType("com.ibm.team.filesystem.workitems.change_set").getSourceEndPointDescriptor());
for (IReference ref : refList) {
IChangeSet cs = (IChangeSet) repo.itemManager().fetchCompleteItem(ref.resolve(), IItemManager.DEFAULT, null);
IComponent component = (IComponent) repo.itemManager().fetchCompleteItem(cs.getComponent(), IItemManager.DEFAULT, null);
IItem owner = (IItem) component.getOwner();
// ...
}
Such a method "IComponent#getOwner()" does not exist, but the information there is as an internal... How can we get the value?
Thanks in advance.
page 1of 1 pagesof 2 pages