Search in sources :

Example 21 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.

the class JREContainerInitializer method initialize.

@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
    if (containerPath.segment(0).equals(JRE_CONTAINER)) {
        IClasspathContainer container = new JREContainer(standardVMType, containerPath, project);
        JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null);
    }
}
Also used : IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 22 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project bndtools by bndtools.

the class BndContainerRuntimeClasspathEntryResolver method resolveRuntimeClasspathEntry.

@Override
public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entryToResolve, IJavaProject entryProject) throws CoreException {
    if (entryToResolve == null || entryProject == null) {
        return new IRuntimeClasspathEntry[0];
    }
    final List<IRuntimeClasspathEntry> resolvedRuntimeClasspathEntries = new ArrayList<>();
    final IClasspathContainer container = JavaCore.getClasspathContainer(entryToResolve.getPath(), entryProject);
    if (container == null) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Could not resolve Bnd classpath container", null));
    }
    final IClasspathEntry[] classpathEntries = container.getClasspathEntries();
    List<IJavaProject> projects = resolvingProjects.get();
    Integer count = resolvingCount.get();
    if (projects == null) {
        projects = new ArrayList<>();
        resolvingProjects.set(projects);
        count = 0;
    }
    int intCount = count.intValue();
    intCount++;
    resolvingCount.set(intCount);
    try {
        for (IClasspathEntry classpathEntry : classpathEntries) {
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(classpathEntry.getPath().segment(0));
                final IJavaProject javaProject = JavaCore.create(project);
                if (!projects.contains(javaProject)) {
                    projects.add(javaProject);
                    final IRuntimeClasspathEntry2 defaultProjectClasspathEntry = (IRuntimeClasspathEntry2) JavaRuntime.newDefaultProjectClasspathEntry(javaProject);
                    final IRuntimeClasspathEntry[] projectRuntimeClasspathEntries = defaultProjectClasspathEntry.getRuntimeClasspathEntries(null);
                    for (IRuntimeClasspathEntry projectRuntimeClasspathEntry : projectRuntimeClasspathEntries) {
                        // instead of resolving all output locations we simply just return the project runtime classpath entry itself
                        if (projectRuntimeClasspathEntry.getType() == IRuntimeClasspathEntry.PROJECT) {
                            IResource resource = projectRuntimeClasspathEntry.getResource();
                            if (resource instanceof IProject) {
                                resolvedRuntimeClasspathEntries.add(projectRuntimeClasspathEntry);
                            }
                        } else {
                            IRuntimeClasspathEntry[] resolvedEntries = JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeClasspathEntry, javaProject);
                            for (IRuntimeClasspathEntry resolvedEntry : resolvedEntries) {
                                resolvedRuntimeClasspathEntries.add(resolvedEntry);
                            }
                        }
                    }
                }
            } else {
                final IRuntimeClasspathEntry runtimeClasspathEntry = new RuntimeClasspathEntry(classpathEntry);
                if (!resolvedRuntimeClasspathEntries.contains(runtimeClasspathEntry)) {
                    resolvedRuntimeClasspathEntries.add(runtimeClasspathEntry);
                }
            }
        }
    } finally {
        intCount--;
        if (intCount == 0) {
            resolvingProjects.set(null);
            resolvingCount.set(null);
        } else {
            resolvingCount.set(intCount);
        }
    }
    for (IRuntimeClasspathEntry resolvedRuntimeClasspathEntry : resolvedRuntimeClasspathEntries) {
        resolvedRuntimeClasspathEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
    }
    return resolvedRuntimeClasspathEntries.toArray(new IRuntimeClasspathEntry[0]);
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) RuntimeClasspathEntry(org.eclipse.jdt.internal.launching.RuntimeClasspathEntry) ArrayList(java.util.ArrayList) IRuntimeClasspathEntry2(org.eclipse.jdt.launching.IRuntimeClasspathEntry2) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) IResource(org.eclipse.core.resources.IResource)

Example 23 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project webtools.sourceediting by eclipse.

the class WebContainerInitializer method initialize.

public void initialize(final IPath containerPath, IJavaProject project) throws CoreException {
    if (bundles == null) {
        try {
            IClasspathEntry servlet = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet")).getAbsolutePath()), null, null);
            IClasspathEntry jsp = JavaCore.newLibraryEntry(new Path(FileLocator.getBundleFile(Platform.getBundle("javax.servlet.jsp")).getAbsolutePath()), null, null);
            bundles = new IClasspathEntry[] { servlet, jsp };
        } catch (Exception e) {
            bundles = new IClasspathEntry[0];
            System.err.println("Couldn't find a necessary bundle " + e);
            e.printStackTrace();
            Logger.logException(e);
        }
    }
    IClasspathContainer container = new IClasspathContainer() {

        public IPath getPath() {
            return containerPath;
        }

        public int getKind() {
            return IClasspathContainer.K_APPLICATION;
        }

        public String getDescription() {
            return "JARs for a Java Web Project";
        }

        public IClasspathEntry[] getClasspathEntries() {
            return bundles;
        }
    };
    JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, new NullProgressMonitor());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) CoreException(org.eclipse.core.runtime.CoreException)

Example 24 with IClasspathContainer

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

the class CoreUtil method getClasspathProjects.

public static IProject[] getClasspathProjects(IProject project) {
    List<IProject> retval = new ArrayList<>();
    try {
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] classpathEntries = getClasspathEntries(project);
        for (IClasspathEntry classpathEntry : classpathEntries) {
            if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER) {
                continue;
            }
            IClasspathContainer container = JavaCore.getClasspathContainer(classpathEntry.getPath(), javaProject);
            IClasspathEntry[] containerClasspathEntries = container.getClasspathEntries();
            for (IClasspathEntry containerClasspathEntry : containerClasspathEntries) {
                if (containerClasspathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IResource member = getWorkspaceRoot().findMember(containerClasspathEntry.getPath());
                    if ((member != null) && (member.getType() == IResource.PROJECT)) {
                        retval.add((IProject) member);
                    }
                }
            }
        }
    } catch (JavaModelException jme) {
    }
    return retval.toArray(new IProject[0]);
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 25 with IClasspathContainer

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

Aggregations

IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)34 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)16 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 IPath (org.eclipse.core.runtime.IPath)13 CoreException (org.eclipse.core.runtime.CoreException)10 ClasspathContainerInitializer (org.eclipse.jdt.core.ClasspathContainerInitializer)8 ArrayList (java.util.ArrayList)6 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 Map (java.util.Map)5 IProject (org.eclipse.core.resources.IProject)5 HashMap (java.util.HashMap)4 WeakHashMap (java.util.WeakHashMap)3 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)3 ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)2 PortalBundle (com.liferay.ide.server.core.portal.PortalBundle)2 IResource (org.eclipse.core.resources.IResource)2 IStatus (org.eclipse.core.runtime.IStatus)2 Path (org.eclipse.core.runtime.Path)2 IJavaModelStatus (org.eclipse.jdt.core.IJavaModelStatus)2 ClasspathDecorations (org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations)2