Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ptp-dev] Getting URI for file in a synchronized project

Hi Dave

Answers below:

On Thu, Sep 22, 2011 at 4:43 PM, Dave Wootton <dwootton@xxxxxxxxxx> wrote:
John, Roland
I'm trying to get a URI for a file that is in a synchronized project using the following code

                        location = null;
                        try {
                                if (project.getNature(RemoteSyncNature.NATURE_ID) != null) {
                                        IManagedBuildInfo buildInfo;
                                        buildInfo = ManagedBuildManager.getBuildInfo(project);
                                        if (buildInfo != null) {
                                                IConfiguration config;

                                                config = buildInfo.getDefaultConfiguration();
                                                if (config != null) {
                                                        BuildScenario build;
                                                        IRemoteConnection connection;

                                                        build = BuildConfigurationManager.getInstance()
                                                                        .getBuildScenarioForBuildConfiguration(
                                                                                        config);
                                                        connection = build.getRemoteConnection();
                                                        location = connection
                                                                        .getRemoteServices()
                                                                        .getFileManager(connection)
                                                                        .toURI(new Path(file.getLocation().toString()));
                                                }
                                        }
                                } else {
                                        location = file.getLocationURI();
                                }
                        } catch (CoreException e) {

                        }

I'm starting with an IFile object named 'file' which I'm getting from an IStructuredSelection object where the user has right clicked on a file in the synchronized project and clicked my menu entry in the popup menu.
When the project is a synchronized project, location ends up being set to null where the toURI method is returning null for the Path it is given.

file.getLocation.toString() is returning the full path to the requested file on the local system, not the remote system, so it looks like the toURI method is failing somewhere in translating this to a remote system URI.
This is correct behavior, I think, because the selected file is a local file. For a sync project, files exist both in the local workspace and on one or more remote sites.
 

Is this the correct way to get the remote file URI or should I be doing this differently?
Yes, this is the correct procedure in general. We plan to add an API or some other way to access this data, which is being tracked as bug 357291, but this should do for now. Note that project explorer displays only the local files. Normally, these files also exist remotely, but this is not guaranteed. Certain files, such as binaries created locally or Eclipse .cproject and .project files, do not exist on the remote side. So your code should be prepared for this case.

Also, I understand that ManagedBuildManager.getBuildInfo() returns null if this is not a CDT project. Is this a correct assumption if the project is a FORTRAN project or are FORTRAN projects not supported at this time?
All sync projects, including sync FORTRAN projects, are CDT projects, so this function should never return null.

I'm getting warnings complaining about discouraged access due to access restrictions for RemoteSyncNature.NATUREID, BuildConfigurationManager.getBuildScenarioForBuildConfiguration, BuildConfigurationManager.getInstance, BuildScenario.getRemoteConnection and the classes BuildConfigurationManager, BuildScenario, and RemoteSyncNature. Are these warnings anything that means I will have problems with this code?
No, this is by design. We allow other packages access but with the understanding that this is not supported API, hence the reason for bug 357291.

If you would like me to look at the code again and help test it once it is implemented, just let me know.


Thanks
John

Thanks
Dave
_______________________________________________
ptp-dev mailing list
ptp-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ptp-dev



Back to the top