Saving a run configuration in the run configuration dropdown
Hi - I wrote a small plugin that launches a run configuration programmatically. Code is given below.
What I want to do next is to save that run configuration to the run configuration dropdown. Right now it's not.
I believe having that run configuration saved would allow the user to debug the same run configuration or to run it again with Shift F10. Is that right?
Any other advice on the code is also welcome as this is my first plugin. The full code is on github.
Thanks a lot.
Matt
{
// .... snipped ....
Project project = e.getData(PlatformDataKeys.PROJECT);
String moduleNameOfRunner = component.getModuleNameOfRunner();
VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
RunManager runManager = RunManager.getInstance(project);
Module module = ModuleManager.getInstance(project).findModuleByName(moduleNameOfRunner);
String filename = file.getPath();
MyRunnerConfigurationType type = new MyRunnerConfigurationType(module, mainClassName, filename);
RunConfiguration runConfiguration = type.getConfigurationFactories()[0].createTemplateConfiguration(project);
RunnerAndConfigurationSettings runnerAndConfigurationSettings = runManager.createRunConfiguration("My Runner", type.getConfigurationFactories()[0]);
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), runConfiguration);
ExecutionEnvironment environment = new ExecutionEnvironment(runner, runnerAndConfigurationSettings, e.getDataContext());
try {
runner.execute(executor, environment);
} catch (ExecutionException e1) {
JavaExecutionUtil.showExecutionErrorMessage(e1, "Error", project);
}
}
Please sign in to leave a comment.
By the way, I'm trying to figure out how to save the run configuration into that dropdown. Anyone knows?
Thanks.
Hello,
firstly it is better to obtain instance of MyRunnerConfigurationType from ConfigurationTypeUtil.findConfigurationType method
(MyRunnerConfigurationType is registered as configurationType extension, right?) rather than create a new instance.
Also you don't need to call createTemplateConfiguration() by hand because a RunConfiguration instance is created in
runManager.createRunConfiguration(...) method. You can obtain it by using runnerAndConfigurationSettings.getConfiguration().
Regarding your question: there are no way to add a run configuration to the dropdown via Open API. However you can do it using
RunManagerEx.getInstanceEx(project).addConfiguration(runnerAndConfigurationSettings, false) method call. Source code of RunManagerEx class can be
found in IDEA Community Edition sources.
>
>
>
>
>
>
>
>
--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Thanks Nikolay.
That was good info.
I was able to hook my run configuration to the dropdown unless it is there already. Hopefully my code can help someone else:
I don't fully udnerstand why the whole API is not accessible for plugin developers though. The RunManager interface is really restrictive.
Thanks,
Matt