@Override public void initialize(IPath containerPath, IJavaProject project) throws CoreException { IClasspathContainer classpathContainer = null; String root = containerPath.segment(0); if (!SDKClasspathContainer.ID.equals(root)) { final String msg = "Invalid plugin classpath container, expecting container root "; //$NON-NLS-1$ throw new CoreException(ProjectCore.createErrorStatus(msg + SDKClasspathContainer.ID)); } PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject()); if (bundle == null) { final String msg = "Invalid sdk properties setting."; throw new CoreException(ProjectCore.createErrorStatus(msg)); } IPath globalDir = bundle.getAppServerLibGlobalDir(); IPath portalDir = bundle.getAppServerPortalDir(); IPath bundleDir = bundle.getAppServerDir(); IPath[] bundleDependencyLibDir = bundle.getBundleDependencyJars(); if (portalDir == null) { return; } classpathContainer = new SDKClasspathContainer( containerPath, project, portalDir, null, null, globalDir, bundleDir, bundleDependencyLibDir); JavaCore.setClasspathContainer( containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {classpathContainer}, null); }
@Override public void requestClasspathContainerUpdate( IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException { final String key = SDKClasspathContainer.getDecorationManagerKey( project.getProject(), containerPath.toString()); final IClasspathEntry[] entries = containerSuggestion.getClasspathEntries(); cpDecorations.clearAllDecorations(key); for (int i = 0; i < entries.length; i++) { final IClasspathEntry entry = entries[i]; final IPath srcpath = entry.getSourceAttachmentPath(); final IPath srcrootpath = entry.getSourceAttachmentRootPath(); final IClasspathAttribute[] attrs = entry.getExtraAttributes(); if (srcpath != null || attrs.length > 0) { final String eid = entry.getPath().toString(); final ClasspathDecorations dec = new ClasspathDecorations(); dec.setSourceAttachmentPath(srcpath); dec.setSourceAttachmentRootPath(srcrootpath); dec.setExtraAttributes(attrs); cpDecorations.setDecorations(key, eid, dec); } } cpDecorations.save(); IPath portalDir = null; IPath portalGlobalDir = null; String javadocURL = null; IPath sourceLocation = null; IPath bundleDir = null; IPath[] bundleLibDependencyPath = null; if (containerSuggestion instanceof SDKClasspathContainer) { portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir(); bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir(); portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir(); javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL(); sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation(); bundleLibDependencyPath = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath(); } else { PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject()); if (bundle == null) { final String msg = "Invalid sdk properties setting."; throw new CoreException(ProjectCore.createErrorStatus(msg)); } portalDir = bundle.getAppServerPortalDir(); portalGlobalDir = bundle.getAppServerLibGlobalDir(); bundleLibDependencyPath = bundle.getBundleDependencyJars(); } if (portalDir != null && portalGlobalDir != null) { IClasspathContainer newContainer = new SDKClasspathContainer( containerPath, project, portalDir, javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleLibDependencyPath); JavaCore.setClasspathContainer( containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {newContainer}, null); } }