Пример #1
0
  /**
   * Crate a plug-in project with the given name
   *
   * @param projectName
   * @param additionalNatures
   * @return a new plug-in project
   * @throws CoreException
   */
  public static IJavaProject createPluginProject(String projectName, String[] additionalNatures)
      throws CoreException {
    String[] resolvednatures = additionalNatures;
    if (additionalNatures != null) {
      ArrayList<String> natures = new ArrayList<String>(Arrays.asList(additionalNatures));
      if (!natures.contains(IBundleProjectDescription.PLUGIN_NATURE)) {
        // need to always set this one first, in case others depend on it, like API Tools does
        natures.add(0, IBundleProjectDescription.PLUGIN_NATURE);
      }
      if (!natures.contains(JavaCore.NATURE_ID)) {
        natures.add(0, JavaCore.NATURE_ID);
      }
      resolvednatures = (String[]) natures.toArray(new String[natures.size()]);
    }

    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    IBundleProjectService service = getBundleProjectService();
    IBundleProjectDescription description = service.getDescription(project);
    IBundleClasspathEntry entry =
        service.newBundleClasspathEntry(new Path(SRC_FOLDER), new Path(BIN_FOLDER), null);
    description.setSymbolicName(projectName);
    description.setBundleClasspath(new IBundleClasspathEntry[] {entry});
    description.setNatureIds(resolvednatures);
    description.setBundleVendor("ibm");
    description.setTargetVersion(IBundleProjectDescription.VERSION_3_4);
    description.setExtensionRegistry(true);
    description.setEquinox(true);
    description.setBundleVersion(new Version("1.0.0"));
    description.setExecutionEnvironments(new String[] {"J2SE-1.5"});
    description.apply(null);
    AbstractApiTest.waitForAutoBuild();
    return JavaCore.create(project);
  }
Пример #2
0
 /**
  * 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();
 }