Search in sources :

Example 1 with IRuntimeClasspathEntry2

use of org.eclipse.jdt.launching.IRuntimeClasspathEntry2 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)

Aggregations

ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 RuntimeClasspathEntry (org.eclipse.jdt.internal.launching.RuntimeClasspathEntry)1 IRuntimeClasspathEntry (org.eclipse.jdt.launching.IRuntimeClasspathEntry)1 IRuntimeClasspathEntry2 (org.eclipse.jdt.launching.IRuntimeClasspathEntry2)1