public void testRemoveFromBuildpathBug153299Lib() throws Exception {
    fJavaProject = createProject(null);
    IPackageFragmentRoot p01 =
        JavaProjectHelper.addSourceContainer(fJavaProject, null, new IPath[] {new Path("src1/")});

    CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject);
    IPath[] jarPaths = new IPath[] {JavaProjectHelper.MYLIB.makeAbsolute()};

    ClasspathModifier.addExternalJars(jarPaths, cpProject);
    ClasspathModifier.commitClassPath(cpProject, null);

    cpProject = CPJavaProject.createFromExisting(fJavaProject);

    BuildpathDelta delta =
        ClasspathModifier.removeFromBuildpath(
            new CPListElement[] {
              CPListElement.createFromExisting(p01.getRawClasspathEntry(), fJavaProject)
            },
            cpProject);
    assertDeltaResources(delta, new IPath[0], new IPath[] {}, new IPath[0], new IPath[0]);
    assertDeltaDefaultOutputFolder(delta, fJavaProject.getPath());
    assertDeltaRemovedEntries(delta, new IPath[] {p01.getPath()});
    assertDeltaAddedEntries(delta, new IPath[0]);

    ClasspathModifier.commitClassPath(cpProject, null);

    IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath();
    assertNumberOfEntries(classpathEntries, 2);
  }
  public void testRemoveFromBuildpathBug153299Src() throws Exception {
    fJavaProject = createProject(null);

    // Use the old behavior in order to test the fallback code. Set to ERROR since 3.8.
    fJavaProject.setOption(
        JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE, JavaCore.IGNORE);

    IPackageFragmentRoot p01 =
        JavaProjectHelper.addSourceContainer(fJavaProject, null, new IPath[] {new Path("src1/")});
    JavaProjectHelper.addSourceContainer(fJavaProject, "src1");

    CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject);

    BuildpathDelta delta =
        ClasspathModifier.removeFromBuildpath(
            new CPListElement[] {
              CPListElement.createFromExisting(p01.getRawClasspathEntry(), fJavaProject)
            },
            cpProject);
    assertDeltaResources(delta, new IPath[0], new IPath[] {}, new IPath[0], new IPath[0]);
    assertDeltaDefaultOutputFolder(
        delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME));
    assertDeltaRemovedEntries(delta, new IPath[] {p01.getPath()});
    assertDeltaAddedEntries(delta, new IPath[0]);

    ClasspathModifier.commitClassPath(cpProject, null);

    IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath();
    assertNumberOfEntries(classpathEntries, 2);
  }
  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);
  }
  public void testRemoveFromBuildpath01() throws Exception {
    fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME);
    IPackageFragmentRoot src1 = JavaProjectHelper.addSourceContainer(fJavaProject, "src1");
    IPackageFragmentRoot src2 = JavaProjectHelper.addSourceContainer(fJavaProject, "src2");

    CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject);
    CPListElement[] toRemove = new CPListElement[2];
    toRemove[0] = CPListElement.createFromExisting(src1.getRawClasspathEntry(), fJavaProject);
    toRemove[1] = CPListElement.createFromExisting(src2.getRawClasspathEntry(), fJavaProject);

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

    ClasspathModifier.commitClassPath(cpProject, null);

    IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath();
    assertNumberOfEntries(classpathEntries, 1);
  }
  public void testRemoveFromBuildpath01RemoveProject() throws Exception {
    fJavaProject = createProject(null);
    IPackageFragmentRoot p01 = JavaProjectHelper.addSourceContainer(fJavaProject, null);

    CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject);

    BuildpathDelta delta =
        ClasspathModifier.removeFromBuildpath(
            new CPListElement[] {
              CPListElement.createFromExisting(p01.getRawClasspathEntry(), fJavaProject)
            },
            cpProject);
    assertDeltaResources(delta, new IPath[0], new IPath[] {}, new IPath[0], new IPath[0]);
    assertDeltaDefaultOutputFolder(delta, fJavaProject.getPath());
    assertDeltaRemovedEntries(delta, new IPath[] {p01.getPath()});
    assertDeltaAddedEntries(delta, new IPath[0]);

    ClasspathModifier.commitClassPath(cpProject, null);

    IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath();
    assertNumberOfEntries(classpathEntries, 1);
  }