/**
   * The fields are populated based on the plug-in attributes. Some fields are set to their default
   * values.
   */
  private FragmentFieldData populateFieldData(IPluginModelBase plugin, Locale locale) {
    FragmentFieldData fragmentData = new FragmentFieldData();

    fragmentData.setId(pluginName(plugin, locale));
    fragmentData.setVersion(DEFAULT_VERSION);
    fragmentData.setMatch(0);

    fragmentData.setPluginId(plugin.getPluginBase().getId());
    fragmentData.setPluginVersion(incrementRelease(plugin.getPluginBase().getVersion()));
    fragmentData.setName(pluginName(plugin, locale) + " Fragment"); // $NON-NLS-1$
    fragmentData.setProvider(EMPTY_STRING);
    fragmentData.setSimple(true);

    if (!(plugin instanceof ExternalPluginModelBase)) {
      fragmentData.setSourceFolderName("src"); // $NON-NLS-1$
      fragmentData.setOutputFolderName("bin"); // $NON-NLS-1$
    }

    fragmentData.setLegacy(false);
    fragmentData.setTargetVersion(
        Double.toString(ensureTargetVersionCompatibility(TargetPlatformHelper.getTargetVersion())));
    fragmentData.setHasBundleStructure(true);
    fragmentData.setOSGiFramework(null);
    fragmentData.setWorkingSets(null);

    return fragmentData;
  }
  /**
   * Tests that resetting the target platform should work OK (i.e. is equivalent to the models in
   * the default target platform).
   *
   * @throws CoreException
   */
  public void testResetTargetPlatform() throws Exception {
    ITargetDefinition definition = getDefaultTargetPlatorm();
    Set urls = getAllBundleURLs(definition);
    Set fragments = new HashSet();
    TargetBundle[] bundles = definition.getBundles();
    for (int i = 0; i < bundles.length; i++) {
      if (bundles[i].isFragment()) {
        fragments.add(new File(bundles[i].getBundleInfo().getLocation()).toURL());
      }
    }

    // current platform
    IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();

    // should be equivalent
    assertEquals("Should have same number of bundles", urls.size(), models.length);
    for (int i = 0; i < models.length; i++) {
      String location = models[i].getInstallLocation();
      URL url = new File(location).toURL();
      assertTrue("Missing plug-in " + location, urls.contains(url));
      if (models[i].isFragmentModel()) {
        assertTrue("Missing fragmnet", fragments.remove(url));
      }
    }
    assertTrue("Different number of fragments", fragments.isEmpty());
  }
  public void createClient(Section section, FormToolkit toolkit) {

    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    section.setLayoutData(data);

    section.setText(PDEUIMessages.IntroSection_sectionText);
    section.setDescription(PDEUIMessages.IntroSection_sectionDescription);

    boolean canCreateNew = TargetPlatformHelper.getTargetVersion() >= NEW_INTRO_SUPPORT_VERSION;

    Composite client = toolkit.createComposite(section);
    client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, canCreateNew ? 3 : 2));
    client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Label label = toolkit.createLabel(client, PDEUIMessages.IntroSection_introLabel, SWT.WRAP);
    GridData td = new GridData();
    td.horizontalSpan = canCreateNew ? 3 : 2;
    label.setLayoutData(td);

    Label introLabel = toolkit.createLabel(client, PDEUIMessages.IntroSection_introInput);
    introLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));

    fIntroCombo = new ComboPart();
    fIntroCombo.createControl(client, toolkit, SWT.READ_ONLY);
    td = new GridData(GridData.FILL_HORIZONTAL);
    fIntroCombo.getControl().setLayoutData(td);
    loadManifestAndIntroIds(false);
    if (fAvailableIntroIds != null) fIntroCombo.setItems(fAvailableIntroIds);
    fIntroCombo.add(""); // $NON-NLS-1$
    fIntroCombo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            handleSelection();
          }
        });

    if (canCreateNew) {
      Button button = toolkit.createButton(client, PDEUIMessages.IntroSection_new, SWT.PUSH);
      button.setEnabled(isEditable());
      button.setLayoutData(new GridData(GridData.FILL));
      button.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              handleNewIntro();
            }
          });
    }

    fIntroCombo.getControl().setEnabled(isEditable());

    toolkit.paintBordersFor(client);
    section.setClient(client);
    // Register to be notified when the model changes
    getModel().addModelChangedListener(this);
  }
 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()]);
 }
  /**
   * Tests setting the target platform to empty.
   *
   * @throws CoreException
   */
  public void testSetEmptyTargetPlatform() throws CoreException {
    try {
      setTargetPlatform(null);

      // current platform
      IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();

      assertEquals("Wrong number of bundles in empty target", 0, models.length);

    } finally {
      resetTargetPlatform();
    }
  }
  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);
  }
  /**
   * Tests setting the target platform to the stored JDT feature test data
   *
   * @throws Exception
   */
  public void testSetTargetPlatformToJdtFeature() throws Exception {
    try {
      // extract the feature
      IPath location = extractModifiedFeatures();
      // org.eclipse.jdt_3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1

      ITargetDefinition target = getNewTarget();
      ITargetLocation container =
          getTargetService()
              .newFeatureLocation(
                  location.toOSString(),
                  "org.eclipse.jdt",
                  "3.6.0.v20100105-0800-7z8VFR9FMTb52_pOyKHhoek1");

      target.setTargetLocations(new ITargetLocation[] {container});

      setTargetPlatform(target);

      List expected = new ArrayList();
      expected.add("org.eclipse.jdt");
      expected.add("org.eclipse.jdt.launching");
      // 2 versions of JUnit
      expected.add("org.junit");
      expected.add("org.junit");
      expected.add("org.junit4");
      if (Platform.getOS().equals(Platform.OS_MACOSX)) {
        expected.add("org.eclipse.jdt.launching.macosx");
      }

      // current platform
      IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels();

      assertEquals("Wrong number of bundles in JDT feature", expected.size(), models.length);
      for (int i = 0; i < models.length; i++) {
        expected.remove(models[i].getPluginBase().getId());
        assertTrue(models[i].isEnabled());
      }
      Iterator iterator = expected.iterator();
      while (iterator.hasNext()) {
        String name = (String) iterator.next();
        System.err.println("Missing: " + name);
      }
      assertTrue("Wrong bundles in target platform", expected.isEmpty());
    } finally {
      resetTargetPlatform();
    }
  }
 private BundleDescription[] getPluginModels() {
   ArrayList list = new ArrayList();
   State state = TargetPlatformHelper.getState();
   IProductPlugin[] plugins = product.getPlugins();
   for (int i = 0; i < plugins.length; i++) {
     BundleDescription bundle = null;
     String v = plugins[i].getVersion();
     if (v != null && v.length() > 0) {
       bundle = state.getBundle(plugins[i].getId(), Version.parseVersion(v));
     }
     // if there's no version, just grab a bundle like before
     if (bundle == null) {
       bundle = state.getBundle(plugins[i].getId(), null);
     }
     if (bundle != null) {
       list.add(bundle);
     }
   }
   Object[] bundleArray = list.toArray(new BundleDescription[list.size()]);
   return (BundleDescription[]) bundleArray;
 }