Search in sources :

Example 1 with ConfigurationFromContext

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

the class ConfigurationsTest method testCreateFromContext.

@Test
public void testCreateFromContext() {
    final Project project = myProjectFixture.getProject();
    final PsiClass psiClass = findTestClass(project);
    final TestNGInClassConfigurationProducer producer = new TestNGInClassConfigurationProducer();
    final MapDataContext dataContext = new MapDataContext();
    dataContext.put(CommonDataKeys.PROJECT, project);
    dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(psiClass));
    dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiClass));
    final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
    assert fromContext != null;
    final RunnerAndConfigurationSettings config = fromContext.getConfigurationSettings();
    final RunConfiguration runConfiguration = config.getConfiguration();
    Assert.assertTrue(runConfiguration instanceof TestNGConfiguration);
    TestNGConfigurationType t = (TestNGConfigurationType) runConfiguration.getType();
    Assert.assertTrue(t.isConfigurationByLocation(runConfiguration, new PsiLocation(project, psiClass)));
}
Also used : Project(com.intellij.openapi.project.Project) MapDataContext(com.intellij.testFramework.MapDataContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiLocation(com.intellij.execution.PsiLocation) Test(org.testng.annotations.Test)

Example 2 with ConfigurationFromContext

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

the class PyTestCase method createRunConfigurationFromContext.

/**
   * Creates run configuration from right click menu
   *
   * @param fixture       test fixture
   * @param expectedClass expected class of run configuration
   * @param <C>           expected class of run configuration
   * @return configuration (if created) or null (otherwise)
   */
@Nullable
public static <C extends RunConfiguration> C createRunConfigurationFromContext(@NotNull final CodeInsightTestFixture fixture, @NotNull final Class<C> expectedClass) {
    final DataContext context = DataManager.getInstance().getDataContext(fixture.getEditor().getComponent());
    for (final RunConfigurationProducer<?> producer : RunConfigurationProducer.EP_NAME.getExtensions()) {
        final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(context));
        if (fromContext == null) {
            continue;
        }
        final C result = PyUtil.as(fromContext.getConfiguration(), expectedClass);
        if (result != null) {
            return result;
        }
    }
    return null;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-plugins by JetBrains.

the class CfmlRunConfigurationTest method getDefaultCfmlRunConfiguration.

public CfmlRunConfiguration getDefaultCfmlRunConfiguration() throws IOException {
    final Project project = myFixture.getProject();
    final Editor editor = openCfmFileInEditor(indexCfm);
    final Presentation presentation = getPresentationForRunAction(editor);
    assert editor != null;
    final DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
    TestCase.assertEquals("Run 'index.cfm'", presentation.getText());
    final ConfigurationContext configurationContext = ConfigurationContext.getFromContext(dataContext);
    final List<RunConfigurationProducer<?>> producers = RunConfigurationProducer.getProducers(project);
    List<ConfigurationFromContext> configs = new ArrayList<>();
    for (RunConfigurationProducer<?> producer : producers) {
        final ConfigurationFromContext configurationFromContext = producer.createConfigurationFromContext(configurationContext);
        if (configurationFromContext != null)
            configs.add(configurationFromContext);
    }
    TestCase.assertEquals(true, configs.size() == 1);
    final ConfigurationFromContext defaultConfigurationFromContext = configs.get(0);
    final RunConfiguration configuration = defaultConfigurationFromContext.getConfiguration();
    TestCase.assertNotNull(configuration);
    UsefulTestCase.assertInstanceOf(configuration, CfmlRunConfiguration.class);
    return (CfmlRunConfiguration) configuration;
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ArrayList(java.util.ArrayList) CfmlRunConfiguration(com.intellij.coldFusion.UI.runner.CfmlRunConfiguration) Project(com.intellij.openapi.project.Project) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) CfmlRunConfiguration(com.intellij.coldFusion.UI.runner.CfmlRunConfiguration) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Editor(com.intellij.openapi.editor.Editor)

Example 4 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-plugins by JetBrains.

the class JstdAssertionFrameworkLineMarkerProvider method execute.

private static void execute(@NotNull Executor executor, @NotNull final PsiElement element) {
    Project project = element.getProject();
    Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor == null) {
        return;
    }
    DataContext dataContext = createDataContext(editor, element);
    RunConfigurationProducer jstdOriginalProducer = getJstdRunConfigurationProducer();
    ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    boolean created = false;
    RunnerAndConfigurationSettings configuration = jstdOriginalProducer.findExistingConfiguration(context);
    if (configuration == null) {
        created = true;
        ConfigurationFromContext fromContext = jstdOriginalProducer.createConfigurationFromContext(context);
        if (fromContext != null) {
            configuration = fromContext.getConfigurationSettings();
        } else {
            return;
        }
    }
    execute(project, executor, configuration, created);
}
Also used : Project(com.intellij.openapi.project.Project) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) DataContext(com.intellij.openapi.actionSystem.DataContext) JstdRunConfigurationProducer(com.google.jstestdriver.idea.execution.JstdRunConfigurationProducer) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Editor(com.intellij.openapi.editor.Editor)

Example 5 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testProducedWhenInsideFuncallExpression.

@Test
public void testProducedWhenInsideFuncallExpression() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    assertThat(nameString).isNotNull();
    ConfigurationContext context = createContextFromPsi(nameString);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)38 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)34 PsiFile (com.intellij.psi.PsiFile)26 Test (org.junit.Test)26 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)24 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)24 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)21 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)21 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)11 PsiClass (com.intellij.psi.PsiClass)10 PsiElement (com.intellij.psi.PsiElement)5 PsiDirectory (com.intellij.psi.PsiDirectory)4 BallerinaApplicationConfiguration (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)4 BallerinaApplicationRunConfigurationProducer (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer)4 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)3 DataContext (com.intellij.openapi.actionSystem.DataContext)3 Project (com.intellij.openapi.project.Project)3 ScalaFile (org.jetbrains.plugins.scala.lang.psi.api.ScalaFile)3 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 Editor (com.intellij.openapi.editor.Editor)2