Skip to content

Commit 70c70a5

Browse files
authored
fix #111: Should not include test classes in classpaths (#202)
* fix #111: Should not include test classes in classpaths when auto resolve maven project
1 parent 011465f commit 70c70a5

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/ResolveClasspathsHandler.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.jdt.core.search.SearchParticipant;
3030
import org.eclipse.jdt.core.search.SearchPattern;
3131
import org.eclipse.jdt.core.search.SearchRequestor;
32+
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
3233
import org.eclipse.jdt.launching.JavaRuntime;
3334

3435
import com.microsoft.java.debug.core.Configuration;
@@ -162,12 +163,34 @@ private static String[][] computeClassPath(IJavaProject javaProject) throws Core
162163
}
163164
String[][] result = new String[2][];
164165
if (JavaRuntime.isModularProject(javaProject)) {
165-
result[0] = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
166+
result[0] = computeDefaultRuntimeClassPath(javaProject);
166167
result[1] = new String[0];
167168
} else {
168169
result[0] = new String[0];
169-
result[1] = JavaRuntime.computeDefaultRuntimeClassPath(javaProject);
170+
result[1] = computeDefaultRuntimeClassPath(javaProject);
170171
}
171172
return result;
172173
}
174+
175+
private static String[] computeDefaultRuntimeClassPath(IJavaProject jproject) throws CoreException {
176+
IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(jproject);
177+
List<String> resolved = new ArrayList<>(unresolved.length);
178+
for (int i = 0; i < unresolved.length; i++) {
179+
IRuntimeClasspathEntry entry = unresolved[i];
180+
if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
181+
IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject);
182+
for (int j = 0; j < entries.length; j++) {
183+
184+
if (entries[j].getClasspathEntry().isTest()) {
185+
continue;
186+
}
187+
String location = entries[j].getLocation();
188+
if (location != null) {
189+
resolved.add(location);
190+
}
191+
}
192+
}
193+
}
194+
return resolved.toArray(new String[resolved.size()]);
195+
}
173196
}

0 commit comments

Comments
 (0)