Search in sources :

Example 1 with CommonProgramRunConfigurationParametersDelegate

use of org.jetbrains.plugins.groovy.runner.util.CommonProgramRunConfigurationParametersDelegate in project intellij-community by JetBrains.

the class GroovyScriptRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final VirtualFile scriptFile = ScriptFileUtil.findScriptFileByPath(getScriptPath());
    if (scriptFile == null)
        return null;
    final GroovyScriptRunner scriptRunner = getScriptRunner();
    if (scriptRunner == null)
        return null;
    return new JavaCommandLineState(environment) {

        @NotNull
        @Override
        protected OSProcessHandler startProcess() throws ExecutionException {
            final OSProcessHandler handler = super.startProcess();
            handler.setShouldDestroyProcessRecursively(true);
            if (scriptRunner.shouldRefreshAfterFinish()) {
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void processTerminated(ProcessEvent event) {
                        if (!ApplicationManager.getApplication().isDisposed()) {
                            VirtualFileManager.getInstance().asyncRefresh(null);
                        }
                    }
                });
            }
            return handler;
        }

        @Override
        protected JavaParameters createJavaParameters() throws ExecutionException {
            final Module module = getModule();
            final boolean tests = ProjectRootManager.getInstance(getProject()).getFileIndex().isInTestSourceContent(scriptFile);
            String jrePath = isAlternativeJrePathEnabled() ? getAlternativeJrePath() : null;
            JavaParameters params = new JavaParameters();
            params.setUseClasspathJar(true);
            params.setDefaultCharset(getProject());
            params.setJdk(module == null ? JavaParametersUtil.createProjectJdk(getProject(), jrePath) : JavaParametersUtil.createModuleJdk(module, !tests, jrePath));
            configureConfiguration(params, new CommonProgramRunConfigurationParametersDelegate(GroovyScriptRunConfiguration.this) {

                @Nullable
                @Override
                public String getProgramParameters() {
                    return null;
                }
            });
            scriptRunner.configureCommandLine(params, module, tests, scriptFile, GroovyScriptRunConfiguration.this);
            return params;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommonProgramRunConfigurationParametersDelegate(org.jetbrains.plugins.groovy.runner.util.CommonProgramRunConfigurationParametersDelegate) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Nullable (org.jetbrains.annotations.Nullable)1 CommonProgramRunConfigurationParametersDelegate (org.jetbrains.plugins.groovy.runner.util.CommonProgramRunConfigurationParametersDelegate)1