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

发布于 2024-12-05 13:37:31 字数 425 浏览 2 评论 0原文

我正在创建一个 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

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

I am creating an IClasspathContainer that access an installed OSGi Bundle (Eclipse Plugin) withing eclipse. I get the IPath for the bundle by

    Bundle bundle = Platform.getBundle(pluginId);
    fullPath = FileLocator.getBundleFile(
    return Path.fromOSString(fullPath);bundle).getAbsolutePath();

However I also want to offer the sources if the source bundle is installed. The source bundle is named by eclipse e.g. for a plugin org.example.myplugin the source bundle is named org.example.myplugin.source.

Does anybody know how to access the source bundle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话墙 2024-12-12 13:37:31

没有直接的方法可以通过符号名称找到 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();

There is no direct way to find an OSGi bundle by it's symbolic name, but one can easily do that oneself by looping through all bundles.

    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;
        }
    }

The location of the bundle can be accessed as:

        sourceBundle.getLocation();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文