Commit 9956c73a authored by Sergei Vorobyov's avatar Sergei Vorobyov Committed by Sergei Vorobyov
Browse files

IDEA-169795 added more intelligence test task finding

parent 30a9ffae
Showing with 657 additions and 153 deletions
+657 -153
......@@ -36,6 +36,8 @@ public class ProjectKeys {
@NotNull public static final Key<ConfigurationData> CONFIGURATION = Key.create(ConfigurationData.class, 350);
@NotNull public static final Key<TestData> TEST = Key.create(TestData.class, 450);
private ProjectKeys() {
}
}
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.externalSystem.model.project;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Set;
public class TestData extends AbstractExternalEntityData {
private final @NotNull String testName;
private final @NotNull String testTaskName;
private final @NotNull String cleanTestTaskName;
private final @NotNull Set<String> sourceFolders;
public TestData(
@NotNull ProjectSystemId owner,
@NotNull String testName,
@NotNull String testTaskName,
@NotNull String cleanTestTaskName,
@NotNull Set<String> sourceFolders
) {
super(owner);
this.testName = testName;
this.testTaskName = testTaskName;
this.cleanTestTaskName = cleanTestTaskName;
this.sourceFolders = sourceFolders;
}
@NotNull
public String getTestName() {
return testName;
}
@NotNull
public String getTestTaskName() {
return testTaskName;
}
@NotNull
public String getCleanTestTaskName() {
return cleanTestTaskName;
}
@NotNull
public Set<String> getSourceFolders() {
return Collections.unmodifiableSet(sourceFolders);
}
}
......@@ -716,6 +716,41 @@ public class ExternalSystemApiUtil {
return tasks;
}
@ApiStatus.Experimental
@Nullable
public static DataNode<ModuleData> findModuleData(@NotNull Module module,
@NotNull ProjectSystemId systemId) {
String externalProjectPath = getExternalProjectPath(module);
if (externalProjectPath == null) return null;
Project project = module.getProject();
DataNode<ProjectData> projectNode = findProjectData(project, systemId, externalProjectPath);
if (projectNode == null) return null;
return find(projectNode, ProjectKeys.MODULE, node -> externalProjectPath.equals(node.getData().getLinkedExternalProjectPath()));
}
@ApiStatus.Experimental
@Nullable
public static DataNode<ProjectData> findProjectData(@NotNull Project project,
@NotNull ProjectSystemId systemId,
@NotNull String projectPath) {
ExternalProjectInfo projectInfo = findProjectInfo(project, systemId, projectPath);
if (projectInfo == null) return null;
return projectInfo.getExternalProjectStructure();
}
@ApiStatus.Experimental
@Nullable
public static ExternalProjectInfo findProjectInfo(@NotNull Project project,
@NotNull ProjectSystemId systemId,
@NotNull String projectPath) {
AbstractExternalSystemSettings settings = getSettings(project, systemId);
ExternalProjectSettings linkedProjectSettings = settings.getLinkedProjectSettings(projectPath);
if (linkedProjectSettings == null) return null;
return ProjectDataManager.getInstance().getExternalProjectsData(project, systemId).stream()
.filter(info -> FileUtil.pathsEqual(linkedProjectSettings.getExternalProjectPath(), info.getExternalProjectPath()))
.findFirst().orElse(null);
}
/**
* DO NOT USE THIS METHOD.
* The method should be removed when the 'java' subsystem features will be extracted from External System API [IDEA-187832]
......
......@@ -1006,6 +1006,13 @@ public class ContainerUtil extends ContainerUtilRt {
return result;
}
@SuppressWarnings("unchecked")
@NotNull
@Contract(pure = true)
public static <T> List<T> filterIsInstance(@NotNull Collection<?> collection, @NotNull final Class<? super T> aClass) {
return (List<T>)filter(collection, Conditions.instanceOf(aClass));
}
@NotNull
@Contract(pure=true)
public static <T> List<T> filter(@NotNull Collection<? extends T> collection, @NotNull Condition<? super T> condition) {
......
......@@ -15,31 +15,35 @@
*/
package org.jetbrains.plugins.gradle.action;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.actions.JavaRerunFailedTestsAction;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.testframework.AbstractTestProxy;
import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings;
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.containers.ContainerUtil;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy;
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer;
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestsExecutionConsole;
import org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import static com.intellij.util.containers.ContainerUtil.filterIsInstance;
import static org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer.findAllTestsTaskToRun;
import static org.jetbrains.plugins.gradle.execution.test.runner.TestGradleConfigurationProducerUtilKt.applyTestConfiguration;
import static org.jetbrains.plugins.gradle.util.GradleRerunFailedTasksActionUtilsKt.containsSubSequenceInSequence;
import static org.jetbrains.plugins.gradle.util.GradleRerunFailedTasksActionUtilsKt.containsTasksInScriptParameters;
/**
* @author Vladislav.Soroka
......@@ -57,52 +61,41 @@ public class GradleRerunFailedTestsAction extends JavaRerunFailedTestsAction {
return new MyRunProfile(configuration) {
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment)
throws ExecutionException {
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) {
ExternalSystemRunConfiguration runProfile = ((ExternalSystemRunConfiguration)getPeer()).clone();
Project project = runProfile.getProject();
Set<String> scriptParameters = ContainerUtil.newLinkedHashSet();
Set<String> tasksToRun = ContainerUtil.newLinkedHashSet();
boolean useResolvedTasks = true;
for (AbstractTestProxy test : failedTests) {
if (test instanceof GradleSMTestProxy) {
String testName = test.getName();
String className = ((GradleSMTestProxy)test).getClassName();
scriptParameters.add(TestMethodGradleConfigurationProducer.createTestFilter(className, testName));
if(!useResolvedTasks) continue;
if(className == null) {
useResolvedTasks = false;
continue;
}
final PsiClass psiClass =
JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.projectScope(project));
if (psiClass == null) {
useResolvedTasks = false;
continue;
final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
ExternalSystemTaskExecutionSettings settings = runProfile.getSettings().clone();
List<GradleSMTestProxy> tests = filterIsInstance(failedTests, GradleSMTestProxy.class);
Function1<GradleSMTestProxy, PsiClass> findPsiClass = test -> {
String className = test.getClassName();
if (className == null) return null;
return javaPsiFacade.findClass(className, projectScope);
};
Function2<PsiClass, GradleSMTestProxy, String> createFilter = (psiClass, test) -> {
String testName = test.getName();
String className = test.getClassName();
return TestMethodGradleConfigurationProducer.createTestFilter(className, testName);
};
Function1<VirtualFile, List<List<String>>> getTestsTaskToRun = source -> {
List<? extends List<String>> foundTasksToRun = findAllTestsTaskToRun(source, project);
List<List<String>> tasksToRun = new ArrayList<>();
boolean isSpecificTask = false;
for (List<String> tasks : foundTasksToRun) {
if (containsSubSequenceInSequence(runProfile.getSettings().getTaskNames(), tasks) ||
containsTasksInScriptParameters(runProfile.getSettings().getScriptParameters(), tasks)) {
ContainerUtil.addAllNotNull(tasksToRun, tasks);
isSpecificTask = true;
}
final PsiFile psiFile = psiClass.getContainingFile();
if (psiFile == null) {
useResolvedTasks = false;
continue;
}
final Module moduleForFile = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(psiFile.getVirtualFile());
if(moduleForFile == null){
useResolvedTasks = false;
continue;
}
ContainerUtil.addAllNotNull(tasksToRun, GradleTestRunConfigurationProducer.getTasksToRun(moduleForFile));
}
}
runProfile.getSettings().setScriptParameters(StringUtil.join(scriptParameters, " "));
if(useResolvedTasks && !tasksToRun.isEmpty()) {
runProfile.getSettings().setTaskNames(ContainerUtil.newArrayList(tasksToRun));
if (!isSpecificTask && !foundTasksToRun.isEmpty()) {
ContainerUtil.addAllNotNull(tasksToRun, foundTasksToRun.iterator().next());
}
return tasksToRun;
};
if (applyTestConfiguration(settings, project, tests, findPsiClass, createFilter, getTestsTaskToRun)) {
runProfile.getSettings().setFrom(settings);
}
return runProfile.getState(executor, environment);
}
......
......@@ -10,14 +10,16 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiPackage;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import org.jetbrains.plugins.gradle.util.GradleExecutionSettingsUtil;
import java.util.List;
import org.jetbrains.plugins.gradle.util.TasksToRun;
/**
* @author Vladislav.Soroka
......@@ -45,7 +47,10 @@ public final class AllInPackageGradleConfigurationProducer extends GradleTestRun
final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (projectPath == null) return false;
List<String> tasksToRun = getTasksToRun(module);
PsiDirectory[] sourceDirs = psiPackage.getDirectories(GlobalSearchScope.moduleScope(module));
if (sourceDirs.length == 0) return false;
VirtualFile source = sourceDirs[0].getVirtualFile();
TasksToRun tasksToRun = findTestsTaskToRun(source, context.getProject());
if (tasksToRun.isEmpty()) return false;
configuration.getSettings().setExternalProjectPath(projectPath);
......@@ -68,7 +73,11 @@ public final class AllInPackageGradleConfigurationProducer extends GradleTestRun
configuration.getSettings().getExternalProjectPath())) {
return false;
}
if (!configuration.getSettings().getTaskNames().containsAll(getTasksToRun(context.getModule()))) return false;
Module module = context.getModule();
PsiDirectory[] sourceDirs = psiPackage.getDirectories(GlobalSearchScope.moduleScope(module));
if (sourceDirs.length == 0) return false;
VirtualFile source = sourceDirs[0].getVirtualFile();
if (!hasTasksInConfiguration(source, context.getProject(), configuration.getSettings())) return false;
final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
final String filter = GradleExecutionSettingsUtil.createTestFilterFrom(psiPackage, /*hasSuffix=*/true);
......
......@@ -8,15 +8,17 @@ import com.intellij.execution.configurations.ConfigurationType;
import com.intellij.openapi.externalSystem.model.DataNode;
import com.intellij.openapi.externalSystem.model.ExternalProjectInfo;
import com.intellij.openapi.externalSystem.model.ProjectKeys;
import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings;
import com.intellij.openapi.externalSystem.model.project.ModuleData;
import com.intellij.openapi.externalSystem.model.project.TestData;
import com.intellij.openapi.externalSystem.model.task.TaskData;
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
......@@ -30,9 +32,11 @@ import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil;
import org.jetbrains.plugins.gradle.service.settings.GradleSettingsService;
import org.jetbrains.plugins.gradle.settings.TestRunner;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import org.jetbrains.plugins.gradle.util.TasksToRun;
import java.util.List;
import java.util.*;
import static com.intellij.openapi.externalSystem.util.ExternalSystemUtil.getExternalProjectInfo;
import static com.intellij.openapi.util.text.StringUtil.endsWithChar;
import static org.jetbrains.plugins.gradle.settings.TestRunner.*;
......@@ -103,6 +107,68 @@ public abstract class GradleTestRunConfigurationProducer extends RunConfiguratio
return GradleRunnerUtil.resolveProjectPath(module);
}
public static boolean hasTasksInConfiguration(VirtualFile source, Project project, ExternalSystemTaskExecutionSettings settings) {
List<TasksToRun> tasksToRun = findAllTestsTaskToRun(source, project);
List<String> taskNames = settings.getTaskNames();
return tasksToRun.stream().anyMatch(taskNames::containsAll);
}
/**
* Finds any of possible tasks to run tests for specified source
*
* @param source is a file or directory for find in source set
* @param project is a project with the source
* @return any of possible tasks to run tests for specified source
*/
@NotNull
public static TasksToRun findTestsTaskToRun(@NotNull VirtualFile source, @NotNull Project project) {
List<TasksToRun> tasksToRun = findAllTestsTaskToRun(source, project);
if (tasksToRun.isEmpty()) return TasksToRun.EMPTY;
return tasksToRun.get(0);
}
/**
* Finds all of possible tasks to run tests for specified source
*
* @param source is a file or directory for find in source set
* @param project is a project with the source
* @return all of possible tasks to run tests for specified source
*/
@NotNull
public static List<TasksToRun> findAllTestsTaskToRun(@NotNull VirtualFile source, @NotNull Project project) {
String sourcePath = source.getPath();
ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
Module module = projectFileIndex.getModuleForFile(source);
if (module == null) return Collections.emptyList();
List<TasksToRun> testTasks = new ArrayList<>();
for (GradleTestTasksProvider provider : GradleTestTasksProvider.EP_NAME.getExtensions()) {
List<String> tasks = provider.getTasks(module, source);
if (!ContainerUtil.isEmpty(tasks)) {
String testName = StringUtil.join(tasks, " ");
testTasks.add(new TasksToRun.Impl(source, module, testName, tasks));
}
}
DataNode<ModuleData> moduleDataNode = ExternalSystemApiUtil.findModuleData(module, GradleConstants.SYSTEM_ID);
if (moduleDataNode == null) return testTasks;
Collection<DataNode<TestData>> testsData = ExternalSystemApiUtil.findAll(moduleDataNode, ProjectKeys.TEST);
for (DataNode<TestData> testDataNode : testsData) {
TestData testData = testDataNode.getData();
Set<String> sourceFolders = testData.getSourceFolders();
for (String sourceFolder : sourceFolders) {
if (FileUtil.isAncestor(sourceFolder, sourcePath, false)) {
String testName = testData.getTestName();
String testTaskName = testData.getTestTaskName();
String clearTestTaskName = testData.getCleanTestTaskName();
List<String> tasks = ContainerUtil.newArrayList(clearTestTaskName, testTaskName);
testTasks.add(new TasksToRun.Impl(source, module, testName, tasks));
}
}
}
return testTasks;
}
@Deprecated
@NotNull
public static List<String> getTasksToRun(@NotNull Module module) {
for (GradleTestTasksProvider provider : GradleTestTasksProvider.EP_NAME.getExtensions()) {
......@@ -117,7 +183,7 @@ public abstract class GradleTestRunConfigurationProducer extends RunConfiguratio
final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
if (projectPath == null) return ContainerUtil.emptyList();
final ExternalProjectInfo externalProjectInfo =
ExternalSystemUtil.getExternalProjectInfo(module.getProject(), GradleConstants.SYSTEM_ID, projectPath);
getExternalProjectInfo(module.getProject(), GradleConstants.SYSTEM_ID, projectPath);
if (externalProjectInfo == null) return ContainerUtil.emptyList();
final List<String> tasks;
......
......@@ -17,6 +17,7 @@ package org.jetbrains.plugins.gradle.execution.test.runner;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import java.util.List;
......@@ -29,4 +30,9 @@ public interface GradleTestTasksProvider {
@NotNull
List<String> getTasks(@NotNull Module module);
@NotNull
default List<String> getTasks(@NotNull Module module, @NotNull VirtualFile source) {
return getTasks(module);
}
}
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.execution.test.runner
import com.intellij.execution.actions.ConfigurationContext
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiElement
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer.findAllTestsTaskToRun
import org.jetbrains.plugins.gradle.util.TasksToRun
import java.util.*
import javax.swing.DefaultListCellRenderer
abstract class TasksChooser {
private val LOG = Logger.getInstance(TasksChooser::class.java)
@Suppress("CAST_NEVER_SUCCEEDS")
private fun error(message: String): Nothing = LOG.error(message) as Nothing
protected abstract fun choosesTasks(tasks: List<Map<String, List<String>>>)
fun runTaskChoosing(context: ConfigurationContext, vararg elements: PsiElement) {
val sources = elements.map { it.containingFile?.virtualFile ?: error("Can not find source file for $it") }
runTaskChoosing(context.dataContext, sources, context.project)
}
private fun runTaskChoosing(context: DataContext, sources: List<VirtualFile>, project: Project) {
val tasks = findAllTestsTaskToRun(sources, project)
if (tasks.isEmpty()) return
if (tasks.size == 1) {
choosesTasks(tasks)
return
}
val identifiedTasks = tasks.map { createIdentifier(it) to it }.toMap()
JBPopupFactory.getInstance()
.createPopupChooserBuilder(identifiedTasks.keys.toList())
.setRenderer(DefaultListCellRenderer())
.setTitle("Choose tasks to run...")
.setMovable(false)
.setResizable(false)
.setRequestFocus(true)
.setItemsChosenCallback { chooses ->
chooseAndPerform(chooses.mapNotNull(identifiedTasks::get))
}
.createPopup()
.showInBestPositionFor(context)
}
private fun findAllTestsTaskToRun(sources: List<VirtualFile>, project: Project): List<Map<String, TasksToRun>> {
val tasks = sources.map { source -> source.path to findAllTestsTaskToRun(source, project).map { it.testName to it }.toMap() }
val taskNames = tasks.map { it.second.keys }.reduce { acc, it -> acc intersect it }
return taskNames.map { name -> tasks.map { it.first to it.second.getValue(name) }.toMap() }
}
private fun chooseAndPerform(tasks: List<Map<String, List<String>>>) {
when {
tasks.isEmpty() -> return
else -> choosesTasks(tasks)
}
}
private fun createIdentifier(tasks: Map<String, TasksToRun>): String {
assert(tasks.isNotEmpty())
val joiner = StringJoiner(" ")
joiner.add(tasks.values.first().testName)
tasks.values.map { it.module.name }.toSet()
.fold(joiner, StringJoiner::add)
return joiner.toString()
}
}
\ No newline at end of file
......@@ -15,9 +15,9 @@ import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExe
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiClassOwner;
import com.intellij.psi.PsiElement;
......@@ -28,13 +28,15 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import org.jetbrains.plugins.gradle.util.GradleExecutionSettingsUtil;
import org.jetbrains.plugins.gradle.util.TasksToRun;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation;
import static org.jetbrains.plugins.gradle.execution.test.runner.TestGradleConfigurationProducerUtilKt.applyTestConfiguration;
import static org.jetbrains.plugins.gradle.util.GradleExecutionSettingsUtil.createTestFilterFrom;
/**
* @author Vladislav.Soroka
......@@ -70,13 +72,14 @@ public class TestClassGradleConfigurationProducer extends GradleTestRunConfigura
final String projectPath = resolveProjectPath(module);
if (projectPath == null) return false;
List<String> tasksToRun = getTasksToRun(module);
VirtualFile source = testClass.getContainingFile().getVirtualFile();
TasksToRun tasksToRun = findTestsTaskToRun(source, context.getProject());
if (tasksToRun.isEmpty()) return false;
configuration.getSettings().setExternalProjectPath(projectPath);
configuration.getSettings().setTaskNames(tasksToRun);
String filter = GradleExecutionSettingsUtil.createTestFilterFrom(testClass, /*hasSuffix=*/false);
String filter = createTestFilterFrom(testClass, /*hasSuffix=*/false);
configuration.getSettings().setScriptParameters(filter);
configuration.setName(testClass.getName());
......@@ -128,13 +131,14 @@ public class TestClassGradleConfigurationProducer extends GradleTestRunConfigura
if (!StringUtil.equals(projectPath, configuration.getSettings().getExternalProjectPath())) {
return false;
}
if (!configuration.getSettings().getTaskNames().containsAll(getTasksToRun(context.getModule()))) return false;
VirtualFile source = testClass.getContainingFile().getVirtualFile();
if (!hasTasksInConfiguration(source, context.getProject(), configuration.getSettings())) return false;
final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
int i = scriptParameters.indexOf("--tests ");
if(i == -1) return false;
String testFilter = GradleExecutionSettingsUtil.createTestFilterFrom(testClass, /*hasSuffix=*/true);
String testFilter = createTestFilterFrom(testClass, /*hasSuffix=*/true);
String filter = testFilter.substring("--tests ".length());
String str = scriptParameters.substring(i + "--tests ".length()).trim() + ' ';
return str.startsWith(filter) && !str.contains("--tests");
......@@ -145,48 +149,41 @@ public class TestClassGradleConfigurationProducer extends GradleTestRunConfigura
final InheritorChooser inheritorChooser = new InheritorChooser() {
@Override
protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
if (!StringUtil.equals(ExternalSystemModulePropertyManager.getInstance(context.getModule()).getExternalSystemId(),
GradleConstants.SYSTEM_ID.toString())) {
return;
}
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration)fromContext.getConfiguration();
if (!applyTestClassConfiguration(configuration, context, ArrayUtil.toObjectArray(classes, PsiClass.class))) return;
super.runForClasses(classes, method, context, performRunnable);
chooseTestClassConfiguration(fromContext, context, performRunnable, ArrayUtil.toObjectArray(classes, PsiClass.class));
}
@Override
protected void runForClass(PsiClass aClass,
PsiMethod psiMethod,
ConfigurationContext context,
Runnable performRunnable) {
if (!StringUtil.equals(
ExternalSystemModulePropertyManager.getInstance(context.getModule()).getExternalSystemId(),
GradleConstants.SYSTEM_ID.toString())) {
return;
}
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration)fromContext.getConfiguration();
if (!applyTestClassConfiguration(configuration, context, aClass)) return;
super.runForClass(aClass, psiMethod, context, performRunnable);
protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
chooseTestClassConfiguration(fromContext, context, performRunnable, aClass);
}
};
if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, null, (PsiClass)fromContext.getSourceElement())) return;
super.onFirstRun(fromContext, context, performRunnable);
if (RunConfigurationProducer.getInstance(PatternGradleConfigurationProducer.class).isMultipleElementsSelected(context)) return;
Location contextLocation = context.getLocation();
if (contextLocation == null) return;
PsiClass psiClass = getPsiClassForLocation(contextLocation);
if (psiClass == null) return;
chooseTestClassConfiguration(fromContext, context, performRunnable, psiClass);
}
private static boolean applyTestClassConfiguration(@NotNull ExternalSystemRunConfiguration configuration,
@NotNull ConfigurationContext context,
@NotNull PsiClass... containingClasses) {
final Project project = context.getProject();
final ExternalSystemTaskExecutionSettings settings = configuration.getSettings();
final Function1<PsiClass, String> createFilter = (psiClass) ->
GradleExecutionSettingsUtil.createTestFilterFrom(psiClass, /*hasSuffix=*/true);
if (!applyTestConfiguration(settings, project, containingClasses, createFilter)) {
return false;
}
configuration.setName(StringUtil.join(containingClasses, aClass -> aClass.getName(), "|"));
return true;
private static void chooseTestClassConfiguration(@NotNull ConfigurationFromContext fromContext,
@NotNull ConfigurationContext context,
@NotNull Runnable performRunnable,
@NotNull PsiClass... classes) {
String systemId = ExternalSystemModulePropertyManager.getInstance(context.getModule()).getExternalSystemId();
if (!StringUtil.equals(systemId, GradleConstants.SYSTEM_ID.toString())) return;
TasksChooser tasksChooser = new TasksChooser() {
@Override
protected void choosesTasks(@NotNull List<? extends Map<String, ? extends List<String>>> tasks) {
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration)fromContext.getConfiguration();
ExternalSystemTaskExecutionSettings settings = configuration.getSettings();
Function1<PsiClass, String> createFilter = (psiClass) -> createTestFilterFrom(psiClass, /*hasSuffix=*/true);
if (!applyTestConfiguration(settings, context.getProject(), tasks, classes, createFilter)) return;
configuration.setName(StringUtil.join(classes, aClass -> aClass.getName(), "|"));
performRunnable.run();
}
};
tasksChooser.runTaskChoosing(context, classes);
}
@Deprecated
......
......@@ -2,42 +2,76 @@
package org.jetbrains.plugins.gradle.execution.test.runner
import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiClass
import org.jetbrains.plugins.gradle.execution.GradleRunnerUtil
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer.getTasksToRun
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer.findTestsTaskToRun
import java.util.*
fun ExternalSystemTaskExecutionSettings.applyTestConfiguration(
project: Project,
testTasksToRun: List<Map<String, List<String>>>,
vararg containingClasses: PsiClass,
createFilter: (PsiClass) -> String
): Boolean {
return applyTestConfiguration(project, containingClasses.toList(), { it }, { it, _ -> createFilter(it) }) { source ->
testTasksToRun.mapNotNull { it[source.path] }
}
}
fun ExternalSystemTaskExecutionSettings.applyTestConfiguration(
project: Project,
vararg containingClasses: PsiClass,
createFilter: (PsiClass) -> String
): Boolean {
return applyTestConfiguration(project, containingClasses.toList(), { it }) { it, _ ->
createFilter(it)
}
}
fun <T> ExternalSystemTaskExecutionSettings.applyTestConfiguration(
project: Project,
tests: Iterable<T>,
findPsiClass: (T) -> PsiClass?,
createFilter: (PsiClass, T) -> String
createFilter: (PsiClass, T) -> String): Boolean {
return applyTestConfiguration(project, tests, findPsiClass, createFilter) { source ->
listOf(findTestsTaskToRun(source, project))
}
}
fun <T> ExternalSystemTaskExecutionSettings.applyTestConfiguration(
project: Project,
tests: Iterable<T>,
findPsiClass: (T) -> PsiClass?,
createFilter: (PsiClass, T) -> String,
getTestsTaskToRun: (VirtualFile) -> List<List<String>>
): Boolean {
val projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project)
val testRunConfigurations = LinkedHashMap<String, Pair<Module, MutableList<String>>>()
val testRunConfigurations = LinkedHashMap<String, Pair<VirtualFile, MutableList<String>>>()
for (test in tests) {
val psiClass = findPsiClass(test) ?: continue
val psiFile = psiClass.containingFile ?: continue
val module = projectFileIndex.getModuleForFile(psiFile.virtualFile) ?: return false
val psiClass = findPsiClass(test) ?: return false
val psiFile = psiClass.containingFile ?: return false
val virtualFile = psiFile.virtualFile
val module = projectFileIndex.getModuleForFile(virtualFile) ?: return false
externalProjectPath = GradleRunnerUtil.resolveProjectPath(module) ?: return false
if (!GradleRunnerUtil.isGradleModule(module)) return false
val (_, arguments) = testRunConfigurations.getOrPut(module.name) { Pair(module, ArrayList()) }
val (_, arguments) = testRunConfigurations.getOrPut(module.name) { Pair(virtualFile, ArrayList()) }
arguments.add(createFilter(psiClass, test))
}
val (module, _) = testRunConfigurations.values.firstOrNull() ?: return false
val taskSettings = ArrayList<Pair<String, List<String>>>()
val unorderedParameters = ArrayList<String>()
externalProjectPath = GradleRunnerUtil.resolveProjectPath(module) ?: return false
for ((testModule, arguments) in testRunConfigurations.values) {
val tasks = getTasksToRun(testModule)
if (tasks.isEmpty()) continue
for (task in tasks.dropLast(1)) {
taskSettings.add(task to emptyList())
for ((source, arguments) in testRunConfigurations.values) {
for (tasks in getTestsTaskToRun(source)) {
if (tasks.isEmpty()) continue
for (task in tasks.dropLast(1)) {
taskSettings.add(task to emptyList())
}
val last = tasks.last()
taskSettings.add(last to arguments)
}
val last = tasks.last()
taskSettings.add(last to arguments)
}
if (testRunConfigurations.size > 1) {
unorderedParameters.add("--continue")
......@@ -72,13 +106,3 @@ fun <T> ExternalSystemTaskExecutionSettings.applyTestConfiguration(
}
return true
}
fun ExternalSystemTaskExecutionSettings.applyTestConfiguration(
project: Project,
vararg containingClasses: PsiClass,
createFilter: (PsiClass) -> String
): Boolean {
return applyTestConfiguration(project, containingClasses.toList(), { it }) { it, _ ->
createFilter(it)
}
}
......@@ -15,6 +15,7 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
......@@ -27,6 +28,7 @@ import org.jetbrains.plugins.gradle.util.GradleConstants;
import org.jetbrains.plugins.gradle.util.GradleExecutionSettingsUtil;
import java.util.List;
import java.util.Map;
import static org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation;
import static org.jetbrains.plugins.gradle.execution.test.runner.TestGradleConfigurationProducerUtilKt.applyTestConfiguration;
......@@ -95,7 +97,8 @@ public class TestMethodGradleConfigurationProducer extends GradleTestRunConfigur
if (!StringUtil.equals(projectPath, configuration.getSettings().getExternalProjectPath())) {
return false;
}
if (!configuration.getSettings().getTaskNames().containsAll(getTasksToRun(module))) return false;
VirtualFile source = psiMethod.getContainingFile().getVirtualFile();
if (!hasTasksInConfiguration(source, context.getProject(), configuration.getSettings())) return false;
final String scriptParameters = configuration.getSettings().getScriptParameters() + ' ';
final String testFilter = createTestFilter(contextLocation, containingClass, psiMethod);
......@@ -105,39 +108,42 @@ public class TestMethodGradleConfigurationProducer extends GradleTestRunConfigur
@Override
public void onFirstRun(@NotNull final ConfigurationFromContext fromContext, @NotNull final ConfigurationContext context, @NotNull final Runnable performRunnable) {
final PsiMethod psiMethod = (PsiMethod)fromContext.getSourceElement();
final PsiClass containingClass = psiMethod.getContainingClass();
final PsiClass psiClass = psiMethod.getContainingClass();
final InheritorChooser inheritorChooser = new InheritorChooser() {
@Override
protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
if (!StringUtil.equals(
ExternalSystemModulePropertyManager.getInstance(context.getModule()).getExternalSystemId(),
GradleConstants.SYSTEM_ID.toString())) {
return;
}
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration)fromContext.getConfiguration();
if (!applyTestMethodConfiguration(configuration, context, psiMethod, ArrayUtil.toObjectArray(classes, PsiClass.class))) return;
super.runForClasses(classes, method, context, performRunnable);
chooseTestClassConfiguration(fromContext, context, performRunnable, psiMethod, ArrayUtil.toObjectArray(classes, PsiClass.class));
}
@Override
protected void runForClass(PsiClass aClass,
PsiMethod psiMethod,
ConfigurationContext context,
Runnable performRunnable) {
if (!StringUtil.equals(
ExternalSystemModulePropertyManager.getInstance(context.getModule()).getExternalSystemId(),
GradleConstants.SYSTEM_ID.toString())) {
return;
}
protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
chooseTestClassConfiguration(fromContext, context, performRunnable, psiMethod, aClass);
}
};
if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, psiMethod, psiClass)) return;
if (RunConfigurationProducer.getInstance(PatternGradleConfigurationProducer.class).isMultipleElementsSelected(context)) return;
chooseTestClassConfiguration(fromContext, context, performRunnable, psiMethod, psiClass);
}
private static void chooseTestClassConfiguration(@NotNull ConfigurationFromContext fromContext,
@NotNull ConfigurationContext context,
@NotNull Runnable performRunnable,
@NotNull PsiMethod psiMethod,
@NotNull PsiClass... classes) {
String systemId = ExternalSystemModulePropertyManager.getInstance(context.getModule()).getExternalSystemId();
if (!StringUtil.equals(systemId, GradleConstants.SYSTEM_ID.toString())) return;
TasksChooser tasksChooser = new TasksChooser() {
@Override
protected void choosesTasks(@NotNull List<? extends Map<String, ? extends List<String>>> tasks) {
ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration)fromContext.getConfiguration();
if (!applyTestMethodConfiguration(configuration, context, psiMethod, aClass)) return;
super.runForClass(aClass, psiMethod, context, performRunnable);
ExternalSystemTaskExecutionSettings settings = configuration.getSettings();
Function1<PsiClass, String> createFilter = (psiClass) -> createTestFilter(context.getLocation(), psiClass, psiMethod);
if (!applyTestConfiguration(settings, context.getProject(), tasks, classes, createFilter)) return;
configuration.setName((classes.length == 1 ? classes[0].getName() + "." : "") + psiMethod.getName());
performRunnable.run();
}
};
if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, psiMethod, containingClass)) return;
super.onFirstRun(fromContext, context, performRunnable);
tasksChooser.runTaskChoosing(context, classes);
}
private static boolean applyTestMethodConfiguration(@NotNull ExternalSystemRunConfiguration configuration,
......@@ -146,12 +152,8 @@ public class TestMethodGradleConfigurationProducer extends GradleTestRunConfigur
@NotNull PsiClass... containingClasses) {
final Project project = context.getProject();
final ExternalSystemTaskExecutionSettings settings = configuration.getSettings();
final Function1<PsiClass, String> createFilter = (psiClass) ->
createTestFilter(context.getLocation(), psiClass, psiMethod);
if (!applyTestConfiguration(settings, project, containingClasses, createFilter)) {
return false;
}
final Function1<PsiClass, String> createFilter = (psiClass) -> createTestFilter(context.getLocation(), psiClass, psiMethod);
if (!applyTestConfiguration(settings, project, containingClasses, createFilter)) return false;
configuration.setName((containingClasses.length == 1 ? containingClasses[0].getName() + "." : "") + psiMethod.getName());
return true;
}
......
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.util
import com.intellij.util.containers.FList
fun containsTasksInScriptParameters(scriptParameters: String?, tasks: List<String>): Boolean {
return scriptParameters?.contains(tasks.joinToString(" ")) ?: false
}
fun containsSubSequenceInSequence(sequence: List<Any>, subSequence: List<Any>) =
hasSubSequenceInSequence(
sequence = FList.createFromReversed(sequence.asReversed()),
subSequence = FList.createFromReversed(subSequence.asReversed())
)
tailrec fun hasSubSequenceInSequence(sequence: FList<Any>, subSequence: FList<Any>): Boolean {
if (sequence.size < subSequence.size) return false
if (sequence.zip(subSequence).all { it.first == it.second }) return true
return hasSubSequenceInSequence(sequence.tail, subSequence)
}
\ No newline at end of file
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.util
import com.intellij.openapi.module.Module
import com.intellij.openapi.vfs.VirtualFile
abstract class TasksToRun(val tasks: List<String>) : List<String> by tasks {
abstract val source: VirtualFile
abstract val module: Module
abstract val testName: String
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
is TasksToRun -> other.tasks == tasks
is List<*> -> other == tasks
else -> false
}
}
override fun hashCode(): Int {
return tasks.hashCode()
}
override fun toString(): String {
return tasks.toString()
}
class Impl(override val source: VirtualFile, override val module: Module, override val testName: String, tasks: List<String>) : TasksToRun(tasks)
object Empty : TasksToRun(emptyList()) {
override val source: VirtualFile
get() = throw UnsupportedOperationException()
override val module: Module
get() = throw UnsupportedOperationException()
override val testName: String
get() = throw UnsupportedOperationException()
}
companion object {
@JvmField
val EMPTY = Empty
}
}
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.execution.test.runner
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.plugins.gradle.execution.test.runner.GradleTestRunConfigurationProducer.findAllTestsTaskToRun
import org.jetbrains.plugins.gradle.importing.GradleBuildScriptBuilderEx
import org.jetbrains.plugins.gradle.settings.TestRunner
import org.junit.Assert
import org.junit.Test
class TestMethodGradleConfigurationProducerTest : GradleConfigurationProducerTestCase() {
......@@ -95,4 +98,43 @@ class TestMethodGradleConfigurationProducerTest : GradleConfigurationProducerTes
val filter = "--tests \"MyGroovyTest.Don\\'t use single * quo\\*tes\" --tests \"MyGroovyTest.test2\" "
assertTestPatternFilter(filter, virtualFile, "Don\\'t use single . quo\\\"tes", "test2")
}
@Test
fun `test intellij tests finding`() {
val buildScript = GradleBuildScriptBuilderEx()
.withJavaPlugin()
.withJUnit("4.12")
.addPrefix("""
sourceSets {
foo.java.srcDirs = ["foo-src", "foo-other-src"]
foo.java.outputDir = file('far/away/bin')
foo.compileClasspath += sourceSets.test.runtimeClasspath
bar.java.srcDirs = ["bar-src", "bar-other-src"]
bar.java.outputDir = file('far/far/away/build')
bar.compileClasspath += sourceSets.test.runtimeClasspath
}
""".trimIndent())
.addPrefix("""
task 'foo test task'(type: Test) {
testClassesDirs = sourceSets.foo.output.classesDirs
classpath += sourceSets.foo.runtimeClasspath
}
task 'super foo test task'(type: Test) {
testClassesDirs = sourceSets.foo.output.classesDirs
classpath += sourceSets.foo.runtimeClasspath
}
""".trimIndent())
importProject(buildScript.generate())
assertTestTasks(createProjectSubFile("foo-src/package/TestCase.java", "class TestCase"),
listOf(":cleanFoo test task", ":foo test task"),
listOf(":cleanSuper foo test task", ":super foo test task"))
assertTestTasks(createProjectSubFile("foo-other-src/package/TestCase.java", "class TestCase"),
listOf(":cleanFoo test task", ":foo test task"),
listOf(":cleanSuper foo test task", ":super foo test task"))
}
private fun assertTestTasks(source: VirtualFile, vararg expected: List<String>) {
val tasks = findAllTestsTaskToRun(source, myProject)
Assert.assertEquals(expected.toList(), tasks)
}
}
\ No newline at end of file
......@@ -60,6 +60,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.model.*;
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData;
import org.jetbrains.plugins.gradle.model.tests.ExternalTestSourceMapping;
import org.jetbrains.plugins.gradle.model.tests.ExternalTestsModel;
import org.jetbrains.plugins.gradle.service.project.data.ExternalProjectDataService;
import org.jetbrains.plugins.gradle.service.project.data.GradleExtensionsDataService;
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings;
......@@ -268,6 +270,19 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
ideModule.createChild(ProjectKeys.CONFIGURATION,
new ConfigurationDataImpl(GradleConstants.SYSTEM_ID, intellijSettings.getSettings()));
}
ProjectImportAction.AllModels models = resolverCtx.getModels();
ExternalTestsModel externalTestsModel = models.getExtraProject(gradleModule, ExternalTestsModel.class);
if (externalTestsModel != null) {
for (ExternalTestSourceMapping testSourceMapping : externalTestsModel.getTestSourceMappings()) {
String testName = testSourceMapping.getTestName();
String testTaskName = testSourceMapping.getTestTaskPath();
String cleanTestTaskName = testSourceMapping.getCleanTestTaskPath();
Set<String> sourceFolders = testSourceMapping.getSourceFolders();
TestData testData = new TestData(GradleConstants.SYSTEM_ID, testName, testTaskName, cleanTestTaskName, sourceFolders);
ideModule.createChild(ProjectKeys.TEST, testData);
}
}
}
@Override
......@@ -672,6 +687,7 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
result.add(BuildScriptClasspathModel.class);
result.add(GradleExtensions.class);
result.add(ExternalProject.class);
result.add(ExternalTestsModel.class);
result.add(IntelliJProjectSettings.class);
result.add(IntelliJSettings.class);
return result;
......
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.model.tests;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
import java.util.Set;
public interface ExternalTestSourceMapping extends Serializable {
@NotNull
String getTestName();
@NotNull
String getTestTaskPath();
@NotNull
String getCleanTestTaskPath();
@NotNull
Set<String> getSourceFolders();
}
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.model.tests;
import org.gradle.tooling.model.Model;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
import java.util.List;
public interface ExternalTestsModel extends Model, Serializable {
@NotNull
List<ExternalTestSourceMapping> getTestSourceMappings();
}
......@@ -19,6 +19,7 @@ org.jetbrains.plugins.gradle.tooling.builder.ModuleExtendedModelBuilderImpl
org.jetbrains.plugins.gradle.tooling.builder.ModelBuildScriptClasspathBuilderImpl
org.jetbrains.plugins.gradle.tooling.builder.ScalaModelBuilderImpl
org.jetbrains.plugins.gradle.tooling.builder.ExternalProjectBuilderImpl
org.jetbrains.plugins.gradle.tooling.builder.ExternalTestsModelBuilderImpl
org.jetbrains.plugins.gradle.tooling.builder.ProjectExtensionsDataBuilderImpl
org.jetbrains.plugins.gradle.tooling.builder.IntelliJSettingsBuilder
org.jetbrains.plugins.gradle.tooling.builder.IntelliJProjectSettingsBuilder
......
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.model.tests;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
public class DefaultExternalTestSourceMapping implements ExternalTestSourceMapping {
@Nullable
private String testName = null;
@Nullable
private String testTaskPath = null;
@Nullable
private String cleanTestTaskPath = null;
@NotNull
private Set<String> sourceFolders = Collections.emptySet();
public DefaultExternalTestSourceMapping() { }
public DefaultExternalTestSourceMapping(@NotNull ExternalTestSourceMapping externalTestSourceMapping) {
testName = externalTestSourceMapping.getTestName();
testTaskPath = externalTestSourceMapping.getTestTaskPath();
cleanTestTaskPath = externalTestSourceMapping.getCleanTestTaskPath();
sourceFolders = new LinkedHashSet<String>(externalTestSourceMapping.getSourceFolders());
}
@Override
@NotNull
public Set<String> getSourceFolders() {
return Collections.unmodifiableSet(sourceFolders);
}
public void setSourceFolders(@NotNull Set<String> sourceFolders) {
this.sourceFolders = sourceFolders;
}
@NotNull
@Override
public String getTestName() {
assert testName != null;
return testName;
}
public void setTestName(@Nullable String testName) {
this.testName = testName;
}
@Override
@NotNull
public String getTestTaskPath() {
assert testTaskPath != null;
return testTaskPath;
}
public void setTestTaskPath(@NotNull String testTaskPath) {
this.testTaskPath = testTaskPath;
}
@NotNull
@Override
public String getCleanTestTaskPath() {
assert cleanTestTaskPath != null;
return cleanTestTaskPath;
}
public void setCleanTestTaskPath(@NotNull String cleanTestTaskPath) {
this.cleanTestTaskPath = cleanTestTaskPath;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment