2 * Copyright 2000-2014 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.
16 package com.intellij.execution;
18 import com.intellij.execution.configurations.ConfigurationFactory;
19 import com.intellij.execution.configurations.ConfigurationType;
20 import com.intellij.execution.configurations.RunConfiguration;
21 import com.intellij.execution.configurations.RunProfile;
22 import com.intellij.openapi.project.Project;
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.regex.Matcher;
29 import java.util.regex.Pattern;
32 * Manages the list of run/debug configurations in a project.
36 * @see ExecutionManager
38 public abstract class RunManager {
39 public static RunManager getInstance(final Project project) {
40 return project.getComponent(RunManager.class);
44 * Returns the list of all registered configuration types.
46 * @return all registered configuration types.
49 public abstract ConfigurationType[] getConfigurationFactories();
52 * Returns the list of all configurations of a specified type.
54 * @param type a run configuration type.
55 * @return all configurations of the type, or an empty array if no configurations of the type are defined.
59 public abstract RunConfiguration[] getConfigurations(@NotNull ConfigurationType type);
62 * Returns the list of all configurations of a specified type.
64 * @param type a run configuration type.
65 * @return all configurations of the type, or an empty array if no configurations of the type are defined.
68 public abstract List<RunConfiguration> getConfigurationsList(@NotNull ConfigurationType type);
71 * Returns the list of {@link RunnerAndConfigurationSettings} for all configurations of a specified type.
73 * @param type a run configuration type.
74 * @return settings for all configurations of the type, or an empty array if no configurations of the type are defined.
78 public abstract RunnerAndConfigurationSettings[] getConfigurationSettings(@NotNull ConfigurationType type);
81 * Returns the list of {@link RunnerAndConfigurationSettings} for all configurations of a specified type.
83 * @param type a run configuration type.
84 * @return settings for all configurations of the type, or an empty array if no configurations of the type are defined.
87 public abstract List<RunnerAndConfigurationSettings> getConfigurationSettingsList(@NotNull ConfigurationType type);
90 * Returns the list of all run configurations.
92 * @return the list of all run configurations.
96 public abstract RunConfiguration[] getAllConfigurations();
99 * Returns the list of all run configurations.
101 * @return the list of all run configurations.
104 public abstract List<RunConfiguration> getAllConfigurationsList();
107 * Returns the list of all run configurations settings.
109 * @return the list of all run configurations settings.
112 public abstract List<RunnerAndConfigurationSettings> getAllSettings();
115 * Returns the list of all temporary run configurations.
117 * @return the list of all temporary run configurations.
118 * @see RunnerAndConfigurationSettings#isTemporary()
122 public abstract RunConfiguration[] getTempConfigurations();
125 * Returns the list of all temporary run configurations settings.
127 * @return the list of all temporary run configurations settings.
128 * @see RunnerAndConfigurationSettings#isTemporary()
131 public abstract List<RunnerAndConfigurationSettings> getTempConfigurationsList();
134 * Checks if the specified run configuration is temporary and will be deleted when the temporary configurations limit is exceeded.
136 * @return true if the configuration is temporary, false otherwise.
137 * @see RunnerAndConfigurationSettings#isTemporary()
140 public abstract boolean isTemporary(@NotNull RunConfiguration configuration);
143 * Saves the specified temporary run configuration and makes it a permanent one.
145 * @param configuration the temporary run configuration to save.
148 public abstract void makeStable(@NotNull RunConfiguration configuration);
151 * Saves the specified temporary run settings and makes it a permanent one.
153 * @param settings the temporary settings to save.
155 public abstract void makeStable(@NotNull RunnerAndConfigurationSettings settings);
158 * Returns the selected item in the run/debug configurations combobox.
160 * @return the selected configuration, or null if no configuration is defined or selected.
163 public abstract RunnerAndConfigurationSettings getSelectedConfiguration();
166 * Selects a configuration in the run/debug configurations combobox.
168 * @param configuration the configuration to select, or null if nothing should be selected.
170 public abstract void setSelectedConfiguration(@Nullable RunnerAndConfigurationSettings configuration);
173 * Creates a configuration of the specified type with the specified name. Note that you need to call
174 * {@link #addConfiguration(RunnerAndConfigurationSettings, boolean)} if you want the configuration to be persisted in the project.
176 * @param name the name of the configuration to create (should be unique and not equal to any other existing configuration)
177 * @param type the type of the configuration to create.
178 * @return the configuration settings object.
179 * @see RunManager#suggestUniqueName(String, Collection)
182 public abstract RunnerAndConfigurationSettings createRunConfiguration(@NotNull String name, @NotNull ConfigurationFactory type);
185 * Creates a configuration settings object based on a specified {@link RunConfiguration}. Note that you need to call
186 * {@link #addConfiguration(RunnerAndConfigurationSettings, boolean)} if you want the configuration to be persisted in the project.
188 * @param runConfiguration the run configuration
189 * @param factory the factory instance.
190 * @return the configuration settings object.
193 public abstract RunnerAndConfigurationSettings createConfiguration(@NotNull RunConfiguration runConfiguration, @NotNull ConfigurationFactory factory);
196 * Returns the template settings for the specified configuration type.
198 * @param factory the configuration factory.
199 * @return the template settings.
202 public abstract RunnerAndConfigurationSettings getConfigurationTemplate(ConfigurationFactory factory);
205 * Adds the specified run configuration to the list of run configurations stored in the project.
207 * @param settings the run configuration settings.
208 * @param isShared true if the configuration is marked as shared (stored in the versioned part of the project files), false if it's local
209 * (stored in the workspace file).
211 public abstract void addConfiguration(final RunnerAndConfigurationSettings settings, final boolean isShared);
214 * Marks the specified run configuration as recently used (the temporary run configurations are deleted in LRU order).
216 * @param profile the run configuration to mark as recently used.
218 public abstract void refreshUsagesList(RunProfile profile);
221 public static String suggestUniqueName(@NotNull String str, @NotNull Collection<String> currentNames) {
222 if (!currentNames.contains(str)) return str;
224 final Matcher matcher = Pattern.compile("(.*?)\\s*\\(\\d+\\)").matcher(str);
225 final String originalName = (matcher.matches()) ? matcher.group(1) : str;
228 final String newName = String.format("%s (%d)", originalName, i);
229 if (!currentNames.contains(newName)) return newName;