Eclipse插件:获取源包的安装位置

时间:2011-09-21 09:05:44

标签: eclipse osgi

我正在创建一个IClasspathContainer,它使用eclipse访问已安装的OSGi Bundle(Eclipse插件)。我通过

获得了捆绑的IPath
    Bundle bundle = Platform.getBundle(pluginId);
    fullPath = FileLocator.getBundleFile(
    return Path.fromOSString(fullPath);bundle).getAbsolutePath();

但是,如果安装了源包,我也想提供源代码。源包由eclipse命名,例如对于插件 org.example.myplugin ,源包名为 org.example.myplugin.source

有人知道如何访问源包吗?

1 个答案:

答案 0 :(得分:1)

没有直接的方法可以通过它的符号名称找到OSGi包,但是可以通过循环遍历所有包来轻松地完成它。

    BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
    String requestedName = bundleContext.getProperty(Constants.BUNDLE_SYMBOLICNAME) + ".source";
    Bundle sourceBundle = null;
    for(Bundle bundle : bundleContext.getBundles())
    {
        String name = bundle.getBundleContext().getProperty(Constants.BUNDLE_SYMBOLICNAME);
        if(name != null && name.equals(requestedName))
        {
            sourceBundle = bundle;
            break;
        }
    }

可以通过以下方式访问捆绑包的位置:

        sourceBundle.getLocation();
相关问题