Search in sources :

Example 1 with GradleSMTestProxy

use of org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy in project intellij-community by JetBrains.

the class BeforeTestEvent method process.

@Override
public void process(@NotNull final TestEventXmlView eventXml) throws TestEventXmlView.XmlParserException {
    final String testId = eventXml.getTestId();
    final String parentTestId = eventXml.getTestParentId();
    final String name = eventXml.getTestName();
    final String fqClassName = eventXml.getTestClassName();
    String locationUrl = findLocationUrl(name, fqClassName);
    final GradleSMTestProxy testProxy = new GradleSMTestProxy(name, false, locationUrl, fqClassName);
    testProxy.setStarted();
    testProxy.setLocator(getExecutionConsole().getUrlProvider());
    registerTestProxy(testId, testProxy);
    if (StringUtil.isEmpty(parentTestId)) {
        addToInvokeLater(() -> getResultsViewer().getTestsRootNode().addChild(testProxy));
    } else {
        final SMTestProxy parentTestProxy = findTestProxy(parentTestId);
        if (parentTestProxy != null) {
            addToInvokeLater(() -> {
                final List<GradleSMTestProxy> notYetAddedParents = ContainerUtil.newSmartList();
                SMTestProxy currentParentTestProxy = parentTestProxy;
                while (currentParentTestProxy != null && currentParentTestProxy instanceof GradleSMTestProxy) {
                    final String parentId = ((GradleSMTestProxy) currentParentTestProxy).getParentId();
                    if (currentParentTestProxy.getParent() == null && parentId != null) {
                        notYetAddedParents.add((GradleSMTestProxy) currentParentTestProxy);
                    }
                    currentParentTestProxy = findTestProxy(parentId);
                }
                for (GradleSMTestProxy gradleSMTestProxy : ContainerUtil.reverse(notYetAddedParents)) {
                    final SMTestProxy parentTestProxy1 = findTestProxy(gradleSMTestProxy.getParentId());
                    if (parentTestProxy1 != null) {
                        parentTestProxy1.addChild(gradleSMTestProxy);
                        getResultsViewer().onSuiteStarted(gradleSMTestProxy);
                    }
                }
                parentTestProxy.addChild(testProxy);
            });
        }
    }
    addToInvokeLater(() -> getResultsViewer().onTestStarted(testProxy));
}
Also used : SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) GradleSMTestProxy(org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy) GradleSMTestProxy(org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy)

Example 2 with GradleSMTestProxy

use of org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy in project intellij-community by JetBrains.

the class BeforeSuiteEvent method process.

@Override
public void process(@NotNull final TestEventXmlView eventXml) throws TestEventXmlView.XmlParserException {
    final String testId = eventXml.getTestId();
    final String parentTestId = eventXml.getTestParentId();
    final String name = eventXml.getTestName();
    final String fqClassName = eventXml.getTestClassName();
    if (StringUtil.isEmpty(parentTestId)) {
        registerTestProxy(testId, getResultsViewer().getTestsRootNode());
    } else {
        String locationUrl = findLocationUrl(null, fqClassName);
        final GradleSMTestProxy testProxy = new GradleSMTestProxy(name, true, locationUrl, null);
        testProxy.setLocator(getExecutionConsole().getUrlProvider());
        testProxy.setParentId(parentTestId);
        testProxy.setStarted();
        registerTestProxy(testId, testProxy);
    }
}
Also used : GradleSMTestProxy(org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy)

Example 3 with GradleSMTestProxy

use of org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy in project intellij-community by JetBrains.

the class GradleRerunFailedTestsAction method getRunProfile.

@Nullable
@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) myConsoleProperties.getConfiguration();
    final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
    return new MyRunProfile(configuration) {

        @NotNull
        @Override
        public Module[] getModules() {
            return Module.EMPTY_ARRAY;
        }

        @Nullable
        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
            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 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));
            }
            return runProfile.getState(executor, environment);
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) GradleSMTestProxy(org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GradleSMTestProxy (org.jetbrains.plugins.gradle.execution.test.runner.GradleSMTestProxy)3 Executor (com.intellij.execution.Executor)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)1 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)1 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)1 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 PsiClass (com.intellij.psi.PsiClass)1 PsiFile (com.intellij.psi.PsiFile)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1