From 19f8f5e206441faae05171aa3266024b266052ea Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 23 Apr 2018 18:06:57 +0200 Subject: [PATCH] ability to have invisible and managed externally run configurations --- .../configurations/ConfigurationType.java | 23 ++++----- .../UnknownConfigurationType.java | 12 +++-- .../impl/RunConfigurationListManagerHelper.kt | 8 +--- .../intellij/execution/impl/RunManagerImpl.kt | 47 +++++++++---------- 4 files changed, 42 insertions(+), 48 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationType.java b/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationType.java index d321c352c1f1..06a5ac47521b 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationType.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationType.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.configurations; import com.intellij.openapi.extensions.ExtensionPointName; @@ -73,4 +59,11 @@ public interface ConfigurationType extends PossiblyDumbAware { * @return the run configuration factories. */ ConfigurationFactory[] getConfigurationFactories(); + + /** + * Is configuration fully managed by RunManager. + */ + default boolean isManaged() { + return true; + } } \ No newline at end of file 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 a3291f37fe17..6c4cfacaa33c 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java @@ -9,14 +9,15 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; -public class UnknownConfigurationType extends ConfigurationTypeBase { +public final class UnknownConfigurationType extends ConfigurationTypeBase { + @NotNull public static final UnknownConfigurationType INSTANCE = new UnknownConfigurationType(); - protected UnknownConfigurationType() { + private UnknownConfigurationType() { this(AllIcons.RunConfigurations.Unknown); } - protected UnknownConfigurationType(@NotNull Icon icon) { + private UnknownConfigurationType(@NotNull Icon icon) { super(NAME, NAME, ExecutionBundle.message("run.configuration.unknown.description"), icon); addFactory(new ConfigurationFactory(this) { @@ -40,4 +41,9 @@ public class UnknownConfigurationType extends ConfigurationTypeBase { public static ConfigurationFactory getFactory() { return INSTANCE.getConfigurationFactories()[0]; } + + @Override + public boolean isManaged() { + return false; + } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationListManagerHelper.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationListManagerHelper.kt index f48558f9ac46..ad4aad764983 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationListManagerHelper.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationListManagerHelper.kt @@ -1,12 +1,9 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.impl import com.intellij.execution.RunnerAndConfigurationSettings import com.intellij.execution.compound.CompoundRunConfiguration import com.intellij.execution.configurations.RunConfiguration -import com.intellij.execution.configurations.UnknownConfigurationType import com.intellij.openapi.util.text.NaturalComparator import com.intellij.util.SmartList import com.intellij.util.containers.ContainerUtil @@ -33,7 +30,7 @@ internal class RunConfigurationListManagerHelper(val manager: RunManagerImpl) { var immutableSortedSettingsList: List? = emptyList() fun setOrder(comparator: Comparator) { - val sorted = idToSettings.values.filterTo(ArrayList(idToSettings.size)) { it.type !is UnknownConfigurationType } + val sorted = idToSettings.values.filterTo(ArrayList(idToSettings.size)) { it.type.isManaged } sorted.sortWith(comparator) customOrder.clear() customOrder.ensureCapacity(sorted.size) @@ -151,7 +148,6 @@ internal class RunConfigurationListManagerHelper(val manager: RunManagerImpl) { fun checkIfDependenciesAreStable(configuration: RunConfiguration, list: List) { for (runTask in configuration.beforeRunTasks) { val runTaskSettings = (runTask as? RunConfigurationBeforeRunProvider.RunConfigurableBeforeRunTask)?.settings - if (runTaskSettings?.isTemporary == true) { manager.makeStable(runTaskSettings) checkIfDependenciesAreStable(runTaskSettings.configuration, list) 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 18cbeb86f07d..3f563955a03b 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -195,7 +195,7 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi override val configurationFactories by lazy { idToType.values.toTypedArray() } override val configurationFactoriesWithoutUnknown: List - get() = idToType.values.filterSmart { it !is UnknownConfigurationType } + get() = idToType.values.filterSmart { it.isManaged } /** * Template configuration is not included @@ -404,10 +404,8 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi if (!isFirstLoadState.get()) { lock.read { val list = idToSettings.values.toList() - for (settings in list) { - if (settings.type !is UnknownConfigurationType) { - listManager.checkIfDependenciesAreStable(settings.configuration, list) - } + list.forEachManaged { + listManager.checkIfDependenciesAreStable(it.configuration, list) } } } @@ -425,12 +423,8 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi } val listElement = Element("list") - for (settings in idToSettings.values) { - if (settings.type is UnknownConfigurationType) { - continue - } - - listElement.addContent(Element("item").setAttribute("itemvalue", settings.uniqueID)) + idToSettings.values.forEachManaged { + listElement.addContent(Element("item").setAttribute("itemvalue", it.uniqueID)) } if (!listElement.isEmpty()) { @@ -439,11 +433,8 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi } val recentList = SmartList() - for (settings in recentlyUsedTemporaries) { - if (settings.type is UnknownConfigurationType) { - continue - } - recentList.add(settings.uniqueID) + recentlyUsedTemporaries.forEachManaged { + recentList.add(it.uniqueID) } if (!recentList.isEmpty()) { val recent = Element(RECENT) @@ -758,21 +749,21 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi override fun getConfigurationType(typeName: String) = idToType.get(typeName) @JvmOverloads - fun getFactory(typeId: String?, _factoryId: String?, checkUnknown: Boolean = false): ConfigurationFactory? { - var type = idToType.get(typeId) + fun getFactory(typeId: String?, factoryId: String?, checkUnknown: Boolean = false): ConfigurationFactory? { + val type = idToType.get(typeId) if (type == null) { if (checkUnknown && typeId != null) { - UnknownFeaturesCollector.getInstance(project).registerUnknownRunConfiguration(typeId, _factoryId) + UnknownFeaturesCollector.getInstance(project).registerUnknownRunConfiguration(typeId, factoryId) } - type = idToType.get(UnknownConfigurationType.NAME) ?: return null + return UnknownConfigurationType.getFactory() } - if (type is UnknownConfigurationType || _factoryId == null) { - return type.configurationFactories.get(0) + if (type is UnknownConfigurationType) { + return type.configurationFactories.firstOrNull() } return type.configurationFactories.firstOrNull { - it.id == _factoryId + factoryId == null || it.id == factoryId } } @@ -1013,4 +1004,12 @@ internal class IprRunManagerImpl(private val project: Project) : PersistentState } } -private fun getNameWeight(n1: String) = if (n1.startsWith("