1 11 package org.eclipse.pde.internal.core; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.osgi.service.resolver.BundleDescription; 17 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 18 import org.eclipse.pde.core.plugin.IFragmentModel; 19 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 20 import org.eclipse.pde.core.plugin.IPluginModelBase; 21 import org.eclipse.pde.core.plugin.PluginRegistry; 22 23 24 public class PDEStateHelper { 25 26 34 public static BundleDescription[] getImportedByFragments(BundleDescription root) { 35 BundleDescription[] fragments = root.getFragments(); 36 List list = new ArrayList (); 37 for (int i = 0; i < fragments.length; i++) { 38 if (fragments[i].isResolved()) { 39 BundleDescription[] toAdd = getImportedBundles(fragments[i]); 40 for (int j = 0; j < toAdd.length; j++) { 41 if (!list.contains(toAdd[j])) 42 list.add(toAdd[j]); 43 } 44 } 45 } 46 BundleDescription[] result = new BundleDescription[list.size()]; 47 return (BundleDescription[]) list.toArray(result); 48 } 49 50 58 public static BundleDescription[] getImportedBundles(BundleDescription root) { 59 if (root == null) 60 return new BundleDescription[0]; 61 ExportPackageDescription[] packages = root.getResolvedImports(); 62 ArrayList resolvedImports = new ArrayList (packages.length); 63 for (int i = 0; i < packages.length; i++) 64 if (!root.getLocation().equals(packages[i].getExporter().getLocation()) 65 && !resolvedImports.contains(packages[i].getExporter())) 66 resolvedImports.add(packages[i].getExporter()); 67 return (BundleDescription[]) resolvedImports.toArray(new BundleDescription[resolvedImports.size()]); 68 } 69 70 public static IPluginExtensionPoint findExtensionPoint(String fullID) { 71 if (fullID == null || fullID.length() == 0) 72 return null; 73 int lastDot = fullID.lastIndexOf('.'); 75 if (lastDot == -1) 76 return null; 77 String pluginID = fullID.substring(0, lastDot); 78 IPluginModelBase model = PluginRegistry.findModel(pluginID); 79 if (model == null) 80 return PDEManager.findExtensionPoint(fullID); 81 String pointID = fullID.substring(lastDot + 1); 82 IPluginExtensionPoint[] points = model.getPluginBase().getExtensionPoints(); 83 for (int i = 0; i < points.length; i++) { 84 IPluginExtensionPoint point = points[i]; 85 if (point.getId().equals(pointID)) 86 return point; 87 } 88 IFragmentModel[] fragments = PDEManager.findFragmentsFor(model); 89 for (int i = 0; i < fragments.length; i++) { 90 points = fragments[i].getPluginBase().getExtensionPoints(); 91 for (int j = 0; j < points.length; j++) 92 if (points[j].getId().equals(pointID)) 93 return points[j]; 94 } 95 return PDEManager.findExtensionPoint(fullID); 96 } 97 98 } 99 | Popular Tags |