Search in sources :

Example 6 with ConfigurationFromContext

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

the class FlexUnitConfigurationTest method doTest.

private void doTest(String filename) throws Exception {
    configureByFile(BASE_PATH + filename);
    final Map<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
    assertFalse("No caret markers found", markers.isEmpty());
    assertFalse("No 'expected' value", markers.containsValue(null));
    final DataContext dataContext = DataManager.getInstance().getDataContext(getEditor().getComponent());
    int i = 1;
    for (Map.Entry<Integer, String> marker : markers.entrySet()) {
        String place = filename + ": marker " + i++ + ": ";
        getEditor().getCaretModel().moveToOffset(marker.getKey());
        final ConfigurationFromContext configurationFromContext = new FlexUnitRuntimeConfigurationProducer().createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
        final RunConfiguration configuration = configurationFromContext == null ? null : configurationFromContext.getConfiguration();
        if ("null".equals(marker.getValue())) {
            assertNull(place + "Null configuration expected", configuration);
        } else {
            assertNotNull(place + "Not null configuration expected", configuration);
            assertTrue(place + "Invalid configuration", configuration instanceof FlexUnitRunConfiguration);
            final String[] expected;
            if ("null".equals(marker.getValue())) {
                expected = null;
            } else {
                expected = marker.getValue().split(" ");
                assertEquals(place + "Expected should be in the form: \"Class com.test.Foo\" or \"Method com.test.Foo.testBar()\" or \"Package com.test\"", 2, expected.length);
            }
            final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) configuration).getRunnerParameters();
            assertEquals(place + "Invalid scope", expected[0], params.getScope().name());
            final String definition;
            switch(params.getScope()) {
                case Class:
                    definition = params.getClassName();
                    break;
                case Method:
                    definition = params.getClassName() + "." + params.getMethodName() + "()";
                    break;
                case Package:
                    definition = params.getPackageName();
                    break;
                default:
                    fail(place + "Unknown scope: " + params.getScope());
                    definition = null;
            }
            assertEquals(place + "Invalid definition", expected[1], definition);
        }
    }
}
Also used : FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) FlexUnitRuntimeConfigurationProducer(com.intellij.lang.javascript.flex.flexunit.FlexUnitRuntimeConfigurationProducer) DataContext(com.intellij.openapi.actionSystem.DataContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Map(java.util.Map)

Example 7 with ConfigurationFromContext

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

the class BaseConfigurationTestCase method createJUnitConfiguration.

protected JUnitConfiguration createJUnitConfiguration(@NotNull PsiElement psiElement, @NotNull Class<? extends AbstractJavaTestConfigurationProducer> producerClass, @NotNull MapDataContext dataContext) {
    ConfigurationContext context = createContext(psiElement, dataContext);
    RunConfigurationProducer producer = RunConfigurationProducer.getInstance(producerClass);
    assert producer != null;
    ConfigurationFromContext fromContext = producer.createConfigurationFromContext(context);
    assertNotNull(fromContext);
    return (JUnitConfiguration) fromContext.getConfiguration();
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfigurationProducer(com.intellij.execution.actions.RunConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration)

Example 8 with ConfigurationFromContext

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

the class GroovyScriptRunConfigurationProducer method createConfigurationByElement.

@Override
protected RunnerAndConfigurationSettings createConfigurationByElement(final Location location, final ConfigurationContext context) {
    final PsiElement element = location.getPsiElement();
    final PsiFile file = element.getContainingFile();
    if (!(file instanceof GroovyFile)) {
        return null;
    }
    GroovyFile groovyFile = (GroovyFile) file;
    final PsiClass aClass = GroovyRunnerPsiUtil.getRunningClass(location.getPsiElement());
    if (aClass instanceof GroovyScriptClass || GroovyRunnerPsiUtil.isRunnable(aClass)) {
        final RunnerAndConfigurationSettings settings = createConfiguration(aClass);
        if (settings != null) {
            mySourceElement = element;
            final GroovyScriptRunConfiguration configuration = (GroovyScriptRunConfiguration) settings.getConfiguration();
            GroovyScriptUtil.getScriptType(groovyFile).tuneConfiguration(groovyFile, configuration, location);
            return settings;
        }
    }
    if (file.getText().contains("@Grab")) {
        ApplicationConfigurationProducer producer = new ApplicationConfigurationProducer();
        ConfigurationFromContext settings = producer.createConfigurationFromContext(context);
        if (settings != null) {
            PsiElement src = settings.getSourceElement();
            mySourceElement = src;
            return createConfiguration(src instanceof PsiMethod ? ((PsiMethod) src).getContainingClass() : (PsiClass) src);
        }
        return null;
    } else {
        return null;
    }
}
Also used : GroovyScriptClass(org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GroovyScriptClass) ApplicationConfigurationProducer(com.intellij.execution.application.ApplicationConfigurationProducer) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile)

Aggregations

ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)8 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)4 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)4 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)3 DataContext (com.intellij.openapi.actionSystem.DataContext)3 Project (com.intellij.openapi.project.Project)3 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)2 Editor (com.intellij.openapi.editor.Editor)2 JstdRunConfigurationProducer (com.google.jstestdriver.idea.execution.JstdRunConfigurationProducer)1 CfmlRunConfiguration (com.intellij.coldFusion.UI.runner.CfmlRunConfiguration)1 PsiLocation (com.intellij.execution.PsiLocation)1 ApplicationConfigurationProducer (com.intellij.execution.application.ApplicationConfigurationProducer)1 JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)1 FlexUnitRunConfiguration (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration)1 FlexUnitRunnerParameters (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters)1 FlexUnitRuntimeConfigurationProducer (com.intellij.lang.javascript.flex.flexunit.FlexUnitRuntimeConfigurationProducer)1 WriteExternalException (com.intellij.openapi.util.WriteExternalException)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 MapDataContext (com.intellij.testFramework.MapDataContext)1