1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.jdt.core.ClasspathContainerInitializer; 16 import org.eclipse.jdt.core.IClasspathContainer; 17 import org.eclipse.jdt.core.IJavaProject; 18 import org.eclipse.jdt.core.JavaCore; 19 import org.eclipse.jdt.internal.core.util.Util; 20 21 24 public class UserLibraryClasspathContainerInitializer extends ClasspathContainerInitializer { 25 26 29 public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) { 30 return isUserLibraryContainer(containerPath); 31 } 32 33 36 public Object getComparisonID(IPath containerPath, IJavaProject project) { 37 return containerPath; 38 } 39 40 43 public String getDescription(IPath containerPath, IJavaProject project) { 44 if (isUserLibraryContainer(containerPath)) { 45 return containerPath.segment(1); 46 } 47 return super.getDescription(containerPath, project); 48 } 49 50 public void initialize(IPath containerPath, IJavaProject project) throws CoreException { 51 if (isUserLibraryContainer(containerPath)) { 52 String userLibName = containerPath.segment(1); 53 UserLibrary userLibrary = JavaModelManager.getUserLibraryManager().getUserLibrary(userLibName); 54 if (userLibrary != null) { 55 UserLibraryClasspathContainer container = new UserLibraryClasspathContainer(userLibName); 56 JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null); 57 } else if (JavaModelManager.CP_RESOLVE_VERBOSE) { 58 verbose_no_user_library_found(project, userLibName); 59 } 60 } else if (JavaModelManager.CP_RESOLVE_VERBOSE) { 61 verbose_not_a_user_library(project, containerPath); 62 } 63 } 64 65 private boolean isUserLibraryContainer(IPath path) { 66 return path != null && path.segmentCount() == 2 && JavaCore.USER_LIBRARY_CONTAINER_ID.equals(path.segment(0)); 67 } 68 69 72 public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { 73 if (isUserLibraryContainer(containerPath)) { 74 String name = containerPath.segment(1); 75 if (containerSuggestion != null) { 76 JavaModelManager.getUserLibraryManager().setUserLibrary(name, containerSuggestion.getClasspathEntries(), containerSuggestion.getKind() == IClasspathContainer.K_SYSTEM); 77 } else { 78 JavaModelManager.getUserLibraryManager().removeUserLibrary(name); 79 } 80 } 82 } 83 84 private void verbose_no_user_library_found(IJavaProject project, String userLibraryName) { 85 Util.verbose( 86 "UserLibrary INIT - FAILED (no user library found)\n" + " project: " + project.getElementName() + '\n' + " userLibraryName: " + userLibraryName); } 90 91 private void verbose_not_a_user_library(IJavaProject project, IPath containerPath) { 92 Util.verbose( 93 "UserLibrary INIT - FAILED (not a user library)\n" + " project: " + project.getElementName() + '\n' + " container path: " + containerPath); } 97 } 98 | Popular Tags |