Using P2 to find "All Plugins that depend somehow on Plugin X" [message #506378] |
Thu, 07 January 2010 11:06 |
|
Hi,
I'm running some API analysis to create some statistics for classes of a given plugin. For instance, I would like to provide the information which methods are typically overridden by subclasses of a given framework class etc. See http://code.google.com/p/code-recommenders/wiki/ExtendedAPID ocs for illustration.
Since I'm analysing a rather large amount of code for these statistics I want to speedup my analysis a little bit. What I want to achieve is the following:
Given a bundle id like org.eclipse.jface, I want to find all bundles / jars that have a dependency to org.eclipse.jface, i.e., may use or extend (directly or indirectly) a class of the JFace framework. With this information I could minimize the number of jars to scan for example classes.
My question is: Can I use p2 to discover such dependencies? If yes, can you provide me some hints how to achieve that?
Thanks in advance,
Marcel
|
|
|
Re: Using P2 to find "All Plugins that depend somehow on Plugin X" [message #506464 is a reply to message #506378] |
Thu, 07 January 2010 15:43 |
|
Hi,
I made some progress. However, the internals of p2 are still challenging. So far I managed to access the installable units and to read out their direct dependencies (as shown below). However, the indirect dependencies are not resolved yet. Is there a utility method or class that traverses the IUs to see whether a dependency can be resolved by the current metadatarepositories? Something I can directly reuse for my needs? Or should I implement this from scratch?
Thank You.
Marcel
final File repoPath = new File("D:/repository");
final NullProgressMonitor monitor = new NullProgressMonitor();
final IMetadataRepository metaRep = ProvisioningUtil.loadMetadataRepository(repoPath.toURI(),
monitor);
final Collector collector = new Collector();
metaRep.query(new MatchQuery()
{
@Override
public boolean isMatch(final Object candidate)
{
return candidate instanceof IInstallableUnit;
}
}, collector, monitor);
for (final IInstallableUnit iu : (Collection<IInstallableUnit>) collector.toCollection())
{
final IRequiredCapability[] metaRequiredCapabilities = iu.getMetaRequiredCapabilities();
final IRequiredCapability[] requiredCapabilities = iu.getRequiredCapabilities();
for (final IRequiredCapability cap : requiredCapabilities)
{
final String name = cap.getName();
// works for direct dependencies declared inside the manifest file only:
if ("org.eclipse.swt".equals(name))
{
System.out.println("requires swt:" + iu);
break;
}
}
System.out.println("");
}
|
|
|
Powered by
FUDForum. Page generated in 0.03315 seconds