Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 360661

Summary: Need easy method to obtain URI of synchronized resource
Product: [Tools] PTP Reporter: Greg Watson <g.watson>
Component: RDT.syncAssignee: Greg Watson <g.watson>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: wspear
Version: 5.0.2   
Target Milestone: 5.0.3   
Hardware: All   
OS: All   
Whiteboard:

Description Greg Watson CLA 2011-10-12 08:39:16 EDT
The IResource#getLocationURI() method is available obtain the URI of a local resource, or a resource in a remote project, however there is no corresponding way to find out the URI that a resource is being synchronized with. This makes it rather compliated to support all three project types.
Comment 1 Greg Watson CLA 2011-10-12 09:11:46 EDT
I've added two methods:

BuildConfigurationManager#getActiveSyncLocationURI(IResource)
BuildConfigurationManager#getSyncLocationURI(IConfiguration, IResource)

The former obtains the resource URI for the active sync configuration (as specified by the active build configuration). The latter can be used to obtain the resource URI based on any build configuration (since a project can have multiple build/sync configurations).

Fixed in ptp_5_0 and HEAD.
Comment 2 Greg Watson CLA 2011-10-13 11:17:19 EDT
This doesn't solve all the issues because using these methods have a dependency on the org.eclipse.ptp.rdt.sync.core plugin. To avoid this, I've added an IRemoteProject interface and an adapter factory that allows an IProject to be adapted to an IRemoteProject. IRemoteProject is in org.eclipse.ptp.remote.core, so the only dependency required is to this plugin. A client can then do the following:

			IRemoteProject remoteProject = (IRemoteProject) resource.getProject().getAdapter(IRemoteProject.class);
			if (remoteProject != null) {
				URI location = remoteProject.getActiveLocationURI(resource);
				if (location != null) {
					...
				}
			}
			
This will obtain the URI of the synchronized resource, or the normal URI if it is a local or remote resource.

This is only available in HEAD as it requires an API change.
Comment 3 Greg Watson CLA 2011-10-13 14:44:41 EDT
The interface has been simplified slightly. It now works directly on a resource rather requiring access to the project:

			IRemoteResource remoteResource = (IRemoteResource) resource.getAdapter(IRemoteResource.class);
			if (remoteResource != null) {
				URI location = remoteResource.getActiveLocationURI();
				if (location != null) {
					...
				}
			}
Comment 4 Greg Watson CLA 2011-10-14 11:52:02 EDT
*** Bug 357291 has been marked as a duplicate of this bug. ***