2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.execution
.runners
;
19 import com
.intellij
.execution
.ExecutionException
;
20 import com
.intellij
.execution
.ExecutionManager
;
21 import com
.intellij
.execution
.ExecutionResult
;
22 import com
.intellij
.execution
.Executor
;
23 import com
.intellij
.execution
.configurations
.*;
24 import com
.intellij
.execution
.process
.ProcessHandler
;
25 import com
.intellij
.execution
.ui
.RunContentDescriptor
;
26 import com
.intellij
.history
.LocalHistory
;
27 import com
.intellij
.history
.LocalHistoryConfiguration
;
28 import com
.intellij
.openapi
.actionSystem
.AnAction
;
29 import com
.intellij
.openapi
.actionSystem
.DataContext
;
30 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
31 import com
.intellij
.openapi
.application
.ApplicationManager
;
32 import com
.intellij
.openapi
.options
.SettingsEditor
;
33 import com
.intellij
.openapi
.project
.Project
;
34 import com
.intellij
.openapi
.util
.JDOMExternalizable
;
35 import org
.jetbrains
.annotations
.NonNls
;
36 import org
.jetbrains
.annotations
.NotNull
;
37 import org
.jetbrains
.annotations
.Nullable
;
42 public abstract class GenericProgramRunner
<Settings
extends JDOMExternalizable
> implements ProgramRunner
<Settings
> {
44 * @see com.intellij.execution.ui.RunContentDescriptor#myContent
46 @NonNls public static final String CONTENT_TO_REUSE
= "contentToReuse";
49 public Settings
createConfigurationData(final ConfigurationInfoProvider settingsProvider
) {
53 public void checkConfiguration(final RunnerSettings settings
, final ConfigurationPerRunnerSettings configurationPerRunnerSettings
)
54 throws RuntimeConfigurationException
{
57 public void onProcessStarted(final RunnerSettings settings
, final ExecutionResult executionResult
) {
60 public AnAction
[] createActions(final ExecutionResult executionResult
) {
61 return AnAction
.EMPTY_ARRAY
;
65 public SettingsEditor
<Settings
> getSettingsEditor(final Executor executor
, final RunConfiguration configuration
) {
69 public void execute(@NotNull final Executor executor
, @NotNull final ExecutionEnvironment environment
) throws ExecutionException
{
70 execute(executor
, environment
, null);
73 public void execute(@NotNull final Executor executor
, @NotNull final ExecutionEnvironment env
, @Nullable final Callback callback
)
74 throws ExecutionException
{
75 final DataContext dataContext
= env
.getDataContext();
76 final RunProfile profile
= env
.getRunProfile();
78 final Project project
= PlatformDataKeys
.PROJECT
.getData(dataContext
);
79 if (project
== null) {
82 final RunContentDescriptor reuseContent
=
83 ExecutionManager
.getInstance(project
).getContentManager().getReuseContent(executor
, dataContext
);
85 final RunProfileState state
= env
.getState(executor
);
90 Runnable startRunnable
= new Runnable() {
93 if (project
.isDisposed()) return;
95 final RunContentDescriptor descriptor
=
96 doExecute(project
, executor
, state
, reuseContent
, env
);
98 if (callback
!= null) callback
.processStarted(descriptor
);
100 if (descriptor
!= null) {
101 if (LocalHistoryConfiguration
.getInstance().ADD_LABEL_ON_RUNNING
) {
102 LocalHistory
.putSystemLabel(project
, executor
.getId() + " " + profile
.getName());
105 ExecutionManager
.getInstance(project
).getContentManager().showRunContent(executor
, descriptor
);
106 final ProcessHandler processHandler
= descriptor
.getProcessHandler();
107 if (processHandler
!= null) processHandler
.startNotify();
110 catch (ExecutionException e
) {
111 ProgramRunnerUtil
.handleExecutionError(project
, profile
, e
);
115 if (ApplicationManager
.getApplication().isUnitTestMode()) {
119 ExecutionManager
.getInstance(project
).compileAndRun(startRunnable
, profile
, state
);
124 protected abstract RunContentDescriptor
doExecute(final Project project
, final Executor executor
, final RunProfileState state
,
125 final RunContentDescriptor contentToReuse
,
126 final ExecutionEnvironment env
) throws ExecutionException
;