1 11 package org.eclipse.pde.internal.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.core.JavaModelException; 25 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 26 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 27 import org.eclipse.jdt.launching.IVMInstall; 28 import org.eclipse.jdt.launching.JavaRuntime; 29 import org.eclipse.jdt.launching.StandardSourcePathProvider; 30 import org.eclipse.pde.internal.ui.PDEPlugin; 31 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 32 35 public class WorkbenchSourcePathProvider extends StandardSourcePathProvider { 36 39 public IRuntimeClasspathEntry[] computeUnresolvedClasspath( 40 ILaunchConfiguration configuration) throws CoreException { 41 boolean defaultPath = configuration.getAttribute( 42 IJavaLaunchConfigurationConstants.ATTR_DEFAULT_SOURCE_PATH, 43 true); 44 if (!defaultPath) { 45 return recoverRuntimePath(configuration, 46 IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH); 47 } 48 List sourcePath = new ArrayList (); 49 String vmInstallName = configuration.getAttribute( 52 IPDELauncherConstants.VMINSTALL, VMHelper 53 .getDefaultVMInstallName()); 54 IVMInstall[] vmInstallations = VMHelper.getAllVMInstances(); 55 IVMInstall jre = null; 56 for (int i = 0; i < vmInstallations.length; i++) { 57 if (vmInstallName.equals(vmInstallations[i].getName())) { 58 jre = vmInstallations[i]; 59 break; 60 } 61 } 62 if (jre != null) { 63 IPath containerPath = new Path(JavaRuntime.JRE_CONTAINER); 65 containerPath = containerPath 66 .append(jre.getVMInstallType().getId()); 67 containerPath = containerPath.append(jre.getName()); 68 IRuntimeClasspathEntry entry = JavaRuntime 69 .newRuntimeContainerClasspathEntry(containerPath, 70 IRuntimeClasspathEntry.BOOTSTRAP_CLASSES); 71 sourcePath.add(entry); 72 } 73 IProject[] projects = getJavaProjects(configuration); 74 for (int i = 0; i < projects.length; i++) { 75 sourcePath.add(JavaRuntime 76 .newProjectRuntimeClasspathEntry(JavaCore.create(projects[i]))); 77 } 78 return (IRuntimeClasspathEntry[]) sourcePath 79 .toArray(new IRuntimeClasspathEntry[sourcePath.size()]); 80 } 81 84 private IProject[] getJavaProjects(ILaunchConfiguration configuration) 85 throws CoreException { 86 IProject[] projects = LaunchPluginValidator.getAffectedProjects(configuration); 87 return PDEPlugin.getWorkspace().computeProjectOrder(projects).projects; 88 } 89 93 public IRuntimeClasspathEntry[] resolveClasspath( 94 IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration) 95 throws CoreException { 96 List all = new ArrayList (entries.length); 97 for (int i = 0; i < entries.length; i++) { 98 if (entries[i].getType() == IRuntimeClasspathEntry.PROJECT) { 99 all.add(entries[i]); 102 IResource resource = entries[i].getResource(); 104 if (resource instanceof IProject) { 105 IJavaProject project = JavaCore.create((IProject) resource); 106 IPackageFragmentRoot[] roots = project 107 .getPackageFragmentRoots(); 108 for (int j = 0; j < roots.length; j++) { 109 if (roots[j].getKind() == IPackageFragmentRoot.K_BINARY && !isJRELibrary(roots[j])) { 110 IRuntimeClasspathEntry rte = JavaRuntime 111 .newArchiveRuntimeClasspathEntry(roots[j] 112 .getPath()); 113 IPath path = roots[j].getSourceAttachmentPath(); 114 if (path != null) { 115 rte.setSourceAttachmentPath(path); 116 rte.setSourceAttachmentRootPath(roots[j] 117 .getSourceAttachmentRootPath()); 118 } 119 if (!all.contains(rte)) 120 all.add(rte); 121 } 122 } 123 } 124 } else { 125 IRuntimeClasspathEntry[] resolved = JavaRuntime 126 .resolveRuntimeClasspathEntry(entries[i], configuration); 127 for (int j = 0; j < resolved.length; j++) { 128 all.add(resolved[j]); 129 } 130 } 131 } 132 return (IRuntimeClasspathEntry[]) all 133 .toArray(new IRuntimeClasspathEntry[all.size()]); 134 } 135 private boolean isJRELibrary(IPackageFragmentRoot root) { 136 try { 137 IPath path = root.getRawClasspathEntry().getPath(); 138 if (path.equals(new Path(JavaRuntime.JRE_CONTAINER)) 139 || path.equals(new Path(JavaRuntime.JRELIB_VARIABLE))) { 140 return true; 141 } 142 } catch (JavaModelException e) { 143 } 144 return false; 145 } 146 } 147 | Popular Tags |