OSGi and Maven detect use of private package

一笑奈何 提交于 2019-12-09 13:28:10

问题


I'm starting a project writing OSGi bundle and using Maven as the build management tool. My understanding is for an OSGi bundle you can choose which package you would like to keep private/public.

Here is the question:

  • If I am depending on a bundle that declares com.example package as exported package and declares com.example.internal as private package, is there any way, during build time, to detect use of com.example.internal (build should fail)?

It would be awesome if that can be detected during development time by Eclipse, but I highly doubt it can.


回答1:


One option is to use Eclipse's Plugin Development Environment (PDE), an OSGi-aware set of tools. It won't let you compile against internal packages, so it gives you the development-time checking. Unlike maven's bundle plugin, it's manifest-first rather than code first, which isn't to everyone's taste.

To integrate PDE with Maven, the best bet is to use the Maven Tycho plugin. This gives you a fully OSGi-aware compilation stage in Maven.




回答2:


In think you will find a lot of support for this in bnd(tools). In general, I find these culprits by watching the Import-Package statement, which is nicely visualized in bndtools. There is some support in bnd(tools) to generate warnings/errors when an import package has no import range, which happen when you import a private or non-existent package.



来源:https://stackoverflow.com/questions/10954288/osgi-and-maven-detect-use-of-private-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!