Bug 88330 - Need access into the API
Summary: Need access into the API
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3   Edit
Assignee: PDE-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2005-03-17 10:12 EST by Richard Kulp CLA
Modified: 2007-10-31 13:47 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Kulp CLA 2005-03-17 10:12:36 EST
There is a big push to get rid of usage of internal classes. In the PDE we use
three internal classes to get access to the API classes. The three classes are:

>>> PDECore.getDefault().getModelManager().getFragments()

We use the model manager to get all of the fragment models. Actually we are
looking only for the fragments for a specific plugin, but I don't see an API for
that. We're interested in all of the fragments, whether they are projects with
code, projects with binary, or referenced through the target platform. From the
fragment model we can see if it is a project or not (using
getUnderlyingResource) and get the imports and libraries of the fragment.

>>>
PDECore.getDefault().getWorkspaceModelManager().getWorkspacePluginModel(IProject)

We use the workspace modelmanager to ask for the plugin model for a project.
From that we can get its IPlugin and from that we can get its IPluginImports.

>>> PDECore.getDefault().findPlugin(id, version, match);

We use this to find the plugin model. 

We use the API for the other requests. The problem is there is no API to get
down to the actual API.

Thanks,
Rich
Comment 1 Wassim Melhem CLA 2005-03-17 10:29:43 EST
There are a lot of methods on PluginModelManager and PDECore that would be 
useful to those who care about plugins.

We need to revisit these two classes and come up with a good set of APIs.

Unfortunately, it's too late for this work in the 3.1 cycle.
Comment 2 Jeff McAffer CLA 2005-03-17 11:02:13 EST
Especially on these classes as they may very well change based on bundles etc.
Comment 3 Wassim Melhem CLA 2005-03-17 11:05:05 EST
absolutely.  I will clean up the internal implementation to be as close to 
100% state-based as possible for 3.1, and kick back during the summer months 
and come up with APIs.
Comment 4 Wassim Melhem CLA 2005-06-03 07:34:27 EDT
resolving to later.
Comment 5 Tod Creasey CLA 2007-08-10 08:52:07 EDT
reopening. Please consider for 3.4.
Comment 6 Brian Bauman CLA 2007-08-10 10:09:39 EDT
The request for the 3 functions below can actually already be satisfied by the PluginRegistry API class.  There might not be a specific function in our API, but I will explain how to satisfy each.

>>> PDECore.getDefault().getModelManager().getFragments()
"Actually we are looking only for the fragments for a specific plugin, but I don't see an API for that."

There is a better way that interating through fragments :)

IPluginModelBase base = PluginRegistry.findModel(String id);
BundleDescription desc = base.getBundleDescription()
BundleDescription[] frags = desc.getFragments();
ArrayList fragmentModels = new ArrayList(frags.length);
for (int i = 0; i < frags.length; i++) {
   IPluginModelBase fragment = PluginRegistry.findModel(frags[i]);
   if (fragment != null)
      fragmentModels.add(fragmentModels);
}
// Now all the fragments for your specific plug-in are in the ArrayList 'fragmentModels'


>>> PDECore.getDefault().getWorkspaceModelManager().getWorkspacePluginModel(IProject)

Use PluginRegistry.findModel(IProject)


>>> PDECore.getDefault().findPlugin(id, version, match);

This one you are going to have to work for a little bit.  Let's say you have a String id and a String version.

ModelEntry entry = PluginRegistry.findEntry(id);
IPluginModelBase[] models = entry.getWorkspaceModels();
for (int i = 0; i < models.length(); i++) {
   if (isMatch(models[i], version, match))
      return models[i];
}
IPluginModelBase[] models = entry.getExternalModels();
for (int i = 0; i < models.length(); i++) {
   if (isMatch(models[i], version, match))
      return models[i];
}

This algorithm is a little more thorough than you may need.  You can try calling ModelEntry.getActiveModels() also.  The way listed above will search not only the active but inactive models also.

Also, you will have to write the isMatch(...) function yourself.  But this should not be very hard, esp. if you are looking for a perfect match.

If you have any questions about any of the functions, please let me know.  Otherwise, I think you should be good to go.
Comment 7 Chris Aniszczyk CLA 2007-08-10 10:58:36 EDT
Also, there's PackageAdmin which may supply you with another way of getting at OSGi related things:

http://www2.osgi.org/javadoc/r4/org/osgi/service/packageadmin/PackageAdmin.html
Comment 8 Tod Creasey CLA 2007-10-31 13:31:52 EDT
Chris and Brian can this be closed then?
Comment 9 Brian Bauman CLA 2007-10-31 13:47:42 EDT
Sounds sufficient to me.  Marking as fixed in 3.3 since that is when we added the PluginRegistry API.