From 16e4280e1876ee1ee8a383628a289b4bcdf60821 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 7 Apr 2017 21:03:57 +0200 Subject: [PATCH] simplify implementations, getConfiguration returns UnknownConfiguration if null (actually, it is already so) (cherry picked from commit bcf2738f96752062442b14eabd933d11425d5d35) --- .../src/com/intellij/execution/RunManager.kt | 66 +---- .../RunnerAndConfigurationSettings.java | 4 +- .../UnknownConfigurationType.java | 28 +- .../execution/impl/RunConfigurable.java | 10 +- .../intellij/execution/impl/RunManagerImpl.kt | 246 ++++++++---------- .../RunnerAndConfigurationSettingsImpl.kt | 4 +- .../intellij/execution/impl/TimedIconCache.kt | 2 +- .../src/com/intellij/mock/MockRunManager.kt | 51 ++-- ...AbstractPythonTestConfigurationProducer.kt | 27 +- 9 files changed, 166 insertions(+), 272 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/RunManager.kt b/platform/lang-api/src/com/intellij/execution/RunManager.kt index 6dc80c3b74ee..bd7930ec4fde 100644 --- a/platform/lang-api/src/com/intellij/execution/RunManager.kt +++ b/platform/lang-api/src/com/intellij/execution/RunManager.kt @@ -20,7 +20,6 @@ import com.intellij.execution.configurations.ConfigurationType import com.intellij.execution.configurations.RunConfiguration import com.intellij.execution.configurations.RunProfile import com.intellij.openapi.project.Project -import com.intellij.openapi.util.Comparing import com.intellij.openapi.util.text.StringUtil import com.intellij.util.containers.ContainerUtil import java.util.regex.Pattern @@ -56,83 +55,65 @@ abstract class RunManager { /** * Returns the list of all registered configuration types. - - * @return all registered configuration types. */ abstract val configurationFactories: Array /** * Returns the list of all configurations of a specified type. - * @param type a run configuration type. - * * * @return all configurations of the type, or an empty array if no configurations of the type are defined. */ - @Deprecated("") - abstract fun getConfigurations(type: ConfigurationType): Array + @Deprecated("", ReplaceWith("getConfigurationsList(type)")) + fun getConfigurations(type: ConfigurationType) = getConfigurationsList(type).toTypedArray() /** * Returns the list of all configurations of a specified type. - * @param type a run configuration type. - * * * @return all configurations of the type, or an empty array if no configurations of the type are defined. */ abstract fun getConfigurationsList(type: ConfigurationType): List /** * Returns the list of [RunnerAndConfigurationSettings] for all configurations of a specified type. - * @param type a run configuration type. - * * * @return settings for all configurations of the type, or an empty array if no configurations of the type are defined. */ @Deprecated("") - abstract fun getConfigurationSettings(type: ConfigurationType): Array + fun getConfigurationSettings(type: ConfigurationType) = getConfigurationSettingsList(type).toTypedArray() /** * Returns the list of [RunnerAndConfigurationSettings] for all configurations of a specified type. - + * + * Template configuration is not included * @param type a run configuration type. - * * * @return settings for all configurations of the type, or an empty array if no configurations of the type are defined. */ abstract fun getConfigurationSettingsList(type: ConfigurationType): List /** * Returns the list of all run configurations. - - * @return the list of all run configurations. */ - @get:Deprecated("") - abstract val allConfigurations: Array + @Deprecated("", ReplaceWith("allConfigurationsList")) + fun getAllConfigurations() = allConfigurationsList.toTypedArray() /** * Returns the list of all run configurations. - - * @return the list of all run configurations. */ abstract val allConfigurationsList: List /** * Returns the list of all run configurations settings. - - * @return the list of all run configurations settings. */ abstract val allSettings: List /** * Returns the list of all temporary run configurations settings. - - * @return the list of all temporary run configurations settings. - * * * @see RunnerAndConfigurationSettings.isTemporary */ abstract val tempConfigurationsList: List /** * Saves the specified temporary run configuration and makes it a permanent one. - * @param configuration the temporary run configuration to save. */ @Deprecated("") @@ -140,67 +121,43 @@ abstract class RunManager { /** * Saves the specified temporary run settings and makes it a permanent one. - * @param settings the temporary settings to save. */ abstract fun makeStable(settings: RunnerAndConfigurationSettings) /** - * Returns the selected item in the run/debug configurations combobox. - - * @return the selected configuration, or null if no configuration is defined or selected. - */ - /** - * Selects a configuration in the run/debug configurations combobox. - - * @param configuration the configuration to select, or null if nothing should be selected. + * The selected item in the run/debug configurations combobox. */ abstract var selectedConfiguration: RunnerAndConfigurationSettings? /** * Creates a configuration of the specified type with the specified name. Note that you need to call * [.addConfiguration] if you want the configuration to be persisted in the project. - * @param name the name of the configuration to create (should be unique and not equal to any other existing configuration) - * * * @param factory the factory instance. - * * - * @return the configuration settings object. - * * * @see RunManager.suggestUniqueName */ abstract fun createConfiguration(name: String, factory: ConfigurationFactory): RunnerAndConfigurationSettings - fun createRunConfiguration(name: String, factory: ConfigurationFactory): RunnerAndConfigurationSettings { - return createConfiguration(name, factory) - } + fun createRunConfiguration(name: String, factory: ConfigurationFactory) = createConfiguration(name, factory) /** * Creates a configuration settings object based on a specified [RunConfiguration]. Note that you need to call * [.addConfiguration] if you want the configuration to be persisted in the project. - * @param runConfiguration the run configuration - * * * @param factory the factory instance. - * * - * @return the configuration settings object. */ abstract fun createConfiguration(runConfiguration: RunConfiguration, factory: ConfigurationFactory): RunnerAndConfigurationSettings /** * Returns the template settings for the specified configuration type. - * @param factory the configuration factory. - * * - * @return the template settings. */ abstract fun getConfigurationTemplate(factory: ConfigurationFactory): RunnerAndConfigurationSettings /** * Adds the specified run configuration to the list of run configurations stored in the project. - * @param settings the run configuration settings. - * * * @param isShared true if the configuration is marked as shared (stored in the versioned part of the project files), false if it's local * * (stored in the workspace file). */ @@ -208,7 +165,6 @@ abstract class RunManager { /** * Marks the specified run configuration as recently used (the temporary run configurations are deleted in LRU order). - * @param profile the run configuration to mark as recently used. */ abstract fun refreshUsagesList(profile: RunProfile) @@ -228,7 +184,7 @@ abstract class RunManager { fun setUniqueNameIfNeed(settings: RunnerAndConfigurationSettings): Boolean { val oldName = settings.name settings.name = suggestUniqueName(StringUtil.notNullize(oldName, UNNAMED), settings.type) - return !Comparing.equal(oldName, settings.name) + return oldName != settings.name } /** @@ -238,6 +194,6 @@ abstract class RunManager { fun setUniqueNameIfNeed(configuration: RunConfiguration): Boolean { val oldName = configuration.name configuration.name = suggestUniqueName(StringUtil.notNullize(oldName, UNNAMED), configuration.type) - return !Comparing.equal(oldName, configuration.name) + return oldName != configuration.name } } diff --git a/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java b/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java index 0a3918b85ae6..bc4b81503488 100644 --- a/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java +++ b/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java @@ -71,10 +71,8 @@ public interface RunnerAndConfigurationSettings { /** * Returns the {@link RunConfiguration} instance that will be used to execute this run configuration. - * - * @return the run configuration, or null if the settings object was loaded from disk and no plugin corresponding to the stored type - * of the run configuration is loaded. */ + @NotNull RunConfiguration getConfiguration(); /** diff --git a/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java b/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java index 77507362b63f..a580a1508557 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.execution.configurations; import com.intellij.icons.AllIcons; @@ -26,11 +25,22 @@ import javax.swing.*; * @author spleaner */ public class UnknownConfigurationType implements ConfigurationType { - public static final UnknownConfigurationType INSTANCE = new UnknownConfigurationType(); public static final String NAME = "Unknown"; + public static final ConfigurationFactory FACTORY = new ConfigurationFactory(new UnknownConfigurationType()) { + @Override + public RunConfiguration createTemplateConfiguration(@NotNull Project project) { + return new UnknownRunConfiguration(this, project); + } + + @Override + public boolean canConfigurationBeSingleton() { + return false; + } + }; + @Override public String getDisplayName() { return getId(); @@ -54,16 +64,6 @@ public class UnknownConfigurationType implements ConfigurationType { @Override public ConfigurationFactory[] getConfigurationFactories() { - return new ConfigurationFactory[] {new ConfigurationFactory(new UnknownConfigurationType()) { - @Override - public RunConfiguration createTemplateConfiguration(final Project project) { - return new UnknownRunConfiguration(this, project); - } - - @Override - public boolean canConfigurationBeSingleton() { - return false; - } - }}; + return new ConfigurationFactory[] {FACTORY}; } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java index 4052387806a1..bd3e9ef9de13 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java @@ -1126,10 +1126,10 @@ class RunConfigurable extends BaseConfigurable { } private void showAddPopup(final boolean showApplicableTypesOnly) { - ConfigurationType[] allTypes = getRunManager().getConfigurationFactories(false); + List allTypes = getRunManager().getConfigurationFactoriesWithoutUnknown(); final List configurationTypes = getTypesToShow(showApplicableTypesOnly, allTypes); Collections.sort(configurationTypes, (type1, type2) -> type1.getDisplayName().compareToIgnoreCase(type2.getDisplayName())); - final int hiddenCount = allTypes.length - configurationTypes.size(); + final int hiddenCount = allTypes.size() - configurationTypes.size(); if (hiddenCount > 0) { configurationTypes.add(null); } @@ -1140,7 +1140,7 @@ class RunConfigurable extends BaseConfigurable { popup.showUnderneathOf(myToolbarDecorator.getActionsPanel()); } - private List getTypesToShow(boolean showApplicableTypesOnly, ConfigurationType[] allTypes) { + private List getTypesToShow(boolean showApplicableTypesOnly, @NotNull List allTypes) { if (showApplicableTypesOnly) { List applicableTypes = new ArrayList<>(); for (ConfigurationType type : allTypes) { @@ -1148,11 +1148,11 @@ class RunConfigurable extends BaseConfigurable { applicableTypes.add(type); } } - if (applicableTypes.size() < allTypes.length - 3) { + if (applicableTypes.size() < allTypes.size() - 3) { return applicableTypes; } } - return new ArrayList<>(Arrays.asList(allTypes)); + return allTypes; } private boolean isApplicable(ConfigurationType type) { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt index 75c1553c8019..b15174645fb6 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -54,7 +54,6 @@ import java.util.function.Function import javax.swing.Icon import kotlin.concurrent.read import kotlin.concurrent.write -import kotlin.properties.Delegates private val LOG = logger() private val SELECTED_ATTR = "selected" @@ -100,21 +99,21 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent private val idToType = LinkedHashMap() private val templateIdToConfiguration = THashMap() - private val idToSettings = LinkedHashMap() // template configurations are not included here + // template configurations are not included here + private val idToSettings = LinkedHashMap() private val sharedConfigurations: MutableMap = ConcurrentHashMap() // When readExternal not all configuration may be loaded, so we need to remember the selected configuration // so that when it is eventually loaded, we can mark is as a selected. - private var myLoadedSelectedConfigurationUniqueName: String? = null - private var mySelectedConfigurationId: String? = null + private var loadedSelectedConfigurationUniqueName: String? = null + private var selectedConfigurationId: String? = null private val iconCache = TimedIconCache() - private var types: Array by Delegates.notNull() private val _config by lazy { RunManagerConfig(PropertiesComponent.getInstance(project)) } @Suppress("DEPRECATION") private val myOrder = JDOMExternalizableStringList() - private val myRecentlyUsedTemporaries = ArrayList() + private val recentlyUsedTemporaries = ArrayList() private var myOrdered = true private val myDispatcher = EventDispatcher.create(RunManagerListener::class.java)!! @@ -196,14 +195,10 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent override fun getConfig() = _config - override fun getConfigurationFactories() = idToType.values.toTypedArray() + override val configurationFactories by lazy { idToType.values.toTypedArray() } - fun getConfigurationFactories(includeUnknown: Boolean): Array { - if (!includeUnknown) { - return idToType.values.filter { it !is UnknownConfigurationType }.toTypedArray() - } - return idToType.values.toTypedArray() - } + val configurationFactoriesWithoutUnknown: List + get() = idToType.values.filterSmart { it !is UnknownConfigurationType } /** * Template configuration is not included @@ -219,40 +214,18 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent result.add(configuration) } } - return ContainerUtil.notNullize(result) + return result ?: emptyList() } - override fun getAllConfigurationsList(): List { - val sortedConfigurations = sortedConfigurations - return if (sortedConfigurations.isEmpty()) emptyList() else sortedConfigurations.mapSmart { it.configuration } - } + override val allConfigurationsList: List + get() = sortedConfigurations.mapSmart { it.configuration } - @Suppress("OverridingDeprecatedMember") - override fun getAllConfigurations() = allConfigurationsList.toTypedArray() - - override fun getAllSettings() = sortedConfigurations.toList() + override val allSettings: List + get() = sortedConfigurations.toList() fun getSettings(configuration: RunConfiguration) = sortedConfigurations.firstOrNull { it.configuration === configuration } as? RunnerAndConfigurationSettingsImpl - /** - * Template configuration is not included - */ - override fun getConfigurationSettingsList(type: ConfigurationType): List { - val result = SmartList() - for (configuration in sortedConfigurations) { - val configurationType = configuration.type - if (configurationType != null && type.id == configurationType.id) { - result.add(configuration) - } - } - return result - } - - @Suppress("OverridingDeprecatedMember") - override fun getConfigurationSettings(type: ConfigurationType) = getConfigurationSettingsList(type).toTypedArray() - - @Suppress("OverridingDeprecatedMember") - override fun getConfigurations(type: ConfigurationType) = getConfigurationSettingsList(type).map { it.configuration }.toTypedArray() + override fun getConfigurationSettingsList(type: ConfigurationType) = sortedConfigurations.filterSmart { it.type?.id == type.id } fun getConfigurationSettings() = idToSettings.values.toTypedArray() @@ -300,7 +273,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent sharedConfigurations.remove(existingId) } - if (mySelectedConfigurationId != null && mySelectedConfigurationId == existingId) { + if (selectedConfigurationId != null && selectedConfigurationId == existingId) { setSelectedConfigurationId(newId) } idToSettings.put(newId, settings) @@ -340,15 +313,15 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent if (profile !is RunConfiguration) return val settings = getSettings(profile) if (settings != null && settings.isTemporary) { - myRecentlyUsedTemporaries.remove(profile) - myRecentlyUsedTemporaries.add(0, profile) + recentlyUsedTemporaries.remove(profile) + recentlyUsedTemporaries.add(0, profile) trimUsagesListToLimit() } } private fun trimUsagesListToLimit() { - while (myRecentlyUsedTemporaries.size > config.recentsLimit) { - myRecentlyUsedTemporaries.removeAt(myRecentlyUsedTemporaries.size - 1) + while (recentlyUsedTemporaries.size > config.recentsLimit) { + recentlyUsedTemporaries.removeAt(recentlyUsedTemporaries.size - 1) } } @@ -359,7 +332,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent val it = idToSettings.values.iterator() while (it.hasNext()) { val configuration = it.next() - if (configuration.isTemporary && !myRecentlyUsedTemporaries.contains(configuration.configuration)) { + if (configuration.isTemporary && !recentlyUsedTemporaries.contains(configuration.configuration)) { removed.add(configuration) it.remove() break @@ -393,22 +366,22 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent setOrdered(false) } - override fun getSelectedConfiguration(): RunnerAndConfigurationSettings? { - if (mySelectedConfigurationId == null && myLoadedSelectedConfigurationUniqueName != null) { - setSelectedConfigurationId(myLoadedSelectedConfigurationUniqueName) + override var selectedConfiguration: RunnerAndConfigurationSettings? + get() { + if (selectedConfigurationId == null && loadedSelectedConfigurationUniqueName != null) { + setSelectedConfigurationId(loadedSelectedConfigurationUniqueName) + } + return selectedConfigurationId?.let { idToSettings.get(it) } + } + set(value) { + setSelectedConfigurationId(value?.uniqueID) + fireRunConfigurationSelected() } - return mySelectedConfigurationId?.let { idToSettings.get(it) } - } - - override fun setSelectedConfiguration(settings: RunnerAndConfigurationSettings?) { - setSelectedConfigurationId(settings?.uniqueID) - fireRunConfigurationSelected() - } private fun setSelectedConfigurationId(id: String?) { - mySelectedConfigurationId = id - if (mySelectedConfigurationId != null) { - myLoadedSelectedConfigurationUniqueName = null + selectedConfigurationId = id + if (selectedConfigurationId != null) { + loadedSelectedConfigurationUniqueName = null } } @@ -516,7 +489,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } val recentList = JDOMExternalizableStringList() - for (each in myRecentlyUsedTemporaries) { + for (each in recentlyUsedTemporaries) { if (each.type is UnknownConfigurationType) { continue } @@ -548,10 +521,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent val configurationElement = Element(CONFIGURATION) parentNode.addContent(configurationElement) (settings as RunnerAndConfigurationSettingsImpl).writeExternal(configurationElement) - - settings.configuration?.let { - writeBeforeRunTasks(it, settings.isTemplate, configurationElement) - } + writeBeforeRunTasks(settings.configuration, settings.isTemplate, configurationElement) } internal fun writeBeforeRunTasks(configuration: RunConfiguration, isTemplate: Boolean, configurationElement: Element) { @@ -598,7 +568,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent // migration (old ids to UUIDs) readList(myOrder) - myRecentlyUsedTemporaries.clear() + recentlyUsedTemporaries.clear() val recentNode = parentNode.getChild(RECENT) if (recentNode != null) { @Suppress("DEPRECATION") @@ -606,16 +576,15 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent list.readExternal(recentNode) readList(list) for (name in list) { - val settings = idToSettings[name] - if (settings != null) { - myRecentlyUsedTemporaries.add(settings.configuration) + idToSettings.get(name)?.configuration?.let { + recentlyUsedTemporaries.add(it) } } } myOrdered = false - myLoadedSelectedConfigurationUniqueName = parentNode.getAttributeValue(SELECTED_ATTR) - setSelectedConfigurationId(myLoadedSelectedConfigurationUniqueName) + loadedSelectedConfigurationUniqueName = parentNode.getAttributeValue(SELECTED_ATTR) + setSelectedConfigurationId(loadedSelectedConfigurationUniqueName) fireBeforeRunTasksUpdated() fireRunConfigurationSelected() @@ -626,7 +595,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent for (settings in idToSettings.values) { val configuration = settings.configuration @Suppress("DEPRECATION") - if (configuration != null && list.get(i) == "${configuration.type.displayName}.${configuration.name}${(configuration as? UnknownRunConfiguration)?.uniqueID ?: ""}") { + if (list.get(i) == "${configuration.type.displayName}.${configuration.name}${(configuration as? UnknownRunConfiguration)?.uniqueID ?: ""}") { list.set(i, settings.uniqueID) break } @@ -635,19 +604,19 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } fun readContext(parentNode: Element) { - myLoadedSelectedConfigurationUniqueName = parentNode.getAttributeValue(SELECTED_ATTR) + loadedSelectedConfigurationUniqueName = parentNode.getAttributeValue(SELECTED_ATTR) for (aChildren in parentNode.children) { val element = aChildren val config = loadConfiguration(element, false) - if (myLoadedSelectedConfigurationUniqueName == null + if (loadedSelectedConfigurationUniqueName == null && config != null && java.lang.Boolean.parseBoolean(element.getAttributeValue(SELECTED_ATTR))) { - myLoadedSelectedConfigurationUniqueName = config.uniqueID + loadedSelectedConfigurationUniqueName = config.uniqueID } } - setSelectedConfigurationId(myLoadedSelectedConfigurationUniqueName) + setSelectedConfigurationId(loadedSelectedConfigurationUniqueName) fireRunConfigurationSelected() } @@ -675,7 +644,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent if (allConfigurations) { this.idToSettings.clear() sharedConfigurations.clear() - mySelectedConfigurationId = null + selectedConfigurationId = null configurations = ArrayList(this.idToSettings.values) } else { @@ -691,17 +660,17 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } } - if (mySelectedConfigurationId != null && this.idToSettings.containsKey(mySelectedConfigurationId!!)) { - mySelectedConfigurationId = null + if (selectedConfigurationId != null && this.idToSettings.containsKey(selectedConfigurationId!!)) { + selectedConfigurationId = null } } lock.write { templateIdToConfiguration.clear() } - myLoadedSelectedConfigurationUniqueName = null + loadedSelectedConfigurationUniqueName = null iconCache.clear() - myRecentlyUsedTemporaries.clear() + recentlyUsedTemporaries.clear() fireRunConfigurationsRemoved(configurations) } @@ -718,7 +687,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent private fun doLoadConfiguration(element: Element, isShared: Boolean, settings: RunnerAndConfigurationSettingsImpl, factory: ConfigurationFactory) { val tasks = element.getChild(METHOD)?.let { readStepsBeforeRun(it, settings) } ?: emptyList() - settings.configuration?.beforeRunTasks = tasks + settings.configuration.beforeRunTasks = tasks if (settings.isTemplate) { lock.write { templateIdToConfiguration.put("${factory.type.id}.${factory.name}", settings) @@ -799,11 +768,12 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent internal val configurationSettings: Collection get() = idToSettings.values - override fun getTempConfigurationsList() = idToSettings.values.filter { it.isTemporary } + override val tempConfigurationsList: List + get() = idToSettings.values.filter { it.isTemporary } override fun makeStable(settings: RunnerAndConfigurationSettings) { settings.isTemporary = false - myRecentlyUsedTemporaries.remove(settings.configuration) + recentlyUsedTemporaries.remove(settings.configuration) if (!myOrder.isEmpty()) { setOrdered(false) } @@ -825,22 +795,25 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } override fun > getBeforeRunTasks(taskProviderId: Key): List { - val tasks = ArrayList() - val checkedTemplates = ArrayList() - for (settings in idToSettings.values.toTypedArray()) { - for (task in getBeforeRunTasks(settings.configuration)) { - if (task.isEnabled && task.providerId === taskProviderId) { - @Suppress("UNCHECKED_CAST") - tasks.add(task as T) - } - else { - val template = getConfigurationTemplate(settings.factory!!) - if (!checkedTemplates.contains(template)) { - checkedTemplates.add(template) - for (templateTask in getBeforeRunTasks(template.configuration!!)) { - if (templateTask.isEnabled && templateTask.providerId === taskProviderId) { - @Suppress("UNCHECKED_CAST") - tasks.add(templateTask as T) + val tasks = SmartList() + val checkedTemplates = SmartList() + lock.read { + for (settings in idToSettings.values.toTypedArray()) { + val configuration = settings.configuration + for (task in getBeforeRunTasks(configuration)) { + if (task.isEnabled && task.providerId === taskProviderId) { + @Suppress("UNCHECKED_CAST") + tasks.add(task as T) + } + else { + val template = getConfigurationTemplate(configuration.factory) + if (!checkedTemplates.contains(template)) { + checkedTemplates.add(template) + for (templateTask in getBeforeRunTasks(template.configuration)) { + if (templateTask.isEnabled && templateTask.providerId === taskProviderId) { + @Suppress("UNCHECKED_CAST") + tasks.add(templateTask as T) + } } } } @@ -919,7 +892,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent val template = getConfigurationTemplate(configuration.factory) val templateConfiguration = template.configuration - if (templateConfiguration == null || templateConfiguration is UnknownRunConfiguration) { + if (templateConfiguration is UnknownRunConfiguration) { return emptyList() } @@ -1005,7 +978,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } else { val templateConfiguration = getConfigurationTemplate(configuration.factory).configuration - val templateTasks = if (templateConfiguration == null || templateConfiguration === configuration) { + val templateTasks = if (templateConfiguration === configuration) { getHardcodedBeforeRunTasks(configuration) } else { @@ -1017,7 +990,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent // see testTemplates test lock.read { for (otherSettings in idToSettings.values) { - val otherConfiguration = otherSettings.configuration ?: continue + val otherConfiguration = otherSettings.configuration if (otherConfiguration !is WrappingRunConfiguration<*> && otherConfiguration.factory === templateConfiguration.factory) { otherConfiguration.beforeRunTasks = getEffectiveBeforeRunTasks(otherConfiguration, isDisableTemplateTasks = true, newTemplateTasks = tasks) } @@ -1068,7 +1041,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent private fun fireRunConfigurationsRemoved(removed: List?) { if (removed != null && !removed.isEmpty()) { - myRecentlyUsedTemporaries.removeAll(removed.map { it.configuration }) + recentlyUsedTemporaries.removeAll(removed.map { it.configuration }) for (settings in removed) { myDispatcher.multicaster.runConfigurationRemoved(settings) } @@ -1101,18 +1074,18 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent return myBeforeStepsMap!!.get(providerId)!! } - @Synchronized private fun getProviderKey(keyString: String): Key> { + @Synchronized + private fun getProviderKey(keyString: String): Key> { if (myProviderKeysMap == null) { initProviderMaps() } - var id: Key>? = myProviderKeysMap!![keyString] - if (id == null) { + + return myProviderKeysMap!!.getOrPut(keyString) { val provider = UnknownBeforeRunTaskProvider(keyString) - id = provider.id!! - myProviderKeysMap!!.put(keyString, id) + val id = provider.id!! myBeforeStepsMap!!.put(id, provider) + id } - return id } private fun initProviderMaps() { @@ -1130,38 +1103,43 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent return } - val it = sortedConfigurations.iterator() - for (otherSettings in it) { - if (otherSettings === settings) { - if (mySelectedConfigurationId != null && mySelectedConfigurationId === settings.uniqueID) { - selectedConfiguration = null + val changedSettings = SmartList() + lock.write { + val iterator = idToSettings.values.iterator() + for (otherSettings in iterator) { + if (otherSettings === settings) { + if (selectedConfigurationId === settings.uniqueID) { + selectedConfiguration = null + } + + iterator.remove() + sharedConfigurations.remove(settings.uniqueID) + recentlyUsedTemporaries.remove(settings.configuration) + myDispatcher.multicaster.runConfigurationRemoved(otherSettings) } - it.remove() - sharedConfigurations.remove(settings.uniqueID) - myRecentlyUsedTemporaries.remove(settings.configuration) - myDispatcher.multicaster.runConfigurationRemoved(otherSettings) - } - - var changed = false - val otherConfiguration = otherSettings.configuration ?: continue - val newList = otherConfiguration.beforeRunTasks.nullize()?.toMutableSmartList() ?: continue - val beforeRunTaskIterator = newList.iterator() - for (task in beforeRunTaskIterator) { - if (task is RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask && task.settings === settings) { - beforeRunTaskIterator.remove() - changed = true - myDispatcher.multicaster.runConfigurationChanged(otherSettings, null) + var changed = false + val otherConfiguration = otherSettings.configuration + val newList = otherConfiguration.beforeRunTasks.nullize()?.toMutableSmartList() ?: continue + val beforeRunTaskIterator = newList.iterator() + for (task in beforeRunTaskIterator) { + if (task is RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask && task.settings === settings) { + beforeRunTaskIterator.remove() + changed = true + changedSettings.add(otherSettings) + } + } + if (changed) { + otherConfiguration.beforeRunTasks = newList } - } - if (changed) { - otherConfiguration.beforeRunTasks = newList } } + + changedSettings.forEach { myDispatcher.multicaster.runConfigurationChanged(it, null) } } } -interface RunConfigurationScheme : Scheme +internal interface RunConfigurationScheme : Scheme private class UnknownRunConfigurationScheme(private val name: String) : RunConfigurationScheme, SerializableScheme { override fun getSchemeState() = SchemeState.UNCHANGED diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt index 4555bf8afebe..522c5fbd9e1d 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt @@ -69,8 +69,6 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m private var wasSingletonSpecifiedExplicitly = false private var folderName: String? = null - //var beforeRunTasks: List>? = null - override fun getFactory() = configuration?.factory override fun isTemplate() = isTemplate @@ -81,7 +79,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m isTemporary = temporary } - override fun getConfiguration(): RunConfiguration? = configuration + override fun getConfiguration() = configuration ?: UnknownConfigurationType.FACTORY.createTemplateConfiguration(manager.project) override fun createFactory() = Factory { val configuration = configuration!! diff --git a/platform/lang-impl/src/com/intellij/execution/impl/TimedIconCache.kt b/platform/lang-impl/src/com/intellij/execution/impl/TimedIconCache.kt index affe03d34be4..ccab9f442d82 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/TimedIconCache.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/TimedIconCache.kt @@ -45,7 +45,7 @@ class TimedIconCache { } fun get(id: String, settings: RunnerAndConfigurationSettings, project: Project): Icon { - return lock.read { idToIcon.get(id) } ?: IconDeferrer.getInstance().deferAutoUpdatable(settings.configuration.icon, project.hashCode() xor settings.hashCode()) { param -> + return lock.read { idToIcon.get(id) } ?: IconDeferrer.getInstance().deferAutoUpdatable(settings.configuration?.icon, project.hashCode() xor settings.hashCode()) { param -> if (project.isDisposed) { return@deferAutoUpdatable null } diff --git a/platform/testFramework/src/com/intellij/mock/MockRunManager.kt b/platform/testFramework/src/com/intellij/mock/MockRunManager.kt index eaa4d27e4209..bd7078dc516a 100644 --- a/platform/testFramework/src/com/intellij/mock/MockRunManager.kt +++ b/platform/testFramework/src/com/intellij/mock/MockRunManager.kt @@ -27,36 +27,29 @@ import javax.swing.Icon * @author gregsh */ class MockRunManager : RunManagerEx() { - override fun getConfigurationFactories() = emptyArray() - - override fun getConfigurations(type: ConfigurationType) = emptyArray() - override fun getConfigurationsList(type: ConfigurationType) = emptyList() - override fun getAllConfigurations() = emptyArray() - - override fun getAllConfigurationsList(): List { - return emptyList() - } - - val tempConfigurations: Array - get() = emptyArray() - - override fun getTempConfigurationsList(): List { - return emptyList() - } - - fun isTemporary(configuration: RunConfiguration): Boolean { - return false - } + fun isTemporary(configuration: RunConfiguration) = false override fun makeStable(configuration: RunConfiguration) {} override fun makeStable(settings: RunnerAndConfigurationSettings) {} - override fun getSelectedConfiguration(): RunnerAndConfigurationSettings? { - return null - } + override val configurationFactories: Array + get() = emptyArray() + + override val allConfigurationsList: List + get() = emptyList() + + override val allSettings: List + get() = emptyList() + + override val tempConfigurationsList: List + get() = emptyList() + + override var selectedConfiguration: RunnerAndConfigurationSettings? + get() = null + set(value) {} override fun createConfiguration(runConfiguration: RunConfiguration, factory: ConfigurationFactory): RunnerAndConfigurationSettings { throw UnsupportedOperationException() @@ -66,10 +59,6 @@ class MockRunManager : RunManagerEx() { throw UnsupportedOperationException() } - override fun getConfigurationSettings(type: ConfigurationType): Array { - return emptyArray() - } - override fun getConfigurationSettingsList(type: ConfigurationType): List { return emptyList() } @@ -78,19 +67,13 @@ class MockRunManager : RunManagerEx() { return emptyMap() } - override fun getAllSettings(): List { - return emptyList() - } - - override fun setSelectedConfiguration(configuration: RunnerAndConfigurationSettings?) {} - override fun setTemporaryConfiguration(tempConfiguration: RunnerAndConfigurationSettings?) {} override fun getConfig(): RunManagerConfig { throw UnsupportedOperationException() } - override fun createConfiguration(name: String, type: ConfigurationFactory): RunnerAndConfigurationSettings { + override fun createConfiguration(name: String, factory: ConfigurationFactory): RunnerAndConfigurationSettings { throw UnsupportedOperationException() } diff --git a/python/src/com/jetbrains/python/testing/AbstractPythonTestConfigurationProducer.kt b/python/src/com/jetbrains/python/testing/AbstractPythonTestConfigurationProducer.kt index ee14a300fcd4..301fb10d7a18 100644 --- a/python/src/com/jetbrains/python/testing/AbstractPythonTestConfigurationProducer.kt +++ b/python/src/com/jetbrains/python/testing/AbstractPythonTestConfigurationProducer.kt @@ -13,25 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ + + package com.jetbrains.python.testing import com.intellij.execution.RunManager -import com.intellij.execution.RunnerAndConfigurationSettings import com.intellij.execution.actions.ConfigurationContext import com.intellij.execution.actions.ConfigurationFromContext import com.intellij.execution.actions.RunConfigurationProducer @@ -57,16 +43,11 @@ abstract class AbstractPythonTestConfigurationProducer = + override fun getConfigurationSettingsList(runManager: RunManager) = super.getConfigurationSettingsList(runManager).filter { configurationClass.isAssignableFrom(it.configuration.javaClass) } override fun createConfigurationFromContext(context: ConfigurationContext?): ConfigurationFromContext? { - if (context == null) { - return null - } - val configuration = cloneTemplateConfiguration(context).configuration ?: return null - - if (!configurationClass.isAssignableFrom(configuration.javaClass)) { + if (context == null || !configurationClass.isAssignableFrom(cloneTemplateConfiguration(context).configuration.javaClass)) { return null } return super.createConfigurationFromContext(context)