[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.jdt] Re: API for finding the plugin providing a given class?

Stephan,
sorry but JDT (Compiler/JavaBuilder) doesn't know of plugins. Plugins are generally Equinox/OSGI or PDE responsibility, depending if you want to manipulate some runtime, or develop plugins. If you have an instance of class, then you can find bundle implementing it by using org.osgi.service.packageadmin.PackageAdmin
Following is an example:


Class myclass = ...
BundleContext context = Activator.getBundleContext();
ServiceReference packageAdminRef = context.getServiceReference(PackageAdmin.class.getName());
PackageAdmin packageAdmin = null;
if (packageAdminRef != null) {
packageAdmin = (PackageAdmin) context.getService(packageAdminRef);
if (packageAdmin != null) {
Bundle bundle = packageAdmin.getBundle(myclass);
System.out.println("class "+myclass+" comes from "+bundle.getSymbolicName());
}
}


If you don't have an instance, then there is a bit problem, because many plugins can define classes of the same names. So i think the best you can do is to ask all plugins if they can resolve class for name, that you have and then ask this class from which plugin it comes.

Stephan Herrmann wrote:
Hi,

In order to implement checking of custom access rules I need to find out
which plug-in actually provides a given resolved class.
This behavior shall be plugged into the JavaBuilder and/or the Compiler.
It seems the required information is not available at any single point.
- a JavaProject knows its RequiredPluginsClasspathContainer but already here
 the list of required bundles is flattened into a list of classpath entries.
- any class resolution operates on this flattened classpath, with no reverse
 link to the providing plug-in.

Is there any API that would answer such a question? To illustrate the question, the following signature would be perfect for my task:
/**
* @param compoundName fully qualified name of a class
* @return the symbolic name of a plug-in exporting the given class
*/
String JavaProject.findDeclaringPlugin(char[][] compoundName)


Of course similar API could be used to provide the same information.

thanks for any hints,
Stephan