1 11 package org.eclipse.pde.internal.core; 12 13 import java.util.Set ; 14 import java.util.StringTokenizer ; 15 import java.util.TreeSet ; 16 17 import org.eclipse.core.runtime.Preferences; 18 import org.eclipse.osgi.service.resolver.BundleDescription; 19 import org.eclipse.osgi.service.resolver.BundleSpecification; 20 import org.eclipse.osgi.service.resolver.ExportPackageDescription; 21 import org.eclipse.osgi.service.resolver.HostSpecification; 22 import org.eclipse.osgi.service.resolver.ImportPackageSpecification; 23 import org.eclipse.osgi.service.resolver.State; 24 import org.eclipse.pde.core.plugin.IPluginExtension; 25 import org.eclipse.pde.core.plugin.IPluginModelBase; 26 import org.osgi.framework.Constants; 27 28 public class DependencyManager { 29 30 34 public static Set getSelfAndDependencies(IPluginModelBase model) { 35 return getDependencies(new Object [] {model}, getImplicitDependencies(), TargetPlatformHelper.getState(), false, true); 36 } 37 38 42 public static Set getSelfandDependencies(IPluginModelBase[] models) { 43 return getDependencies(models, getImplicitDependencies(), TargetPlatformHelper.getState(), false, true); 44 } 45 46 50 public static Set getDependencies(Object [] selected, String [] implicit, State state) { 51 return getDependencies(selected, implicit, state, true, true); 52 } 53 54 58 public static Set getDependencies(Object [] selected, boolean includeOptional) { 59 return getDependencies(selected, getImplicitDependencies(), TargetPlatformHelper.getState(), true, includeOptional); 60 } 61 62 66 private static Set getDependencies(Object [] selected, String [] implicit, State state, boolean removeSelf, boolean includeOptional) { 67 Set set = new TreeSet (); 68 for (int i = 0; i < selected.length; i++) { 69 if (!(selected[i] instanceof IPluginModelBase)) 70 continue; 71 IPluginModelBase model = (IPluginModelBase)selected[i]; 72 addBundleAndDependencies(model.getBundleDescription(), set, includeOptional); 73 IPluginExtension[] extensions = model.getPluginBase().getExtensions(); 74 for (int j = 0; j < extensions.length; j++) { 75 String point = extensions[j].getPoint(); 76 if (point != null) { 77 int dot = point.lastIndexOf('.'); 78 if (dot != -1) { 79 String id = point.substring(0, dot); 80 addBundleAndDependencies(state.getBundle(id, null), set, includeOptional); 81 } 82 } 83 } 84 } 85 86 for (int i = 0; i < implicit.length; i++) { 87 addBundleAndDependencies(state.getBundle(implicit[i], null), set, includeOptional); 88 } 89 90 if (removeSelf) { 91 for (int i = 0; i < selected.length; i++) { 92 if (!(selected[i] instanceof IPluginModelBase)) 93 continue; 94 IPluginModelBase model = (IPluginModelBase)selected[i]; 95 set.remove(model.getPluginBase().getId()); 96 } 97 } 98 return set; 99 } 100 101 private static String [] getImplicitDependencies() { 102 Preferences preferences = PDECore.getDefault().getPluginPreferences(); 103 String dependencies = preferences.getString(ICoreConstants.IMPLICIT_DEPENDENCIES); 104 if (dependencies.length() == 0) 105 return new String [0]; 106 StringTokenizer tokenizer = new StringTokenizer (dependencies, ","); String [] implicitIds = new String [tokenizer.countTokens()]; 108 for (int i = 0; i < implicitIds.length; i++) 109 implicitIds[i] = tokenizer.nextToken(); 110 return implicitIds; 111 } 112 113 private static void addBundleAndDependencies(BundleDescription desc, Set set, boolean includeOptional) { 114 if (desc != null && set.add(desc.getSymbolicName())) { 115 BundleSpecification[] required = desc.getRequiredBundles(); 116 for (int i = 0; i < required.length; i++) { 117 if (includeOptional || !required[i].isOptional()) 118 addBundleAndDependencies((BundleDescription)required[i].getSupplier(), set, includeOptional); 119 } 120 ImportPackageSpecification[] importedPkgs = desc.getImportPackages(); 121 for (int i = 0; i < importedPkgs.length; i++) { 122 ExportPackageDescription exporter = (ExportPackageDescription)importedPkgs[i].getSupplier(); 123 if (exporter == null || (!includeOptional && 125 Constants.RESOLUTION_OPTIONAL.equals(importedPkgs[i].getDirective(Constants.RESOLUTION_DIRECTIVE)))) 126 continue; 127 addBundleAndDependencies(exporter.getExporter(), set, includeOptional); 128 } 129 BundleDescription[] fragments = desc.getFragments(); 130 for (int i = 0; i < fragments.length; i++) { 131 if (!fragments[i].isResolved()) 132 continue; 133 String id = fragments[i].getSymbolicName(); 134 if (!"org.eclipse.ui.workbench.compatibility".equals(id)) addBundleAndDependencies(fragments[i], set, includeOptional); 136 } 137 HostSpecification host = desc.getHost(); 138 if (host != null) 139 addBundleAndDependencies((BundleDescription)host.getSupplier(), set, includeOptional); 140 } 141 } 142 143 144 } 145 | Popular Tags |