コード例 #1
0
  protected IClasspathEntry createClasspathEntry(
      IPath entryPath, IPath sourcePath, String javadocURL) {
    IPath sourceRootPath = null;
    IAccessRule[] rules = new IAccessRule[] {};
    IClasspathAttribute[] attrs = new IClasspathAttribute[] {};

    final ClasspathDecorations dec =
        cpDecorations.getDecorations(
            getDecorationManagerKey(javaProject.getProject(), getPath().toString()),
            entryPath.toString());

    if (dec != null) {
      sourcePath = dec.getSourceAttachmentPath();
      sourceRootPath = dec.getSourceAttachmentRootPath();
      attrs = dec.getExtraAttributes();
    }

    if (javadocURL != null) {
      if (CoreUtil.empty(attrs)) {
        attrs = new IClasspathAttribute[] {newJavadocAttr(javadocURL)};
      } else {
        List<IClasspathAttribute> newAttrs = new ArrayList<IClasspathAttribute>();

        for (IClasspathAttribute attr : attrs) {
          if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attr.getName())) {
            newAttrs.add(newJavadocAttr(javadocURL));
          } else {
            newAttrs.add(attr);
          }
        }

        attrs = newAttrs.toArray(new IClasspathAttribute[0]);
      }
    }

    return JavaCore.newLibraryEntry(entryPath, sourcePath, sourceRootPath, rules, attrs, false);
  }
コード例 #2
0
  @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);
    }
  }