| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,9 @@ public class ResolveClasspathsHandler { | |||
| 70 | 70 | */ | |
| 71 | 71 | public String[][] resolveClasspaths(List<Object> arguments) throws Exception { | |
| 72 | 72 | try { | |
| 73 | + if (arguments.size() == 3) { | ||
| 74 | + return computeClassPath((String) arguments.get(0), (String) arguments.get(1), (String) arguments.get(2)); | ||
| 75 | + } | ||
| 73 | 76 | return computeClassPath((String) arguments.get(0), (String) arguments.get(1)); | |
| 74 | 77 | } catch (CoreException e) { | |
| 75 | 78 | logger.log(Level.SEVERE, "Failed to resolve classpath: " + e.getMessage(), e); | |
@@ -159,6 +162,23 @@ public void acceptSearchMatch(SearchMatch match) { | |||
| 159 | 162 | * CoreException | |
| 160 | 163 | */ | |
| 161 | 164 | 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 { | ||
| 162 | 182 | IJavaProject project = null; | |
| 163 | 183 | // if type exists in multiple projects, debug configuration need provide | |
| 164 | 184 | // project name. | |
@@ -179,6 +199,12 @@ private static String[][] computeClassPath(String mainClass, String projectName) | |||
| 179 | 199 | project = projects.get(0); | |
| 180 | 200 | } | |
| 181 | 201 | ||
| 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 | + | ||
| 182 | 208 | IJavaElement testElement = findMainClassInTestFolders(project, mainClass); | |
| 183 | 209 | List<IResource> mappedResources = (testElement != null && testElement.getResource() != null) | |
| 184 | 210 | ? Arrays.asList(testElement.getResource()) : Collections.EMPTY_LIST; | |
@@ -275,7 +301,7 @@ public void acceptSearchMatch(SearchMatch match) { | |||
| 275 | 301 | ||
| 276 | 302 | private static class JavaApplicationLaunchConfiguration extends LaunchConfiguration { | |
| 277 | 303 | 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" | ||
| 279 | 305 | + "<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_PATHS\">\n" | |
| 280 | 306 | + "</listAttribute>\n" | |
| 281 | 307 | + "<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_TYPES\">\n" | |
@@ -302,7 +328,18 @@ protected JavaApplicationLaunchConfiguration(IProject project, String mainType, | |||
| 302 | 328 | } else if (ProjectUtils.isGradleProject(project)) { | |
| 303 | 329 | classpathProvider = "org.eclipse.buildship.core.classpathprovider"; | |
| 304 | 330 | } | |
| 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); | ||
| 306 | 343 | } | |
| 307 | 344 | ||
| 308 | 345 | @Override | |
| Back | FazBrowse Home | New Git URL |
0 commit comments