637729d795ccaecb61ebc5d73220c5802bd53d5a
[idea/community.git] / platform / lang-api / src / com / intellij / execution / runners / BaseProgramRunner.java
1 /*
2  * Copyright 2000-2014 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.intellij.execution.runners;
18
19 import com.intellij.execution.*;
20 import com.intellij.execution.configurations.*;
21 import com.intellij.execution.ui.RunContentDescriptor;
22 import com.intellij.openapi.options.SettingsEditor;
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
25
26 abstract class BaseProgramRunner<Settings extends RunnerSettings> implements ProgramRunner<Settings> {
27   @Override
28   @Nullable
29   public Settings createConfigurationData(ConfigurationInfoProvider settingsProvider) {
30     return null;
31   }
32
33   @Override
34   public void checkConfiguration(RunnerSettings settings, ConfigurationPerRunnerSettings configurationPerRunnerSettings)
35     throws RuntimeConfigurationException {
36   }
37
38   @Override
39   public void onProcessStarted(RunnerSettings settings, ExecutionResult executionResult) {
40   }
41
42   @Override
43   @Nullable
44   public SettingsEditor<Settings> getSettingsEditor(Executor executor, RunConfiguration configuration) {
45     return null;
46   }
47
48   @Override
49   public void execute(@NotNull ExecutionEnvironment environment) throws ExecutionException {
50     execute(environment, null);
51   }
52
53   @Override
54   public void execute(@NotNull ExecutionEnvironment environment, @Nullable Callback callback) throws ExecutionException {
55     RunProfileState state = environment.getState();
56     if (state == null) {
57       return;
58     }
59
60     RunManager.getInstance(environment.getProject()).refreshUsagesList(environment.getRunProfile());
61     execute(environment, callback, state);
62   }
63
64   protected abstract void execute(@NotNull ExecutionEnvironment environment,
65                                   @Nullable Callback callback,
66                                   @NotNull RunProfileState state) throws ExecutionException;
67
68   @Nullable
69   static RunContentDescriptor postProcess(@NotNull ExecutionEnvironment environment, @Nullable RunContentDescriptor descriptor, @Nullable Callback callback) {
70     if (descriptor != null) {
71       descriptor.setExecutionId(environment.getExecutionId());
72       RunnerAndConfigurationSettings settings = environment.getRunnerAndConfigurationSettings();
73       if (settings != null) {
74         descriptor.setActivateToolWindowWhenAdded(settings.isActivateToolWindowBeforeRun());
75       }
76     }
77     if (callback != null) {
78       callback.processStarted(descriptor);
79     }
80     return descriptor;
81   }
82 }