22c17726ef7fde7d3c8a89011936bb18b619c78d
[idea/community.git] / platform / lang-api / src / com / intellij / execution / runners / GenericProgramRunner.java
1 /*
2  * Copyright 2000-2016 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.ExecutionException;
20 import com.intellij.execution.ExecutionManager;
21 import com.intellij.execution.RunProfileStarter;
22 import com.intellij.execution.configurations.RunProfileState;
23 import com.intellij.execution.configurations.RunnerSettings;
24 import com.intellij.execution.ui.RunContentDescriptor;
25 import com.intellij.openapi.actionSystem.DataKey;
26 import com.intellij.openapi.project.Project;
27 import org.jetbrains.annotations.NonNls;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30
31 public abstract class GenericProgramRunner<Settings extends RunnerSettings> extends BaseProgramRunner<Settings> {
32   @Deprecated
33   public static final DataKey<RunContentDescriptor> CONTENT_TO_REUSE_DATA_KEY = DataKey.create("contentToReuse");
34   @SuppressWarnings({"UnusedDeclaration", "deprecation"}) @Deprecated @NonNls
35   public static final String CONTENT_TO_REUSE = CONTENT_TO_REUSE_DATA_KEY.getName();
36
37   @Override
38   protected void execute(@NotNull ExecutionEnvironment environment, @Nullable final Callback callback, @NotNull RunProfileState state)
39     throws ExecutionException {
40     ExecutionManager.getInstance(environment.getProject()).startRunProfile(new RunProfileStarter() {
41       @Override
42       public RunContentDescriptor execute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
43         return postProcess(environment, doExecute(state, environment), callback);
44       }
45     }, state, environment);
46   }
47
48   @Nullable
49   protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
50     return doExecute(environment.getProject(), state, environment.getContentToReuse(), environment);
51   }
52
53   /**
54    * @deprecated to remove in IDEA 16
55    */
56   @Deprecated
57   @Nullable
58   protected RunContentDescriptor doExecute(@NotNull Project project,
59                                            @NotNull RunProfileState state,
60                                            @Nullable RunContentDescriptor contentToReuse,
61                                            @NotNull ExecutionEnvironment environment) throws ExecutionException {
62     throw new AbstractMethodError();
63   }
64 }