Skip to content

Commit

Permalink
Fix gradle test scope (#333)
Browse files Browse the repository at this point in the history
* Fix gradle test scope

Signed-off-by: Jinbo Wang <[email protected]>

* make checkstyle happy

Signed-off-by: Jinbo Wang <[email protected]>
  • Loading branch information
testforstephen authored May 11, 2020
1 parent b7f00af commit 8de2814
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private static String[][] computeClassPath(String mainClass, String projectName)
IJavaElement testElement = findMainClassInTestFolders(project, mainClass);
List<IResource> mappedResources = (testElement != null && testElement.getResource() != null)
? Arrays.asList(testElement.getResource()) : Collections.EMPTY_LIST;
return computeClassPath(project, testElement == null, mappedResources);
return computeClassPath(project, mainClass, testElement == null, mappedResources);
}

/**
Expand All @@ -195,13 +195,13 @@ private static String[][] computeClassPath(String mainClass, String projectName)
* @throws CoreException
* CoreException
*/
private static String[][] computeClassPath(IJavaProject javaProject, boolean excludeTestCode, List<IResource> mappedResources)
private static String[][] computeClassPath(IJavaProject javaProject, String mainType, boolean excludeTestCode, List<IResource> mappedResources)
throws CoreException {
if (javaProject == null) {
throw new IllegalArgumentException("javaProject is null");
}

ILaunchConfiguration launchConfig = new JavaApplicationLaunchConfiguration(javaProject.getProject(), excludeTestCode, mappedResources);
ILaunchConfiguration launchConfig = new JavaApplicationLaunchConfiguration(javaProject.getProject(), mainType, excludeTestCode, mappedResources);
IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(launchConfig);
IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveRuntimeClasspath(unresolved, launchConfig);
Set<String> classpaths = new LinkedHashSet<>();
Expand Down Expand Up @@ -282,15 +282,18 @@ private static class JavaApplicationLaunchConfiguration extends LaunchConfigurat
+ "</listAttribute>\n"
+ "</launchConfiguration>";
private IProject project;
private String mainType;
private boolean excludeTestCode;
private List<IResource> mappedResources;
private String classpathProvider;
private String sourcepathProvider;
private LaunchConfigurationInfo launchInfo;

protected JavaApplicationLaunchConfiguration(IProject project, boolean excludeTestCode, List<IResource> mappedResources) throws CoreException {
protected JavaApplicationLaunchConfiguration(IProject project, String mainType, boolean excludeTestCode, List<IResource> mappedResources)
throws CoreException {
super(String.valueOf(new Date().getTime()), null, false);
this.project = project;
this.mainType = mainType;
this.excludeTestCode = excludeTestCode;
this.mappedResources = mappedResources;
if (ProjectUtils.isMavenProject(project)) {
Expand Down Expand Up @@ -319,6 +322,8 @@ public String getAttribute(String attributeName, String defaultValue) throws Cor
return classpathProvider;
} else if (IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER.equalsIgnoreCase(attributeName)) {
return sourcepathProvider;
} else if (IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME.equalsIgnoreCase(attributeName)) {
return mainType;
}

return super.getAttribute(attributeName, defaultValue);
Expand Down

0 comments on commit 8de2814

Please sign in to comment.