1 11 package org.eclipse.pde.internal.ui.views.dependencies; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.osgi.service.resolver.BaseDescription; 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.ImportPackageSpecification; 21 import org.eclipse.pde.core.plugin.IPluginModelBase; 22 import org.osgi.framework.Constants; 23 24 public class CalleesContentProvider extends DependenciesViewPageContentProvider { 25 private BundleDescription fFragmentDescription; 26 27 public CalleesContentProvider(DependenciesView view) { 28 super(view); 29 } 30 31 protected Object [] findCallees(IPluginModelBase model) { 32 BundleDescription desc = model.getBundleDescription(); 33 if (desc == null) 34 return new Object [0]; 35 fFragmentDescription = null; 36 HostSpecification spec = desc.getHost(); 37 if (spec != null) { 38 fFragmentDescription = desc; 39 Object [] fragmentDependencies = getDependencies(desc); 40 BaseDescription host = spec.getSupplier(); 41 if (host instanceof BundleDescription) { 42 BundleDescription hostDesc = (BundleDescription)host; 43 for (int i = 0; i < fragmentDependencies.length; i++) { 45 BundleDescription dependency = null; 46 if (fragmentDependencies[i] instanceof BundleSpecification) 47 dependency = ((BundleSpecification)fragmentDependencies[i]).getBundle(); 48 else if (fragmentDependencies[i] instanceof ImportPackageSpecification) { 49 ExportPackageDescription epd = (ExportPackageDescription)((ImportPackageSpecification)fragmentDependencies[i]).getSupplier(); 50 if (epd != null) 51 dependency = epd.getSupplier(); 52 } 53 if (dependency != null && dependency.equals(hostDesc)) 54 return fragmentDependencies; 55 } 56 57 Object [] result = new Object [fragmentDependencies.length + 1]; 59 result[0] = hostDesc; 60 System.arraycopy(fragmentDependencies, 0, result, 1, fragmentDependencies.length); 61 return result; 62 } 63 return fragmentDependencies; 64 } 65 return getDependencies(desc); 66 } 67 68 protected Object [] findCallees(BundleDescription desc) { 69 if (desc == null) 70 return new Object [0]; 71 return getDependencies(desc); 72 } 73 74 private Object [] getDependencies(BundleDescription desc) { 75 HashMap dependencies = new HashMap (); 79 BundleSpecification[] requiredBundles = desc.getRequiredBundles(); 80 for (int i = 0; i < requiredBundles.length; i++) { 81 BaseDescription bd = requiredBundles[i].getSupplier(); 82 if (bd != null) 83 dependencies.put(bd, requiredBundles[i]); 84 else 85 dependencies.put(requiredBundles[i], requiredBundles[i]); 86 } 87 ImportPackageSpecification[] importedPkgs = desc.getImportPackages(); 88 for (int i = 0; i < importedPkgs.length; i++) { 89 BaseDescription bd = importedPkgs[i].getSupplier(); 90 if (bd != null && bd instanceof ExportPackageDescription) { 91 BundleDescription exporter = ((ExportPackageDescription)bd).getExporter(); 92 if (exporter != null) { 93 Object obj = dependencies.get(exporter); 94 if (obj == null) { 95 dependencies.put(exporter, importedPkgs[i]); 96 } else if (!Constants.RESOLUTION_OPTIONAL.equals(importedPkgs[i].getDirective(Constants.RESOLUTION_DIRECTIVE)) 97 && obj instanceof ImportPackageSpecification && 98 Constants.RESOLUTION_OPTIONAL.equals(((ImportPackageSpecification)obj).getDirective(Constants.RESOLUTION_DIRECTIVE))) { 99 dependencies.put(exporter, importedPkgs[i]); 102 } 103 } 104 } 105 } 107 BundleDescription frags[] = desc.getFragments(); 109 for (int i = 0; i < frags.length; i++) { 110 if (!frags[i].equals(fFragmentDescription)) 111 dependencies.put(frags[i], frags[i]); 112 } 113 return dependencies.values().toArray(); 114 } 115 116 } 117 | Popular Tags |