Plugin location

Is there a "proper" way to find the path to the plugin installation directory at runtime?

Will this be the way to go?

PluginManager.getPlugin(PluginId.getId("myplugin")).getPath()

7 comments
Comment actions Permalink

Hi Anton,

Have you tried PluginClass.class.getProtectionDomain().getCodeSource().getLocation() ?

Regards, Denis

0
Comment actions Permalink

Tried it now, thx. Gives the same result as if I used PluginManager

0
Comment actions Permalink

Don't have better answer at the moment then.

Btw, why would you need that information?

Denis

0
Comment actions Permalink

I'd like to refer a file in the plugin installation.

Let's say I have a plugin structure:


C:/Users/anton/.IntelliJIDEAx0

    plugins

        Sample

            lib

                             - plugin.jar
                             - agent.jar


then, the plugin should set a system property for a Java process automatically (already done), e.g.:

java -javaagent:C:/users/anton.IntelliJIDEAx0/plugins/Sample/lib/agent.jar

0
Comment actions Permalink

What is returned by ...CodeSource().getLocation() and PluginManager.getPlugin(PluginId.getId("myplugin")).getPath() ? null?

You can get path to the root plugins dir via PathManager.getPluginsPath() then and manually filter your plugin data there.

Denis

0
Comment actions Permalink

PluginManager.getPlugin(PluginId.getId("myplugin")).getPath() returns the path  - all is fine. Probably I did something wrong at my first tries. thx!

0
Comment actions Permalink

I have this utility method which I most likely got from somewhere in the CE sources. It uses the same technique as in your example.

@Nullable
public static VirtualFile getPluginVirtualDirectory() {
    IdeaPluginDescriptor descriptor = PluginManager.getPlugin(PluginId.getId("Lua"));
    if (descriptor != null) {
        File pluginPath = descriptor.getPath();

        String url = VfsUtil.pathToUrl(pluginPath.getAbsolutePath());

        return VirtualFileManager.getInstance().findFileByUrl(url);
    }

    return null;
}
0

Please sign in to leave a comment.