0

In my InteliJ plugin I want to modify (e.g. the main class name of a JUnit run configuration) the properties of an existing run configuration and execute the modified version afterwards. I can get the related config object and execute it:

final RunManager runManager = RunManager.getInstance(project);
List<RunConfiguration> configs = runManager.getAllConfigurationsList();

String configName = "NameOfRunConfig";

RunConfiguration runConfigurationToExecute = null;

for (RunConfiguration config : configs) {
  if(configName.equalsIgnoreCase(config.getName())){
    runConfigurationToExecute = config;
    break;
  }
}

if (runConfigurationToExecute == null) {
  Messages.showInfoMessage(
     "No run config \"" + configName + "\" found.",
     "MyPlugin"
  );

  return;
}

//TODO: Adjust properties of the configuration
//runConfigurationToExecute

Executor executorToUse = DefaultRunExecutor.getRunExecutorInstance();

ExecutionEnvironmentBuilder.create(project, executorToUse, runConfigurationToExecute).buildAndExecute();

But I can't find I way to modify it. Can somebody tell me how to modify the properties?

Bernd
  • 1

1 Answers1

0

There isn't much functionality on the base RunConfiguration - the only provided setter functions relevant to your question are setName, setBeforeRunTasks, setAllowRunningInParallel. Instead, it seems that the intention is to use a specific subclass of RunConfiguration which is intended for the particular language or runtime that you are using.

For example, if I were using Python I would utilize the PythonRunConfiguration which has additional setter methods to fine-tune the configuration. What setters are available will vary between ConfigurationTypes but for the Python class the following additional setters are available:

  • setScriptName - set the name (path) of the script that is run
  • setScriptParameters - sets the arguments passed to the script
  • setShowCommandLineAfterwards - determines if the python console will open after execution
  • setEmulateTerminal - determines if terminal commands will be emulated
  • readExternal - read in settings from an external XML file
  • setModuleMode - whether the script will be invoked as a Python module
  • setRedirectInput - whether to redirect input to a file or not
  • setInputFile - if the above is true, the file that inputs will be redirected to

Here's a quick example of creating a new config and setting properties:

final RunManager runManager = RunManager.getInstance(project);
RunnerAndConfigurationSettings settings = runManager.createConfiguration("My Example Config", PythonConfigurationType.class);
PythonRunConfiguration configuration = (PythonRunConfiguration) settings.configuration;

configuration.setScriptName("/path/to/my/script.py");
configuration.setShowCommandLineAfterwards(true);