[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Re: .043 Plugin.getDefault().getDescriptor().getInstallURL().getFile() does not work

The current return value is correct.  The value given back from
getInstalURL() is an "eclipse" url.  The syntax of an eclipse URL is
    eclipse:/plugin/<plugin name here>
(note the absence of an 's' in 'plugin').  Saying getFile() to that result
does the normal Java thing and returns the part after the protocol (i.e.,
plugin/<plugin name>).

The semantics of getFile() of a URL are specific to the protocol handler for
that URL.  In this case, the eclipse URL handler does not publish any
semantics for the returned value.  Much like saying getFile() to na http URL
which points at a servlet etc.  Client-side interpretation of the getFile()
value is tenuous at best.  The role of the eclipse URL is to isolate the
platform and tools running on the platform from the reality of where things
actually are.  This allows for enormous flexibility in runtime
configurations.

So let me ask you why you are trying to use this code pattern?

If you are trying to get access to files included with your plugin, check
out
    Plugin.openStream()
This API gives you read access to your plugin's files.

If you need some scratch space for temporary working files, or to store
preferences etc, see
    Plugin.getStateLocation()
    Platform.getPluginStateLocation()
This gives you the path to spot in the metadata area of the workspace which
is reserved exclusively for your plugin.  You can create, read, write files
and directories as needed.

Finally, if for some reason you absolutely must have the "raw" URL which
points to the install directory of your plugin, STOP. Think about it first.
In general, plugins can be installed anywhere including on remote HTTP
servers.  All of the files etc required to run the plugin are accessed via
URLs. Further, you cannot assume that you can write to these install
locations.  For example, enterprise installs will likely have shared plugin
directories and will not allow people to write there.  There are very very
few cases where you will actually need/want to use anything other than the
above functionality.

In those rare cases, the Platform provides two additional methods
    Platform.asLocalURL()
    Platform.resolve()
asLocalURL() fetches the content of whatever it was you wanted and caches it
locally.  The return value is a "file" URL.  The second simply returns the
given eclipse URL into the raw form (e.g., http:, file:, ...) as
appropriate.

Think hard about using these methods (especially the latter).  Doing so may
well render your plugin useless in many install scenarios.

Jeff


"Ilya Rozenberg" <irozenberg@xxxxxxxxxxxx> wrote in message
news:9b836e$bq7$1@xxxxxxxxxxxxxxxx
> Plugin.getDefault().getDescriptor().getInstallURL().getFile()
> returns
> plugin\<plugin name here>
> should be
> plugins\<plugin name here>
>
>