コード例 #1
0
  public void testRemoveFromBuildpath01RemoveLibs() throws Exception {
    fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME);

    IPath[] jarPaths =
        new IPath[] {
          JavaProjectHelper.MYLIB.makeAbsolute(), JavaProjectHelper.JUNIT_SRC_381.makeAbsolute()
        };

    CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject);
    BuildpathDelta delta = ClasspathModifier.addExternalJars(jarPaths, cpProject);
    ClasspathModifier.commitClassPath(cpProject, null);

    CPListElement[] toRemove = {delta.getAddedEntries().get(0), delta.getAddedEntries().get(1)};

    delta = ClasspathModifier.removeFromBuildpath(toRemove, cpProject);
    assertDeltaResources(delta, new IPath[0], new IPath[0], new IPath[0], new IPath[0]);
    assertDeltaDefaultOutputFolder(
        delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME));
    assertDeltaRemovedEntries(delta, new IPath[] {toRemove[0].getPath(), toRemove[1].getPath()});
    assertDeltaAddedEntries(delta, new IPath[0]);

    ClasspathModifier.commitClassPath(cpProject, null);

    IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath();
    assertNumberOfEntries(classpathEntries, 1);
  }
コード例 #2
0
 private static void assertDeltaAddedEntries(BuildpathDelta delta, IPath[] paths) {
   List addedEntries = delta.getAddedEntries();
   assertTrue(
       "Expected " + paths.length + " is " + addedEntries.size(),
       addedEntries.size() == paths.length);
   IPath[] added = new IPath[addedEntries.size()];
   int i = 0;
   for (Iterator iterator = addedEntries.iterator(); iterator.hasNext(); ) {
     CPListElement element = (CPListElement) iterator.next();
     added[i] = element.getPath();
     i++;
   }
   for (int j = 0; j < paths.length; j++) {
     assertTrue("Entry " + paths[j] + " was not added", contains(added, paths[j]));
   }
   for (int j = 0; j < added.length; j++) {
     assertTrue("Entry " + added[j] + " was added", contains(paths, added[j]));
   }
 }