1 11 package org.eclipse.jdt.launching; 12 13 14 import java.util.Collections ; 15 import java.util.Iterator ; 16 import java.util.LinkedHashSet ; 17 import java.util.List ; 18 import java.util.Set ; 19 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.debug.core.ILaunchConfiguration; 22 import org.eclipse.jdt.core.IJavaProject; 23 24 31 public class StandardClasspathProvider implements IRuntimeClasspathProvider { 32 33 36 public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException { 37 boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); 38 if (useDefault) { 39 IJavaProject proj = JavaRuntime.getJavaProject(configuration); 40 IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(configuration); 41 if (proj == null) { 42 if (jreEntry == null) { 44 return new IRuntimeClasspathEntry[0]; 45 } 46 return new IRuntimeClasspathEntry[]{jreEntry}; 47 } 48 IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(proj); 49 IRuntimeClasspathEntry projEntry = JavaRuntime.computeJREEntry(proj); 51 if (jreEntry != null && projEntry != null) { 52 if (!jreEntry.equals(projEntry)) { 53 for (int i = 0; i < entries.length; i++) { 54 IRuntimeClasspathEntry entry = entries[i]; 55 if (entry.equals(projEntry)) { 56 entries[i] = jreEntry; 57 return entries; 58 } 59 } 60 } 61 } 62 return entries; 63 } 64 return recoverRuntimePath(configuration, IJavaLaunchConfigurationConstants.ATTR_CLASSPATH); 66 } 67 68 71 public IRuntimeClasspathEntry[] resolveClasspath(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration) throws CoreException { 72 Set all = new LinkedHashSet (entries.length); 74 for (int i = 0; i < entries.length; i++) { 75 IRuntimeClasspathEntry[] resolved =JavaRuntime.resolveRuntimeClasspathEntry(entries[i], configuration); 76 for (int j = 0; j < resolved.length; j++) { 77 all.add(resolved[j]); 78 } 79 } 80 return (IRuntimeClasspathEntry[])all.toArray(new IRuntimeClasspathEntry[all.size()]); 81 } 82 83 94 protected IRuntimeClasspathEntry[] recoverRuntimePath(ILaunchConfiguration configuration, String attribute) throws CoreException { 95 List entries = configuration.getAttribute(attribute, Collections.EMPTY_LIST); 96 IRuntimeClasspathEntry[] rtes = new IRuntimeClasspathEntry[entries.size()]; 97 Iterator iter = entries.iterator(); 98 int i = 0; 99 while (iter.hasNext()) { 100 rtes[i] = JavaRuntime.newRuntimeClasspathEntry((String )iter.next()); 101 i++; 102 } 103 return rtes; 104 } 105 106 } 107 | Popular Tags |