Search in sources :

Example 21 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.

the class TestClassGradleConfigurationProducer method applyTestConfiguration.

private static boolean applyTestConfiguration(@NotNull ExternalSystemRunConfiguration configuration, @NotNull ConfigurationContext context, @NotNull PsiClass... containingClasses) {
    final Module module = context.getModule();
    if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
        return false;
    final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
    if (projectPath == null)
        return false;
    List<String> tasksToRun = getTasksToRun(module);
    if (tasksToRun.isEmpty())
        return false;
    configuration.getSettings().setExternalProjectPath(projectPath);
    configuration.getSettings().setTaskNames(tasksToRun);
    StringBuilder buf = new StringBuilder();
    for (PsiClass aClass : containingClasses) {
        buf.append(String.format("--tests %s ", aClass.getQualifiedName()));
    }
    configuration.getSettings().setScriptParameters(buf.toString());
    configuration.setName(StringUtil.join(containingClasses, aClass -> aClass.getName(), "|"));
    return true;
}
Also used : ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) InheritorChooser(com.intellij.execution.junit.InheritorChooser) ArrayUtil(com.intellij.util.ArrayUtil) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ExternalSystemConstants(com.intellij.openapi.externalSystem.util.ExternalSystemConstants) GradleRunnerUtil.getMethodLocation(org.jetbrains.plugins.gradle.execution.GradleRunnerUtil.getMethodLocation) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) PsiClass(com.intellij.psi.PsiClass) JavaRunConfigurationExtensionManager(com.intellij.execution.JavaRunConfigurationExtensionManager) GradleExternalTaskConfigurationType(org.jetbrains.plugins.gradle.service.execution.GradleExternalTaskConfigurationType) PsiElement(com.intellij.psi.PsiElement) Module(com.intellij.openapi.module.Module) PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) JUnitUtil(com.intellij.execution.junit.JUnitUtil) PsiMethod(com.intellij.psi.PsiMethod) StringUtil(com.intellij.openapi.util.text.StringUtil) JavaExecutionUtil(com.intellij.execution.JavaExecutionUtil) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) GradleConstants(org.jetbrains.plugins.gradle.util.GradleConstants) Location(com.intellij.execution.Location) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module)

Example 22 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.

the class TestMethodGradleConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(final ConfigurationFromContext fromContext, final ConfigurationContext context, @NotNull final Runnable performRunnable) {
    final PsiMethod psiMethod = (PsiMethod) fromContext.getSourceElement();
    final PsiClass containingClass = psiMethod.getContainingClass();
    final InheritorChooser inheritorChooser = new InheritorChooser() {

        @Override
        protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), 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);
        }

        @Override
        protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
            if (!StringUtil.equals(context.getModule().getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY), GradleConstants.SYSTEM_ID.toString())) {
                return;
            }
            ExternalSystemRunConfiguration configuration = (ExternalSystemRunConfiguration) fromContext.getConfiguration();
            if (!applyTestMethodConfiguration(configuration, context, psiMethod, aClass))
                return;
            super.runForClass(aClass, psiMethod, context, performRunnable);
        }
    };
    if (inheritorChooser.runMethodInAbstractClass(context, performRunnable, psiMethod, containingClass))
        return;
    super.onFirstRun(fromContext, context, performRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) List(java.util.List)

Example 23 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project kotlin by JetBrains.

