How to run rake-task in RubyMine using OpenAPI?

Hello.
How can I run rake-task in RubyMine using OpenAPI and capture all output into a string?
How can I specify what RubyOnRails environment (producion/development) to use for this task?

Thanks.

3 comments

Hi Basil,

For what do you ned it? You are writing some java plugin for RubyMine which launches Rake tasks and does smth with it output? Currenlty there is no OpenAPI for launching Rake tasks.

0

Yes. I'm wrinting a plugin which should run some rake task, then analyse output and provide some useful information. You said that OpenAPI does not have this functionality, but how does RubyMine collect available tasks? How does it migrate database? This is rake task and it's executed in some way when I select needed migration in RubyMine dialog. I assume that it can be made not via OpenAPI, but could you please tell what is the proper way to do this?
Thank you.

0

but how does RubyMine collect available tasks?

RubyMine collects tasks and launches them using separate ways. To collect rake tasks RubyMine launches 'rake' script provided by rake gem with necessary options. Actually we lauch it 2 times - for documented (rake --tasks --trace) and undocumented (rake --prereqs --trace) tasks. You can lauch a script provided by gem using:

package org.jetbrains.plugins.ruby.gem;

public class GemsRunner {
  // ...

/**    * Returns output after execution.    *    * @param sdk Ruby sdk    * @param module       Module    * @param rubyScriptName  Gem Executable ruby script name. (e.g. rails, spec, rake)    * @param workingDir    working directory    * @param mode Execution mode    * @param showStdErrErrors   If true, all data from stderr will be shown as errors in Message tab. In this case project must be not null!    * @param errorTitle If showStdErrors is set this title will be used in console. If null, standard error title will be used.    * @param arguments Script arguments    * @return Output    *    */

   @Nullable
   public static Output runGemsExecutableScript(@NotNull final Sdk sdk,

                                               @Nullable final Module module,                                                @NotNull final String gemName,                                                @NotNull final String rubyScriptName,                                                @Nullable final String workingDir,                                                @NotNull final ExecutionMode mode,                                                final boolean showStdErrErrors,                                                @Nullable final String errorTitle,                                                @NotNull final String... arguments) throws ExecutionException {...}
   //...
}


Where
  • Sdk and Module are from idea openapi
  • com.intellij.execution.Output and com.intellij.execution.ExecutionModes source are available in IDEA community edition sources


E.g. documented_tasks_output = GemsRunner.runGemsExecutableScript(sdk, module, "rake", "rake", module_content_root, new ExecutionModes.SameThreadMode(), false, errorTitle, "--tasks","--trace");

Bundler exec emulation will be turen on If module contains dependency on bunlder gem and Gemfile & Gemfile.lock files exists. Output is a pair of dumped stdout and stderr output. I think you can use these way.

How does it migrate database? This is rake task and it's executed in some way when I select needed migration in RubyMine dialog. I assume that it can be made not via OpenAPI, but could you please tell what is the proper way to do this?


RubyMine lauches Rake tasks using fake Rake run configuration. RubyMine automatically generates and configures such run configurations. Main advantage is that user can configure whether use bundler, trace, etc. options; consider test output as tests results or not, etc. But I don't think that you can easily reuse it for your purposes. In such case RubyMine always shows run configuration console and you can only add output listener to it.
0

Please sign in to leave a comment.