in org.apache.ivyde.eclipse/src/java/org/apache/ivyde/internal/eclipse/cpcontainer/IvyClasspathInitializer.java [64:162]
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
if (IvyClasspathContainerHelper.isIvyClasspathContainer(containerPath)) {
IvyDEMessage.info("Initializing container " + containerPath);
// try to get an existing one
IClasspathContainer container = null;
try {
container = JavaCore.getClasspathContainer(containerPath, project);
} catch (JavaModelException ex) {
// unless there are issues with the JDT, this should never happen
IvyPlugin.logError("Unable to get container for " + containerPath.toString(), ex);
return;
}
try {
boolean refresh = false;
IvyClasspathContainerImpl ivycp = null;
IClasspathEntry entry = IvyClasspathContainerHelper.getEntry(containerPath,
project);
IClasspathAttribute[] attributes;
if (entry != null) {
attributes = entry.getExtraAttributes();
} else {
attributes = new IClasspathAttribute[0];
}
if (container instanceof IvyClasspathContainerImpl) {
IvyDEMessage.debug("Container already configured");
ivycp = (IvyClasspathContainerImpl) container;
} else {
if (container == null) {
IvyDEMessage.debug("No saved container");
// try what the IvyDE plugin saved
IvyClasspathContainerSerializer serializer = IvyPlugin.getDefault()
.getIvyClasspathContainerSerializer();
Map<IPath, IvyClasspathContainer> containers = serializer.read(project);
if (containers != null) {
IvyDEMessage.debug("Found serialized containers");
ivycp = (IvyClasspathContainerImpl) containers.get(containerPath);
}
if (ivycp == null) {
IvyDEMessage.debug("No serialized containers match the expected container path");
// still bad luck or just a new classpath container
ivycp = new IvyClasspathContainerImpl(project, containerPath,
new IClasspathEntry[0], attributes);
// empty, so force refresh at least
refresh = true;
}
} else {
IvyDEMessage.debug("Loading from a saved container");
// this might be the persisted one : reuse the persisted entries
ivycp = new IvyClasspathContainerImpl(project, containerPath,
container.getClasspathEntries(), attributes);
}
}
// FIXME : container path upgrade removed since it seems to make some trouble:
// containers get either uninitialized or initialized twice...
// recompute the path as it may have been "upgraded"
// IPath updatedPath = IvyClasspathContainerConfAdapter.getPath(ivycp.getConf());
// if (!updatedPath.equals(containerPath)) {
// IvyDEMessage.verbose("Upgrading container path from " + containerPath + " to " +
// updatedPath);
// updateIvyDEContainerPath(project, entry, attributes, exported, updatedPath);
// return;
// }
IvyDEMessage.verbose("Setting container in JDT model");
JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project},
new IClasspathContainer[] {ivycp}, null);
int startupMode = IvyPlugin.getPreferenceStoreHelper().getResolveOnStartup();
if (startupMode == ON_STARTUP_NOTHING) {
if (!refresh) {
IvyDEMessage.verbose("Doing nothing on startup");
// unless we force a refresh, actually do nothing
return;
}
} else {
refresh = startupMode == ON_STARTUP_REFRESH;
}
if (refresh) {
IvyDEMessage.info("Scheduling a refresh of the container");
} else {
IvyDEMessage.info("Scheduling a resolve of the container");
}
// now refresh the container to be synchronized with the ivy.xml
ivycp.launchResolve(refresh, null);
} catch (Exception ex) {
IStatus status = new Status(IStatus.ERROR, IvyPlugin.ID, IStatus.OK,
"Unable to set container for " + containerPath.toString(), ex);
throw new CoreException(status);
}
}
}