예제 #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 an entry to the bundle class path header
  *
  * @param project the project
  * @param entry the entry to append
  * @throws CoreException
  */
 public static void addBundleClasspathEntry(IProject project, IBundleClasspathEntry entry)
     throws CoreException {
   IBundleProjectDescription description = getBundleProjectService().getDescription(project);
   IBundleClasspathEntry[] classpath = description.getBundleClasspath();
   IBundleClasspathEntry[] next = new IBundleClasspathEntry[classpath.length + 1];
   System.arraycopy(classpath, 0, next, 0, classpath.length);
   next[next.length - 1] = entry;
   description.setBundleClasspath(next);
   description.apply(null);
 }
  /** Tests removing a library from the classpath of a project */
  public void testWPUpdateLibraryRemovedFromClasspath() throws Exception {
    IPath libPath = null;
    try {
      IJavaProject project = getTestingProject();
      assertNotNull("The testing project must exist", project);

      // add to classpath
      IFolder folder = assertTestLibrary(project, new Path("libx"), "component.a_1.0.0.jar");
      IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName());
      assertNotNull("the workspace component must exist", component);
      int before = component.getApiTypeContainers().length;
      libPath = folder.getFullPath().append("component.a_1.0.0.jar");

      // remove classpath entry
      ProjectUtils.removeFromClasspath(project, JavaCore.newLibraryEntry(libPath, null, null));
      waitForAutoBuild();

      // remove from bundle class path
      IBundleProjectService service = ProjectUtils.getBundleProjectService();
      IBundleProjectDescription description = service.getDescription(project.getProject());
      description.setBundleClasspath(
          new IBundleClasspathEntry[] {
            service.newBundleClasspathEntry(new Path(ProjectUtils.SRC_FOLDER), null, null)
          });
      description.apply(null);
      waitForAutoBuild();

      // retrieve updated component
      component = getWorkspaceBaseline().getApiComponent(project.getElementName());
      assertTrue(
          "there must be less containers after the removal",
          before > component.getApiTypeContainers().length);
    } finally {
      if (libPath != null) {
        FileUtils.delete(libPath.toOSString());
      }
    }
  }