|
13 | 13 |
|
14 | 14 | import java.util.ArrayList; |
15 | 15 | import java.util.List; |
| 16 | +import java.util.Objects; |
16 | 17 | import java.util.logging.Level; |
17 | 18 | import java.util.logging.Logger; |
18 | 19 | import java.util.stream.Collectors; |
19 | 20 |
|
20 | 21 | import org.eclipse.core.runtime.CoreException; |
21 | 22 | import org.eclipse.core.runtime.IStatus; |
22 | 23 | import org.eclipse.core.runtime.Status; |
| 24 | +import org.eclipse.jdt.core.IClasspathAttribute; |
| 25 | +import org.eclipse.jdt.core.IClasspathEntry; |
23 | 26 | import org.eclipse.jdt.core.IJavaElement; |
24 | 27 | import org.eclipse.jdt.core.IJavaProject; |
25 | 28 | import org.eclipse.jdt.core.search.IJavaSearchConstants; |
|
29 | 32 | import org.eclipse.jdt.core.search.SearchParticipant; |
30 | 33 | import org.eclipse.jdt.core.search.SearchPattern; |
31 | 34 | import org.eclipse.jdt.core.search.SearchRequestor; |
| 35 | +import org.eclipse.jdt.launching.IRuntimeClasspathEntry; |
32 | 36 | import org.eclipse.jdt.launching.JavaRuntime; |
33 | 37 |
|
34 | 38 | import com.microsoft.java.debug.core.Configuration; |
@@ -162,12 +166,45 @@ private static String[][] computeClassPath(IJavaProject javaProject) throws Core |
162 | 166 | } |
163 | 167 | String[][] result = new String[2][]; |
164 | 168 | if (JavaRuntime.isModularProject(javaProject)) { |
165 | | - result[0] = JavaRuntime.computeDefaultRuntimeClassPath(javaProject); |
| 169 | + result[0] = computeDefaultRuntimeClassPath(javaProject); |
166 | 170 | result[1] = new String[0]; |
167 | 171 | } else { |
168 | 172 | result[0] = new String[0]; |
169 | | - result[1] = JavaRuntime.computeDefaultRuntimeClassPath(javaProject); |
| 173 | + result[1] = computeDefaultRuntimeClassPath(javaProject); |
170 | 174 | } |
171 | 175 | return result; |
172 | 176 | } |
| 177 | + |
| 178 | + private static String[] computeDefaultRuntimeClassPath(IJavaProject jproject) throws CoreException { |
| 179 | + IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(jproject); |
| 180 | + List<String> resolved = new ArrayList<>(unresolved.length); |
| 181 | + for (int i = 0; i < unresolved.length; i++) { |
| 182 | + IRuntimeClasspathEntry entry = unresolved[i]; |
| 183 | + if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) { |
| 184 | + IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject); |
| 185 | + for (int j = 0; j < entries.length; j++) { |
| 186 | + if (entries[j].getClasspathEntry().getPath().equals(jproject.getOutputLocation())) { |
| 187 | + continue; |
| 188 | + } |
| 189 | + if (isTest(entries[j].getClasspathEntry())) { |
| 190 | + continue; |
| 191 | + } |
| 192 | + String location = entries[j].getLocation(); |
| 193 | + if (location != null) { |
| 194 | + resolved.add(location); |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + } |
| 199 | + return resolved.toArray(new String[resolved.size()]); |
| 200 | + } |
| 201 | + |
| 202 | + private static boolean isTest(final IClasspathEntry classpathEntry) { |
| 203 | + for (final IClasspathAttribute classpathAttribute : classpathEntry.getExtraAttributes()) { |
| 204 | + if (Objects.equals(classpathAttribute.getName(), "test")) { |
| 205 | + return Objects.equals(classpathAttribute.getValue(), "true"); |
| 206 | + } |
| 207 | + } |
| 208 | + return false; |
| 209 | + } |
173 | 210 | } |
0 commit comments