/**
  * Returns a {@link Set} of bundle ids for the dependents of the given {@link IPluginModelBase}s.
  * The set includes the ids of the given model bases as well as all computed implicit / optional
  * dependencies.
  *
  * @param models the array of {@link IPluginModelBase}s to compute dependencies for
  * @param excludeFragments a collection of <b>fragment</b> bundle symbolic names to exclude from
  *     the dependency resolution or <code>null</code> if none
  * @return a set of bundle IDs
  */
 public static Set<String> getSelfandDependencies(
     IPluginModelBase[] models, String[] excludeFragments) {
   return getDependencies(
       models,
       getImplicitDependencies(),
       TargetPlatformHelper.getState(),
       false,
       true,
       toSet(excludeFragments));
 }
 /**
  * Returns a {@link Set} of bundle ids for the dependents of the given {@link IPluginModelBase}.
  * The set includes the id of the given model base as well as all computed implicit / optional
  * dependencies.
  *
  * @param model the {@link IPluginModelBase} to compute dependencies for
  * @param excludeFragments a collection of <b>fragment</b> bundle symbolic names to exclude from
  *     the dependency resolution or <code>null</code> if none
  * @return a set of bundle IDs
  */
 public static Set<String> getSelfAndDependencies(
     IPluginModelBase model, String[] excludeFragments) {
   return getDependencies(
       new Object[] {model},
       getImplicitDependencies(),
       TargetPlatformHelper.getState(),
       false,
       true,
       toSet(excludeFragments));
 }
 /**
  * Returns a {@link Set} of bundle ids for the dependents of the given objects. The set does not
  * include the ids of the given objects but does include the computed set of implicit
  * dependencies.
  *
  * @param selected selected the group of objects to compute dependencies for. Any items in this
  *     array that are not {@link IPluginModelBase}s are ignored.
  * @param includeOptional if optional bundle ids should be included
  * @param excludeFragments a collection of <b>fragment</b> bundle symbolic names to exclude from
  *     the dependency resolution or <code>null</code> if none
  * @return a set of bundle IDs
  */
 public static Set<String> getDependencies(
     Object[] selected, boolean includeOptional, String[] excludeFragments) {
   return getDependencies(
       selected,
       getImplicitDependencies(),
       TargetPlatformHelper.getState(),
       true,
       includeOptional,
       toSet(excludeFragments));
 }
 private BundleDescription[] getBundles() {
   TreeMap<String, BundleDescription> map = new TreeMap<String, BundleDescription>();
   IProduct product = getProduct();
   BundleDescription[] bundles = TargetPlatformHelper.getState().getBundles();
   for (int i = 0; i < bundles.length; i++) {
     String id = bundles[i].getSymbolicName();
     if (!product.containsPlugin(id)) {
       map.put(id, bundles[i]);
     }
   }
   return map.values().toArray(new BundleDescription[map.size()]);
 }
  public static void handleAddRequired(IProductPlugin[] plugins, boolean includeOptional) {
    if (plugins.length == 0) return;

    ArrayList<BundleDescription> list = new ArrayList<BundleDescription>(plugins.length);
    for (int i = 0; i < plugins.length; i++) {
      list.add(TargetPlatformHelper.getState().getBundle(plugins[i].getId(), null));
    }
    DependencyCalculator calculator = new DependencyCalculator(includeOptional);
    calculator.findDependencies(list.toArray());

    BundleDescription[] bundles = TargetPlatformHelper.getState().getBundles();
    for (int i = 0; i < bundles.length; i++) {
      HostSpecification host = bundles[i].getHost();
      if (host != null
          && !("org.eclipse.ui.workbench.compatibility"
              .equals(bundles[i].getSymbolicName())) // $NON-NLS-1$
          && calculator.containsPluginId(host.getName())) {
        calculator.findDependency(bundles[i]);
      }
    }

    Collection<?> dependencies = calculator.getBundleIDs();

    IProduct product = plugins[0].getProduct();
    IProductModelFactory factory = product.getModel().getFactory();
    IProductPlugin[] requiredPlugins = new IProductPlugin[dependencies.size()];
    int i = 0;
    Iterator<?> iter = dependencies.iterator();
    while (iter.hasNext()) {
      String id = iter.next().toString();
      IProductPlugin plugin = factory.createPlugin();
      plugin.setId(id);
      requiredPlugins[i++] = plugin;
    }
    product.addPlugins(requiredPlugins);
  }