/**
   * Tests that an exported package removal in the PDE model is reflected in the workspace api
   * baseline
   */
  public void testWPUpdateExportPackageRemoved() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project);

    // add package
    assertTestPackage(
        project,
        new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute(),
        "export1");

    setPackageToApi(project, "export1");
    IApiAnnotations annot =
        getTestProjectApiDescription().resolveAnnotations(Factory.packageDescriptor("export1"));
    assertNotNull("there must be an annotation for the new exported package", annot);
    assertTrue(
        "the newly exported package must be API visibility",
        annot.getVisibility() == VisibilityModifiers.API);

    // remove exported packages
    IBundleProjectService service = ProjectUtils.getBundleProjectService();
    IBundleProjectDescription description = service.getDescription(project.getProject());
    description.setPackageExports(null);
    description.apply(null);

    // check the API description
    annot = getTestProjectApiDescription().resolveAnnotations(Factory.packageDescriptor("export1"));
    assertNotNull("should still be an annotation for the package", annot);
    assertTrue(
        "unexported package must be private", VisibilityModifiers.isPrivate(annot.getVisibility()));
  }
 /**
  * Removes the given package from the exported packages header, if it exists.
  *
  * <p>This method is not safe to use in a head-less manner.
  *
  * @param project the project to remove the package from
  * @param packagename the name of the package to remove from the export package header
  */
 public static void removeExportedPackage(IProject project, String packagename)
     throws CoreException {
   IBundleProjectDescription description = getBundleProjectService().getDescription(project);
   IPackageExportDescription[] exports = description.getPackageExports();
   if (exports != null) {
     List<IPackageExportDescription> list = new ArrayList<IPackageExportDescription>();
     for (int i = 0; i < exports.length; i++) {
       if (!packagename.equals(exports[i].getName())) {
         list.add(exports[i]);
       }
     }
     if (list.size() < exports.length) {
       description.setPackageExports(
           (IPackageExportDescription[]) list.toArray(new IPackageExportDescription[list.size()]));
       description.apply(null);
     }
   }
 }
 /**
  * Adds a new exported package to the manifest.
  *
  * <p>This method is not safe to use in a head-less manner.
  *
  * @param project the project to get the manifest information from
  * @param packagename the fully qualified name of the package to add
  * @param internal if the added package should be internal or not
  * @param friends a listing of friends for this exported package
  * @throws CoreException if something bad happens
  */
 public static void addExportedPackage(
     IProject project, String packagename, boolean internal, String[] friends)
     throws CoreException {
   if (!project.exists() || packagename == null) {
     // do no work
     return;
   }
   IBundleProjectService service = getBundleProjectService();
   IBundleProjectDescription description = service.getDescription(project);
   IPackageExportDescription[] exports = description.getPackageExports();
   List<IPackageExportDescription> list = new ArrayList<IPackageExportDescription>();
   if (exports != null) {
     for (int i = 0; i < exports.length; i++) {
       list.add(exports[i]);
     }
   }
   list.add(service.newPackageExport(packagename, null, !internal, friends));
   description.setPackageExports(
       (IPackageExportDescription[]) list.toArray(new IPackageExportDescription[list.size()]));
   description.apply(null);
   AbstractApiTest.waitForAutoBuild();
 }