Index: src/java/com/shelter/eclipse/plugin/ivy/classpath/IvyClasspathContainerInitializer.java =================================================================== --- src/java/com/shelter/eclipse/plugin/ivy/classpath/IvyClasspathContainerInitializer.java (revision 0) +++ src/java/com/shelter/eclipse/plugin/ivy/classpath/IvyClasspathContainerInitializer.java (revision 0) @@ -0,0 +1,118 @@ +package com.shelter.eclipse.plugin.ivy.classpath; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.ClasspathContainerInitializer; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; + +/** + * @since November 15, 2007 + * @author Jon Schneider + */ +public class IvyClasspathContainerInitializer extends + ClasspathContainerInitializer +{ +// private final String containerId = "com.shelter.eclipse.plugin.ivy.IvyPlugin.IVY_CLASSPATH_CONTAINER"; + private final String inheritedContainerId = "com.shelter.eclipse.plugin.ivy.IvyPlugin.IVY_INHERITED_CLASSPATH_CONTAINER"; + + private final static Map/**/ INITIALIZED = new HashMap/**/(); + + /** + * @see org.eclipse.jdt.core.ClasspathContainerInitializer#canUpdateClasspathContainer(org.eclipse.core.runtime.IPath, + * org.eclipse.jdt.core.IJavaProject) + */ + public boolean canUpdateClasspathContainer(IPath path, IJavaProject project) + { + return true; + } + + /** + * @see org.eclipse.jdt.core.ClasspathContainerInitializer#initialize(org.eclipse.core.runtime.IPath, + * org.eclipse.jdt.core.IJavaProject) + */ + public void initialize(IPath path, IJavaProject project) + throws CoreException + { + ProjectContainerPath containerPath = new ProjectContainerPath(path, + project); + + if (!INITIALIZED.containsKey(containerPath)) + { + boolean isInheritedContainer = path.equals(new Path( + inheritedContainerId)); + + try + { + IClasspathContainer existingContainer = JavaCore + .getClasspathContainer(path, project); + IvyClasspathContainer newContainer = null; + + if (existingContainer == null) + { + newContainer = new IvyClasspathContainer(isInheritedContainer); + } + else + { + newContainer = new IvyClasspathContainer(path, existingContainer + .getClasspathEntries(), isInheritedContainer); + } + + JavaCore.setClasspathContainer(path, + new IJavaProject[] { project }, + new IClasspathContainer[] { newContainer }, + new NullProgressMonitor()); + + INITIALIZED.put(containerPath, containerPath); + + } + catch (JavaModelException e) + { + System.out.println(e); + } + } + } + + private static class ProjectContainerPath + { + private final IPath _path; + private final IJavaProject _project; + + public ProjectContainerPath(IPath path, IJavaProject project) + { + _path = path; + _project = project; + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() + { + return _path.hashCode() + _project.hashCode(); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object o) + { + if (o instanceof ProjectContainerPath) + { + ProjectContainerPath thatContainerPath = (ProjectContainerPath) o; + + return thatContainerPath._path.equals(_path) + && thatContainerPath._project.equals(_project); + } + + return false; + } + } +}