Search in sources :

Example 6 with RunnerAndConfigurationSettings

use of com.intellij.execution.RunnerAndConfigurationSettings 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 7 with RunnerAndConfigurationSettings

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

the class GroovyScriptRunConfigurationProducer method createConfiguration.

@Nullable
private RunnerAndConfigurationSettings createConfiguration(@Nullable final PsiClass aClass) {
    if (aClass == null)
        return null;
    final Project project = aClass.getProject();
    RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).createConfiguration("", getConfigurationFactory());
    final GroovyScriptRunConfiguration configuration = (GroovyScriptRunConfiguration) settings.getConfiguration();
    final PsiFile file = aClass.getContainingFile().getOriginalFile();
    final PsiDirectory dir = file.getContainingDirectory();
    if (dir != null) {
        configuration.setWorkingDirectory(dir.getVirtualFile().getPath());
    }
    final VirtualFile vFile = file.getVirtualFile();
    if (vFile == null)
        return null;
    String path = ScriptFileUtil.getScriptFilePath(vFile);
    configuration.setScriptPath(path);
    RunConfigurationModule module = configuration.getConfigurationModule();
    String name = GroovyRunnerUtil.getConfigurationName(aClass, module);
    configuration.setName(StringUtil.isEmpty(name) ? vFile.getName() : name);
    configuration.setModule(JavaExecutionUtil.findModule(aClass));
    return settings;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) RunConfigurationModule(com.intellij.execution.configurations.RunConfigurationModule) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with RunnerAndConfigurationSettings

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

the class AbstractTestNGSuiteConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final PsiElement element = context.getPsiLocation();
    final PsiFile containingFile = element != null ? element.getContainingFile() : null;
    if (containingFile == null)
        return false;
    final VirtualFile virtualFile = containingFile.getVirtualFile();
    if (virtualFile == null || !virtualFile.isValid())
        return false;
    if (!TestNGUtil.isTestngXML(virtualFile))
        return false;
    RunnerAndConfigurationSettings settings = cloneTemplateConfiguration(context);
    setupConfigurationModule(context, configuration);
    final Module originalModule = configuration.getConfigurationModule().getModule();
    configuration.getPersistantData().SUITE_NAME = virtualFile.getPath();
    configuration.getPersistantData().TEST_OBJECT = TestType.SUITE.getType();
    configuration.restoreOriginalModule(originalModule);
    configuration.setGeneratedName();
    settings.setName(configuration.getName());
    sourceElement.set(containingFile);
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 9 with RunnerAndConfigurationSettings

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

the class PyRunConfigurationFactoryImpl method createPythonScriptRunConfiguration.

@Override
public PythonRunConfigurationParams createPythonScriptRunConfiguration(Module module, String scriptName, boolean singleton) {
    RunnerAndConfigurationSettings settings = createRunConfiguration(module, PythonConfigurationType.getInstance().getFactory());
    settings.setSingleton(singleton);
    PythonRunConfigurationParams configuration = (PythonRunConfigurationParams) settings.getConfiguration();
    configuration.setScriptName(scriptName);
    return configuration;
}
Also used : RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings)

Example 10 with RunnerAndConfigurationSettings

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

the class DocutilsConfigurationProducer method findExistingByElement.

@Nullable
@Override
protected RunnerAndConfigurationSettings findExistingByElement(Location location, @NotNull List<RunnerAndConfigurationSettings> existingConfigurations, ConfigurationContext context) {
    PsiFile script = location.getPsiElement().getContainingFile();
    if (script == null) {
        return null;
    }
    final VirtualFile vFile = script.getVirtualFile();
    if (vFile == null) {
        return null;
    }
    String path = vFile.getPath();
    for (RunnerAndConfigurationSettings configuration : existingConfigurations) {
        final String scriptName = ((RestRunConfiguration) configuration.getConfiguration()).getInputFile();
        if (FileUtil.toSystemIndependentName(scriptName).equals(FileUtil.toSystemIndependentName(path))) {
            return configuration;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiFile(com.intellij.psi.PsiFile) RestRunConfiguration(com.jetbrains.rest.run.RestRunConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)104 Project (com.intellij.openapi.project.Project)24 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)16 RunManagerEx (com.intellij.execution.RunManagerEx)14 Nullable (org.jetbrains.annotations.Nullable)14 RunManager (com.intellij.execution.RunManager)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Module (com.intellij.openapi.module.Module)10 NotNull (org.jetbrains.annotations.NotNull)9 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)7 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)7 ExternalSystemRunConfiguration (com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration)7 ExternalSystemTaskExecutionSettings (com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings)6 Executor (com.intellij.execution.Executor)4 RunManagerImpl (com.intellij.execution.impl.RunManagerImpl)4 AbstractExternalSystemTaskConfigurationType (com.intellij.openapi.externalSystem.service.execution.AbstractExternalSystemTaskConfigurationType)4 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)4 RunConfigurationNode (com.intellij.openapi.externalSystem.view.RunConfigurationNode)4 PsiElement (com.intellij.psi.PsiElement)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)3