Search in sources :

Example 1 with ClasspathDecorations

use of org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations in project liferay-ide by liferay.

the class PluginClasspathContainer method createClasspathEntry.

protected IClasspathEntry createClasspathEntry(IPath entryPath, IPath sourceLocation, String javadocURL) {
    IPath sourceRootPath = null;
    IPath sourcePath = null;
    IAccessRule[] rules = {};
    IClasspathAttribute[] attrs = new IClasspathAttribute[0];
    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 (ListUtil.isEmpty(attrs)) {
            attrs = new IClasspathAttribute[] { newJavadocAttr(javadocURL) };
        } else {
            List<IClasspathAttribute> newAttrs = new ArrayList<>();
            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]);
        }
    }
    if ((sourcePath == null) && (sourceLocation != null)) {
        sourcePath = sourceLocation;
    }
    return JavaCore.newLibraryEntry(entryPath, sourcePath, sourceRootPath, rules, attrs, false);
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ClasspathDecorations(org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 2 with ClasspathDecorations

use of org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations in project liferay-ide by liferay.

the class PluginClasspathContainerInitializer method requestClasspathContainerUpdate.

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
    String key = PluginClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());
    IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
    cpDecorations.clearAllDecorations(key);
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        IPath srcpath = entry.getSourceAttachmentPath();
        IPath srcrootpath = entry.getSourceAttachmentRootPath();
        IClasspathAttribute[] attrs = entry.getExtraAttributes();
        if ((srcpath != null) || ListUtil.isNotEmpty(attrs)) {
            String eid = entry.getPath().toString();
            ClasspathDecorations dec = new ClasspathDecorations();
            dec.setSourceAttachmentPath(srcpath);
            dec.setSourceAttachmentRootPath(srcrootpath);
            dec.setExtraAttributes(attrs);
            cpDecorations.setDecorations(key, eid, dec);
        }
    }
    cpDecorations.save();
    IPath portalDir = null;
    String javadocURL = null;
    IPath sourceLocation = null;
    if (containerSuggestion instanceof PluginClasspathContainer) {
        portalDir = ((PluginClasspathContainer) containerSuggestion).getPortalDir();
        javadocURL = ((PluginClasspathContainer) containerSuggestion).getJavadocURL();
        sourceLocation = ((PluginClasspathContainer) containerSuggestion).getSourceLocation();
    } else {
        portalDir = ServerUtil.getPortalDir(project);
        try {
            ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project.getProject());
            if (liferayRuntime != null) {
                javadocURL = liferayRuntime.getJavadocURL();
                sourceLocation = liferayRuntime.getSourceLocation();
            }
        } catch (Exception e) {
            ProjectCore.logError(e);
        }
    }
    if (portalDir != null) {
        IClasspathContainer newContainer = getCorrectContainer(containerPath, containerPath.segment(1), project, portalDir, javadocURL, sourceLocation);
        IJavaProject[] projects = { project };
        IClasspathContainer[] containers = { newContainer };
        JavaCore.setClasspathContainer(containerPath, projects, containers, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) CoreException(org.eclipse.core.runtime.CoreException) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) ClasspathDecorations(org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 3 with ClasspathDecorations

use of org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations in project liferay-ide by liferay.

the class SDKClasspathContainerInitializer method requestClasspathContainerUpdate.

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
    String key = SDKClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());
    IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
    cpDecorations.clearAllDecorations(key);
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        IPath srcpath = entry.getSourceAttachmentPath();
        IPath srcrootpath = entry.getSourceAttachmentRootPath();
        IClasspathAttribute[] attrs = entry.getExtraAttributes();
        if ((srcpath != null) || ListUtil.isNotEmpty(attrs)) {
            String eid = entry.getPath().toString();
            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[] bundleDependencyJarPaths = null;
    PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());
    boolean containerChanged = true;
    if (containerSuggestion instanceof SDKClasspathContainer) {
        portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir();
        bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir();
        portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir();
        javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL();
        sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation();
        bundleDependencyJarPaths = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath();
        if ((bundle != null) && bundle.getAppServerPortalDir().equals(portalDir)) {
            containerChanged = false;
        }
    }
    if (containerChanged == true) {
        if (bundle == null) {
            return;
        }
        portalDir = bundle.getAppServerPortalDir();
        portalGlobalDir = bundle.getAppServerLibGlobalDir();
        bundleDependencyJarPaths = bundle.getBundleDependencyJars();
    }
    IPath[] sdkDependencyPaths = _getSDKDependencies(project);
    if ((portalDir != null) && (portalGlobalDir != null)) {
        IClasspathContainer newContainer = new SDKClasspathContainer(containerPath, project, portalDir, javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleDependencyJarPaths, sdkDependencyPaths);
        IJavaProject[] projects = { project };
        IClasspathContainer[] containers = { newContainer };
        JavaCore.setClasspathContainer(containerPath, projects, containers, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) ClasspathDecorations(org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Aggregations

IPath (org.eclipse.core.runtime.IPath)3 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)3 ClasspathDecorations (org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations)3 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)1 PortalBundle (com.liferay.ide.server.core.portal.PortalBundle)1 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAccessRule (org.eclipse.jdt.core.IAccessRule)1