I'd like to modify a classpath container initialised by another plug-in. Specifically, I'd like to filter/remove certain classpath entries in the "Android Dependencies" classpath container initialized by the Eclipse Android Development Tools plug-in (ADT).
Currently I'm "modifying" the contents by creating a new classpath container, copying the entries I'm interested from the original Android classpath container and then deleting the original:
final IPath path = new Path(AdtConstants.CONTAINER_LIBRARIES);
IClasspathContainer container = findClasspathContainer(classpath, path, project);
MavenLibrariesClasspathContainer newContainer = new MavenLibrariesClasspathContainer("Android Dependencies", path);
for(IClasspathEntry entry : container.getClasspathEntries()) {
if(!entry.getPath().toOSString().contains(File.separator + "libs" + File.separator)) {
newContainer.addClasspathEntry(entry);
}
}
classpath.removeEntry(path);
JavaCore.setClasspathContainer(
new Path("me.gladwell.eclipse.m2e.android.LIBRARIES"),
new IJavaProject[] { project },
new IClasspathContainer[] { newContainer },
new NullProgressMonitor()
);
However, this is buggy and causes the Eclipse workspace to be (temporarily) broken and looks ugly when Eclipse is restarted.
Is there a more seamless way I can remove classpath entries from a classpath container perhaps without having to delete the whole classpath container and replace it?