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?
There isn't much functionality on the base
RunConfiguration- the only provided setter functions relevant to your question aresetName,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
PythonRunConfigurationwhich has additional setter methods to fine-tune the configuration. What setters are available will vary betweenConfigurationTypesbut for the Python class the following additional setters are available:setScriptName- set the name (path) of the script that is runsetScriptParameters- sets the arguments passed to the scriptsetShowCommandLineAfterwards- determines if the python console will open after executionsetEmulateTerminal- determines if terminal commands will be emulatedreadExternal- read in settings from an external XML filesetModuleMode- whether the script will be invoked as a Python modulesetRedirectInput- whether to redirect input to a file or notsetInputFile- if the above is true, the file that inputs will be redirected toHere's a quick example of creating a new config and setting properties: