FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support customizing the classpaths and modulepaths by jdneo · Pull Request #376 · microsoft/java-debug · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class ResolveClasspathsHandler {
*/
public String[][] resolveClasspaths(List<Object> arguments) throws Exception {
try {
if (arguments.size() == 3) {
return computeClassPath((String) arguments.get(0), (String) arguments.get(1), (String) arguments.get(2));
}
return computeClassPath((String) arguments.get(0), (String) arguments.get(1));
} catch (CoreException e) {
logger.log(Level.SEVERE, "Failed to resolve classpath: " + e.getMessage(), e);
Expand Down Expand Up @@ -159,6 +162,23 @@ public void acceptSearchMatch(SearchMatch match) {
* CoreException
*/
private static String[][] computeClassPath(String mainClass, String projectName) throws CoreException {
return computeClassPath(mainClass, projectName, null);
}

/**
* Accord to the project name and the main class, compute runtime classpath.
*
* @param mainClass
* fully qualified class name
* @param projectName
* project name
* @param scope
* scope of the classpath
* @return class path
* @throws CoreException
* CoreException
*/
private static String[][] computeClassPath(String mainClass, String projectName, String scope) throws CoreException {
IJavaProject project = null;
// if type exists in multiple projects, debug configuration need provide
// project name.
Expand All @@ -179,6 +199,12 @@ private static String[][] computeClassPath(String mainClass, String projectName)
project = projects.get(0);
}

if ("test".equals(scope)) {
return computeClassPath(project, mainClass, false /*excludeTestCode*/, Collections.EMPTY_LIST);
} else if ("runtime".equals(scope)) {
return computeClassPath(project, mainClass, true /*excludeTestCode*/, Collections.EMPTY_LIST);
}

IJavaElement testElement = findMainClassInTestFolders(project, mainClass);
List<IResource> mappedResources = (testElement != null && testElement.getResource() != null)
? Arrays.asList(testElement.getResource()) : Collections.EMPTY_LIST;
Expand Down Expand Up @@ -275,7 +301,7 @@ public void acceptSearchMatch(SearchMatch match) {

private static class JavaApplicationLaunchConfiguration extends LaunchConfiguration {
public static final String JAVA_APPLICATION_LAUNCH = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ "<launchConfiguration type=\"org.eclipse.jdt.launching.localJavaApplication\">\n"
+ "<launchConfiguration type=\"%s\">\n"
+ "<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_PATHS\">\n"
+ "</listAttribute>\n"
+ "<listAttribute key=\"org.eclipse.debug.core.MAPPED_RESOURCE_TYPES\">\n"
Expand All @@ -302,7 +328,18 @@ protected JavaApplicationLaunchConfiguration(IProject project, String mainType,
} else if (ProjectUtils.isGradleProject(project)) {
classpathProvider = "org.eclipse.buildship.core.classpathprovider";
}
this.launchInfo = new JavaLaunchConfigurationInfo(JAVA_APPLICATION_LAUNCH);

// Since MavenRuntimeClasspathProvider will only including test entries when:
// 1. Launch configuration is JUnit/TestNG type
// 2. Mapped resource is in test path.
// That's why we use JUnit launch configuration here to make sure the result is right when excludeTestCode is false.
String launchXml = null;
if (!excludeTestCode && mappedResources.isEmpty()) {
launchXml = String.format(JAVA_APPLICATION_LAUNCH, "org.eclipse.jdt.junit.launchconfig");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

if test runner extension is not installed, does this still work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes it is. junit is already embedded in JLS.

} else {
launchXml = String.format(JAVA_APPLICATION_LAUNCH, "org.eclipse.jdt.launching.localJavaApplication");
}
this.launchInfo = new JavaLaunchConfigurationInfo(launchXml);
}

@Override
Expand Down

Back | FazBrowse Home | New Git URL