junit: put modularized junit5 dependencies on module path (IDEA-222920)

GitOrigin-RevId: a97662eea6c383f26926933fbced88f7654df236
This commit is contained in:
Anna Kozlova
2019-09-17 20:03:08 +00:00
committed by intellij-monorepo-bot
parent 761229a03b
commit 725cfc7145
@@ -265,7 +265,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
}
public void appendJUnit5LauncherClasses(JavaParameters javaParameters, Project project, GlobalSearchScope globalSearchScope) throws CantRunException {
final PathsList classPath = javaParameters.getClassPath();
JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
PsiClass classFromCommon = DumbService.getInstance(project).computeWithAlternativeResolveEnabled(
() -> psiFacade.findClass("org.junit.platform.commons.JUnitException", globalSearchScope));
@@ -276,13 +276,10 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
return;
}
if (!hasPackageWithDirectories(psiFacade, "org.junit.platform.launcher", globalSearchScope)) {
downloadDependenciesWhenRequired(project, classPath,
new RepositoryLibraryProperties("org.junit.platform", "junit-platform-launcher", launcherVersion));
}
//for modularized junit ensure launcher is included in the module graph
else if (JavaSdkUtil.isJdkAtLeast(javaParameters.getJdk(), JavaSdkVersion.JDK_1_9) &&
VersionComparatorUtil.compare(launcherVersion, "1.5.0") >= 0) {
boolean isModularized = JavaSdkUtil.isJdkAtLeast(javaParameters.getJdk(), JavaSdkVersion.JDK_1_9) &&
VersionComparatorUtil.compare(launcherVersion, "1.5.0") >= 0;
if (isModularized) { //for modularized junit ensure launcher is included in the module graph
ParametersList vmParametersList = javaParameters.getVMParametersList();
String launcherModuleName = "org.junit.platform.launcher";
if (!vmParametersList.hasParameter(launcherModuleName)) {
@@ -291,6 +288,12 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
}
}
final PathsList pathsList = isModularized ? javaParameters.getModulePath() : javaParameters.getClassPath();
if (!hasPackageWithDirectories(psiFacade, "org.junit.platform.launcher", globalSearchScope)) {
downloadDependenciesWhenRequired(project, pathsList,
new RepositoryLibraryProperties("org.junit.platform", "junit-platform-launcher", launcherVersion));
}
//add standard engines only if no engine api is present
if (!hasJUnit5EnginesAPI(globalSearchScope, psiFacade) || !isCustomJUnit5(globalSearchScope)) {
PsiClass testAnnotation = DumbService.getInstance(project).computeWithAlternativeResolveEnabled(
@@ -298,7 +301,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
String jupiterVersion = ObjectUtils.notNull(getVersion(testAnnotation), "5.0.0");
if (!hasPackageWithDirectories(psiFacade, "org.junit.jupiter.engine", globalSearchScope) &&
hasPackageWithDirectories(psiFacade, JUnitUtil.TEST5_PACKAGE_FQN, globalSearchScope)) {
downloadDependenciesWhenRequired(project, classPath,
downloadDependenciesWhenRequired(project, pathsList,
new RepositoryLibraryProperties("org.junit.jupiter", "junit-jupiter-engine", jupiterVersion));
}
@@ -307,7 +310,7 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
String version = VersionComparatorUtil.compare(launcherVersion, "1.1.0") >= 0
? jupiterVersion
: "4.12." + StringUtil.getShortName(launcherVersion);
downloadDependenciesWhenRequired(project, classPath,
downloadDependenciesWhenRequired(project, pathsList,
new RepositoryLibraryProperties("org.junit.vintage", "junit-vintage-engine", version));
}
}