How to rerun programmatically the program

Hi, I want to programmatically rerun(There is a command for this also you can use ctrl-f5) Below is a picture of rhis button in idea
http://joxi.ru/uploads/prod/20130517/4b5/6cf/119d577d10bee5716a18d89056f2aa15d43eb9ce.png?v=2.1.2

So how I can run this action by myself?

9 comments
Comment actions Permalink

Hi Evgeniy,

You should use ExecutionManager.restartRunProfile() for that.

Default IJ implementation achieves that via RestartAction (the one from your screenshot).

Denis

0
Comment actions Permalink

Thank you, this helped me a lot :)

0
Comment actions Permalink

You are welcome

0
Comment actions Permalink

I did it and restarted the process sucessfully. But if I have two or more processes running, I cannot rerun all of them, it just reruns one of them
Here is my code

     ToolWindowManager manager = ToolWindowManager.getInstance(e.getProject());         ToolWindow window = manager.getToolWindow("Run");         if (window == null) {             return;         }         Content[] contents = window.getContentManager().getContents();         for (Content content : contents) {             final RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(e.getProject());             final Collection<RunnerAndConfigurationSettings> allConfigurations = runManager.getSortedConfigurations();             for (RunnerAndConfigurationSettings runConfiguration : allConfigurations) {                 if (content.getTabName().contains(runConfiguration.getName())) {                     String name = runConfiguration.getName();                     System.out.println(name);                     content.setDisplayName("!" + name);                     ExecutionManager.getInstance(e.getProject()).restartRunProfile(e.getProject(),                             DefaultRunExecutor.getRunExecutorInstance(),                             DefaultExecutionTarget.INSTANCE,                             runManager.findConfigurationByName(name),                             e.getData(RunContentManager.RUN_CONTENT_DESCRIPTOR));                 }             }         }

0
Comment actions Permalink

Try

ExecutionManager.getInstance(project).getContentManager().getAllDescriptors()

and then use them for restarting with ExecutionManager.getInstance(project).restartRunProfile()

Also you can invoke RunContentDescriptor.getRestarter().run()

0
Comment actions Permalink

I don't have method getAllDescriptors() in 12 version of IDEA ?:|

UPDATE: sorry, it was on RunContentManager, not in ContentManager, my fault

0
Comment actions Permalink

OK, code snipped has been updated, my fault too.


0
Comment actions Permalink

I used the way you suggested, but there is only one tab reruns from all tabs in Run wndow
Here is my new code

public void actionPerformed(final AnActionEvent e) {         Project project = e.getProject();         if (project == null) {             return;         }         ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow("Run");         if (window == null) {             return;         }         for (final Content content : window.getContentManager().getContents()) {             final RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);             final Collection<RunnerAndConfigurationSettings> allConfigurations = runManager.getSortedConfigurations();             for (RunnerAndConfigurationSettings runConfiguration : allConfigurations) {                 System.out.println(runConfiguration.getName());                 ExecutionManager executionManager = ExecutionManager.getInstance(project);                 RunContentDescriptor descriptor = content.getUserData(new Key<RunContentDescriptor>("Descriptor"));                 RunnerAndConfigurationSettings configurationByName = runManager.findConfigurationByName(runConfiguration.getName());                 if (configurationByName == null) {                     continue;                 }                 List<ExecutionTarget> targets = ExecutionTargetManager.getTargetsFor(project, configurationByName);                 for (ExecutionTarget target : targets) {                     executionManager.restartRunProfile(project,                             DefaultRunExecutor.getRunExecutorInstance(),                             target,                             configurationByName,                             descriptor);                 }                 turnOffCheckbox(content);             }         }     }

0
Comment actions Permalink

Now there is a bug and you cannot restart more than one running instance at the same time. It's going to be fixed in next 13 EAP. You can use this code snippet:

    ExecutionManager executionManager = ExecutionManager.getInstance(project);
    List<RunContentDescriptor> descriptors = executionManager.getContentManager().getAllDescriptors();
    for (RunContentDescriptor descriptor : descriptors) {
      descriptor.getRestarter().run();
    }

0

Please sign in to leave a comment.