1 11 package org.eclipse.pde.ui.launcher; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.Path; 20 import org.eclipse.debug.core.ILaunchConfiguration; 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.IPackageFragmentRoot; 23 import org.eclipse.jdt.core.JavaCore; 24 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 25 import org.eclipse.jdt.launching.IVMInstall; 26 import org.eclipse.jdt.launching.JavaRuntime; 27 import org.eclipse.jdt.launching.StandardSourcePathProvider; 28 import org.eclipse.pde.internal.core.util.PDEJavaHelper; 29 import org.eclipse.pde.internal.ui.PDEPlugin; 30 import org.eclipse.pde.internal.ui.launcher.LaunchPluginValidator; 31 import org.eclipse.pde.internal.ui.launcher.VMHelper; 32 33 40 public class PDESourcePathProvider extends StandardSourcePathProvider { 41 42 public static final String ID = "org.eclipse.pde.ui.workbenchClasspathProvider"; 44 48 public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException { 49 List sourcePath = new ArrayList (); 50 sourcePath.add(getJREEntry(configuration)); 51 IProject[] projects = getJavaProjects(configuration); 52 for (int i = 0; i < projects.length; i++) { 53 sourcePath.add(JavaRuntime.newProjectRuntimeClasspathEntry(JavaCore.create(projects[i]))); 54 } 55 return (IRuntimeClasspathEntry[]) sourcePath.toArray(new IRuntimeClasspathEntry[sourcePath.size()]); 56 } 57 58 68 private IRuntimeClasspathEntry getJREEntry(ILaunchConfiguration configuration) throws CoreException { 69 IVMInstall jre = VMHelper.createLauncher(configuration); 70 IPath containerPath = new Path(JavaRuntime.JRE_CONTAINER); 71 containerPath = containerPath.append(jre.getVMInstallType().getId()); 72 containerPath = containerPath.append(jre.getName()); 73 return JavaRuntime.newRuntimeContainerClasspathEntry(containerPath, IRuntimeClasspathEntry.BOOTSTRAP_CLASSES); 74 } 75 76 88 private IProject[] getJavaProjects(ILaunchConfiguration configuration) throws CoreException { 89 IProject[] projects = LaunchPluginValidator.getAffectedProjects(configuration); 90 return PDEPlugin.getWorkspace().computeProjectOrder(projects).projects; 91 } 92 93 97 public IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration) 98 throws CoreException { 99 List all = new ArrayList (entries.length); 100 for (int i = 0; i < entries.length; i++) { 101 if (entries[i].getType() == IRuntimeClasspathEntry.PROJECT) { 102 all.add(entries[i]); 105 IResource resource = entries[i].getResource(); 107 if (resource instanceof IProject) { 108 addBinaryPackageFragmentRoots(JavaCore.create((IProject)resource), all); 109 } 110 } else { 111 IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveRuntimeClasspathEntry(entries[i], configuration); 112 for (int j = 0; j < resolved.length; j++) { 113 all.add(resolved[j]); 114 } 115 } 116 } 117 return (IRuntimeClasspathEntry[]) all.toArray(new IRuntimeClasspathEntry[all.size()]); 118 } 119 120 131 private void addBinaryPackageFragmentRoots(IJavaProject jProject, List all) throws CoreException { 132 IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots(); 133 for (int j = 0; j < roots.length; j++) { 134 if (roots[j].getKind() == IPackageFragmentRoot.K_BINARY && !PDEJavaHelper.isJRELibrary(roots[j])) { 135 IRuntimeClasspathEntry rte = JavaRuntime.newArchiveRuntimeClasspathEntry(roots[j].getPath()); 136 IPath path = roots[j].getSourceAttachmentPath(); 137 if (path != null) { 138 rte.setSourceAttachmentPath(path); 139 rte.setSourceAttachmentRootPath(roots[j].getSourceAttachmentRootPath()); 140 } 141 if (!all.contains(rte)) 142 all.add(rte); 143 } 144 } 145 146 } 147 } | Popular Tags |