the class KotlinTestNgConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(ConfigurationFromContext configuration, ConfigurationContext context, Runnable startRunnable) {
    KtNamedDeclaration declarationToRun = getDeclarationToRun(configuration.getSourceElement());
    final PsiNamedElement lightElement = CollectionsKt.firstOrNull(LightClassUtilsKt.toLightElements(declarationToRun));
    // Copied from TestNGInClassConfigurationProducer.onFirstRun()
    if (lightElement instanceof PsiMethod || lightElement instanceof PsiClass) {
        PsiMethod psiMethod;
        PsiClass containingClass;
        if (lightElement instanceof PsiMethod) {
            psiMethod = (PsiMethod) lightElement;
            containingClass = psiMethod.getContainingClass();
        } else {
            psiMethod = null;
            containingClass = (PsiClass) lightElement;
        }
        InheritorChooser inheritorChooser = new InheritorChooser() {

            @Override
            protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
                ((TestNGConfiguration) context.getConfiguration().getConfiguration()).bePatternConfiguration(classes, method);
                super.runForClasses(classes, method, context, performRunnable);
            }

            @Override
            protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
                if (lightElement instanceof PsiMethod) {
                    Project project = psiMethod.getProject();
                    MethodLocation methodLocation = new MethodLocation(project, psiMethod, PsiLocation.fromPsiElement(aClass));
                    ((TestNGConfiguration) context.getConfiguration().getConfiguration()).setMethodConfiguration(methodLocation);
                } else {
                    ((TestNGConfiguration) context.getConfiguration().getConfiguration()).setClassConfiguration(aClass);
                }
                super.runForClass(aClass, psiMethod, context, performRunnable);
            }
        };
        if (inheritorChooser.runMethodInAbstractClass(context, startRunnable, psiMethod, containingClass, new Condition<PsiClass>() {

            @Override
            public boolean value(PsiClass aClass) {
                return aClass.hasModifierProperty(PsiModifier.ABSTRACT) && TestNGUtil.hasTest(aClass);
            }
        }))
            return;
    }
    super.onFirstRun(configuration, context, startRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) Project(com.intellij.openapi.project.Project) List(java.util.List) MethodLocation(com.intellij.execution.junit2.info.MethodLocation)

Example 24 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project intellij-community by JetBrains.

the class PyStudyRunContextAction method update.

@Override
public void update(AnActionEvent event) {
    final ConfigurationContext context = ConfigurationContext.getFromContext(event.getDataContext());
    final Location location = context.getLocation();
    if (location == null)
        return;
    super.update(event);
    final InputEvent inputEvent = event.getInputEvent();
    final Presentation presentation = event.getPresentation();
    if (inputEvent == null && !(context.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT) instanceof EditorGutter)) {
        presentation.setText("");
    }
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) EditorGutter(com.intellij.openapi.editor.EditorGutter) InputEvent(java.awt.event.InputEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) Location(com.intellij.execution.Location)

Example 25 with ConfigurationContext

use of com.intellij.execution.actions.ConfigurationContext in project android by JetBrains.

the class TestConfigurationTesting method createConfigurationFromPsiElement.

@Nullable
private static RunConfiguration createConfigurationFromPsiElement(@NotNull Project project, @NotNull PsiElement psiElement) {
    ConfigurationContext context = createContext(project, psiElement);
    RunnerAndConfigurationSettings settings = context.getConfiguration();
    if (settings == null) {
        return null;
    }
    RunConfiguration configuration = settings.getConfiguration();
    if (configuration instanceof AndroidTestRunConfiguration || configuration instanceof AndroidJUnitConfiguration) {
        return configuration;
    }
    return null;
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) AndroidTestRunConfiguration(com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AndroidTestRunConfiguration(com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration) AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)26 PsiFile (com.intellij.psi.PsiFile)9 PsiElement (com.intellij.psi.PsiElement)7 GotestRunConfigurationProducer (com.goide.runconfig.testing.frameworks.gotest.GotestRunConfigurationProducer)5 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)5 InheritorChooser (com.intellij.execution.junit.InheritorChooser)5 List (java.util.List)5 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)4 Project (com.intellij.openapi.project.Project)4 Location (com.intellij.execution.Location)3 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)3 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)3 PsiClass (com.intellij.psi.PsiClass)3 PsiMethod (com.intellij.psi.PsiMethod)3 GoApplicationConfiguration (com.goide.runconfig.application.GoApplicationConfiguration)2 GoApplicationRunConfigurationProducer (com.goide.runconfig.application.GoApplicationRunConfigurationProducer)2 GoRunFileConfiguration (com.goide.runconfig.file.GoRunFileConfiguration)2 GoRunFileConfigurationProducer (com.goide.runconfig.file.GoRunFileConfigurationProducer)2