Search in sources :

Example 36 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project webtools.servertools by eclipse.

the class ModuleTraverser method getRawComponentClasspathDependencies.

/*
	 * Derived from ClasspathDependencyUtil.getRawComponentClasspathDependencies()
	 */
private static Map getRawComponentClasspathDependencies(final IJavaProject javaProject) throws CoreException {
    if (javaProject == null) {
        return Collections.EMPTY_MAP;
    }
    final Map<IClasspathEntry, IClasspathAttribute> referencedRawEntries = new HashMap<IClasspathEntry, IClasspathAttribute>();
    final IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (int i = 0; i < entries.length; i++) {
        final IClasspathEntry entry = entries[i];
        final IClasspathAttribute attrib = checkForComponentDependencyAttribute(entry, DEPENDECYATTRIBUTETYPE_CLASSPATH_COMPONENT_DEPENDENCY);
        if (attrib != null) {
            referencedRawEntries.put(entry, attrib);
        }
    }
    return referencedRawEntries;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 37 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute in project liferay-ide by liferay.

the class LiferayGradleProject method _createResorcesFolder.

private IFolder _createResorcesFolder(IProject project) {
    try {
        IJavaProject javaProject = JavaCore.create(project);
        List<IClasspathEntry> existingRawClasspath;
        existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());
        List<IClasspathEntry> newRawClasspath = new ArrayList<>();
        IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute("FROM_GRADLE_MODEL", "true") };
        IClasspathEntry resourcesEntry = JavaCore.newSourceEntry(project.getFullPath().append("src/main/resources"), new IPath[0], new IPath[0], null, attributes);
        for (IClasspathEntry entry : existingRawClasspath) {
            newRawClasspath.add(entry);
        }
        if (!existingRawClasspath.contains(resourcesEntry)) {
            newRawClasspath.add(resourcesEntry);
        }
        javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), new NullProgressMonitor());
        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        IFolder[] sourceFolders = getSourceFolders();
        for (IFolder folder : sourceFolders) {
            if (folder.getName().equals("resources")) {
                return folder;
            }
        }
    } catch (CoreException ce) {
        GradleCore.logError(ce);
    }
    return null;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IFolder(org.eclipse.core.resources.IFolder)

Example 38 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute 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 39 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute 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 40 with IClasspathAttribute

use of org.eclipse.jdt.core.IClasspathAttribute 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

IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)52 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)37 IPath (org.eclipse.core.runtime.IPath)26 ArrayList (java.util.ArrayList)17 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 Path (org.eclipse.core.runtime.Path)11 HashMap (java.util.HashMap)9 CoreException (org.eclipse.core.runtime.CoreException)9 IAccessRule (org.eclipse.jdt.core.IAccessRule)9 File (java.io.File)6 LinkedHashMap (java.util.LinkedHashMap)6 IProject (org.eclipse.core.resources.IProject)6 Map (java.util.Map)5 IFolder (org.eclipse.core.resources.IFolder)5 Bundle (org.osgi.framework.Bundle)5 Iterator (java.util.Iterator)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 URL (java.net.URL)3 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)3