2011-09-21 46 views
2

的位置,我創建訪問安裝OSGi包(Eclipse插件)withing日食的IClasspathContainer。我得到的IPATH的束通過Eclipse插件:獲取安裝源代碼包

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

不過我也想提供源是否安裝了源代碼包。源包由eclipse命名,例如一個插件 org.example.myplugin源束被命名 org.example.myplugin.source

有誰知道如何訪問源代碼包?

回答

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(); 
+0

這似乎並沒有工作。沒有源束被'getBundles'返回,至少在我的測試插件(使用Eclipse的JUnit啓動配置中運行)。我是否需要爲該啓動配置添加特別的東西? –