@@ -70,6 +70,9 @@ public class ResolveClasspathsHandler {
7070 */
7171 public String [][] resolveClasspaths (List <Object > arguments ) throws Exception {
7272 try {
73+ if (arguments .size () == 3 ) {
74+ return computeClassPath ((String ) arguments .get (0 ), (String ) arguments .get (1 ), (String ) arguments .get (2 ));
75+ }
7376 return computeClassPath ((String ) arguments .get (0 ), (String ) arguments .get (1 ));
7477 } catch (CoreException e ) {
7578 logger .log (Level .SEVERE , "Failed to resolve classpath: " + e .getMessage (), e );
@@ -159,6 +162,23 @@ public void acceptSearchMatch(SearchMatch match) {
159162 * CoreException
160163 */
161164 private static String [][] computeClassPath (String mainClass , String projectName ) throws CoreException {
165+ return computeClassPath (mainClass , projectName , null );
166+ }
167+
168+ /**
169+ * Accord to the project name and the main class, compute runtime classpath.
170+ *
171+ * @param mainClass
172+ * fully qualified class name
173+ * @param projectName
174+ * project name
175+ * @param scope
176+ * scope of the classpath
177+ * @return class path
178+ * @throws CoreException
179+ * CoreException
180+ */
181+ private static String [][] computeClassPath (String mainClass , String projectName , String scope ) throws CoreException {
162182 IJavaProject project = null ;
163183 // if type exists in multiple projects, debug configuration need provide
164184 // project name.
@@ -179,6 +199,12 @@ private static String[][] computeClassPath(String mainClass, String projectName)
179199 project = projects .get (0 );
180200 }
181201
202+ if ("test" .equals (scope )) {
203+ return computeClassPath (project , mainClass , false /*excludeTestCode*/ , Collections .EMPTY_LIST );
204+ } else if ("runtime" .equals (scope )) {
205+ return computeClassPath (project , mainClass , true /*excludeTestCode*/ , Collections .EMPTY_LIST );
206+ }
207+
182208 IJavaElement testElement = findMainClassInTestFolders (project , mainClass );
183209 List <IResource > mappedResources = (testElement != null && testElement .getResource () != null )
184210 ? Arrays .asList (testElement .getResource ()) : Collections .EMPTY_LIST ;
@@ -275,7 +301,7 @@ public void acceptSearchMatch(SearchMatch match) {
275301
276302 private static class JavaApplicationLaunchConfiguration extends LaunchConfiguration {
277303 public static final String JAVA_APPLICATION_LAUNCH = "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" no\" ?>\n "
278- + "<launchConfiguration type=\" org.eclipse.jdt.launching.localJavaApplication \" >\n "
304+ + "<launchConfiguration type=\" %s \" >\n "
279305 + "<listAttribute key=\" org.eclipse.debug.core.MAPPED_RESOURCE_PATHS\" >\n "
280306 + "</listAttribute>\n "
281307 + "<listAttribute key=\" org.eclipse.debug.core.MAPPED_RESOURCE_TYPES\" >\n "
@@ -302,7 +328,18 @@ protected JavaApplicationLaunchConfiguration(IProject project, String mainType,
302328 } else if (ProjectUtils .isGradleProject (project )) {
303329 classpathProvider = "org.eclipse.buildship.core.classpathprovider" ;
304330 }
305- this .launchInfo = new JavaLaunchConfigurationInfo (JAVA_APPLICATION_LAUNCH );
331+
332+ // Since MavenRuntimeClasspathProvider will only including test entries when:
333+ // 1. Launch configuration is JUnit/TestNG type
334+ // 2. Mapped resource is in test path.
335+ // That's why we use JUnit launch configuration here to make sure the result is right when excludeTestCode is false.
336+ String launchXml = null ;
337+ if (!excludeTestCode && mappedResources .isEmpty ()) {
338+ launchXml = String .format (JAVA_APPLICATION_LAUNCH , "org.eclipse.jdt.junit.launchconfig" );
339+ } else {
340+ launchXml = String .format (JAVA_APPLICATION_LAUNCH , "org.eclipse.jdt.launching.localJavaApplication" );
341+ }
342+ this .launchInfo = new JavaLaunchConfigurationInfo (launchXml );
306343 }
307344
308345 @ Override
0 commit comments