Process started through RunConfiguration won't exit
Answered
Hello,
I'm currently developing a plugin that allows the user to create a run configuration, that executes Groovy code on a remote server. It is completed to a point where I have a custom form, can create instances of my configuration and run them. Currently the configuration is only printing some text on the console.
Unfortunally the process that my configuration started seems to never exit. I always have to manually stop the process or it keeps running indefinitely. What am I missing in my implementation?
public class GroovyConsoleRunConfiguration extends LocatableConfigurationBase {
private String groovyScriptPath = "";
protected GroovyConsoleRunConfiguration(final Project project, @NotNull final ConfigurationFactory factory, final String name) {
super(project, factory, name);
}
@NotNull
@Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new GroovyConsoleSettingsEditor(getProject());
}
@Nullable
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment executionEnvironment) throws ExecutionException {
return new GroovyConsoleState(this, getProject());
}
public String getGroovyScriptPath(){
return groovyScriptPath;
}
}
public class GroovyConsoleState implements RunProfileState {
private GroovyConsoleRunConfiguration runConfiguration;
private Project project;
public GroovyConsoleState(final GroovyConsoleRunConfiguration runConfiguration, final Project project) {
this.runConfiguration = runConfiguration;
this.project = project;
}
@Nullable
@Override
public ExecutionResult execute(final Executor executor, @NotNull final ProgramRunner programRunner) throws ExecutionException {
final TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(project);
final ConsoleView console = consoleBuilder.getConsole();
console.print("Executing Groovy Console! (SYSTEM)\n", ConsoleViewContentType.SYSTEM_OUTPUT);
console.print("Executing Groovy Console! (ERROR)\n", ConsoleViewContentType.ERROR_OUTPUT);
console.print("Executing Groovy Console! (NORMAL)", ConsoleViewContentType.NORMAL_OUTPUT);
return new DefaultExecutionResult(console, new NopProcessHandler());
}
}
I don't need to execute any external programs. The whole process of calling the remote server and transmitting the Groovy code will be implemented in the plugin itself.
Best Regards
Please sign in to leave a comment.
You should link your remote 'caller' and ProcessHandler mentioned above (
) to be mutual 'destroyers'. After remote calling you should invoke method handler.destroyProcess() and vise versa during the process termination (for example when user press Stop button) you should call some cancel() in your remote caller.
Ok, that solved my issue.
Thank you!
Sorry to revive this thread. This is exactly what I'm looking for but I don't understand fully what the solution was. Can someone here give a code snippet on how to do the mutual destroyers?
Ok, I undestand it now. I just needed a break before I could understand it. Thanks!