1 11 package org.eclipse.pde.internal.core; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.osgi.service.resolver.BundleDescription; 17 import org.eclipse.osgi.service.resolver.BundleSpecification; 18 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 19 import org.eclipse.osgi.service.resolver.HostSpecification; 20 import org.eclipse.osgi.service.resolver.State; 21 import org.eclipse.pde.core.plugin.IPluginExtension; 22 import org.eclipse.pde.core.plugin.IPluginModelBase; 23 24 public class RequiredDependencyManager { 25 26 public static Set addRequiredPlugins(Object [] selected, String [] implicit, State state) { 27 Set set = new HashSet (); 28 for (int i = 0; i < selected.length; i++) { 29 if (!(selected[i] instanceof IPluginModelBase)) 30 continue; 31 IPluginModelBase model = (IPluginModelBase)selected[i]; 32 addBundleAndDependencies(model.getBundleDescription(), set); 33 IPluginExtension[] extensions = model.getPluginBase().getExtensions(); 34 for (int j = 0; j < extensions.length; j++) { 35 String point = extensions[j].getPoint(); 36 if (point != null) { 37 int dot = point.lastIndexOf('.'); 38 if (dot != -1) { 39 String id = point.substring(0, dot); 40 addBundleAndDependencies(state.getBundle(id, null), set); 41 } 42 } 43 } 44 } 45 46 for (int i = 0; i < implicit.length; i++) { 47 addBundleAndDependencies(state.getBundle(implicit[i], null), set); 48 } 49 50 for (int i = 0; i < selected.length; i++) { 51 if (!(selected[i] instanceof IPluginModelBase)) 52 continue; 53 IPluginModelBase model = (IPluginModelBase)selected[i]; 54 set.remove(model.getPluginBase().getId()); 55 } 56 return set; 57 } 58 59 private static void addBundleAndDependencies(BundleDescription desc, Set set) { 60 if (desc != null && set.add(desc.getSymbolicName())) { 61 BundleSpecification[] required = desc.getRequiredBundles(); 62 for (int i = 0; i < required.length; i++) { 63 addBundleAndDependencies((BundleDescription)required[i].getSupplier(), set); 64 } 65 ExportPackageDescription[] exported = desc.getResolvedImports(); 66 for (int i = 0; i < exported.length; i++) { 67 addBundleAndDependencies(exported[i].getExporter(), set); 68 } 69 BundleDescription[] fragments = desc.getFragments(); 70 for (int i = 0; i < fragments.length; i++) { 71 if (!fragments[i].isResolved()) 72 continue; 73 String id = fragments[i].getSymbolicName(); 74 if (!"org.eclipse.ui.workbench.compatibility".equals(id)) addBundleAndDependencies(fragments[i], set); 76 } 77 HostSpecification host = desc.getHost(); 78 if (host != null) 79 addBundleAndDependencies((BundleDescription)host.getSupplier(), set); 80 } 81 } 82 83 } 84 | Popular Tags |