diff --git a/platform/lang-impl/src/com/intellij/execution/impl/BeforeRunTaskHelper.kt b/platform/lang-impl/src/com/intellij/execution/impl/BeforeRunTaskHelper.kt new file mode 100644 index 000000000000..17f78276a068 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/execution/impl/BeforeRunTaskHelper.kt @@ -0,0 +1,53 @@ +// Copyright 2000-2017 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.BeforeRunTask +import com.intellij.execution.BeforeRunTaskProvider +import com.intellij.execution.configurations.RunConfiguration +import com.intellij.openapi.extensions.Extensions +import com.intellij.util.SmartList +import com.intellij.util.containers.filterSmartMutable +import com.intellij.util.containers.mapSmartSet +import com.intellij.util.containers.nullize + +internal fun getEffectiveBeforeRunTaskList(ownTasks: List>, templateTasks: List>, ownIsOnlyEnabled: Boolean, isDisableTemplateTasks: Boolean): MutableList> { + val idToSet = ownTasks.mapSmartSet { it.providerId } + val result = ownTasks.filterSmartMutable { !ownIsOnlyEnabled || it.isEnabled } + var i = 0 + for (templateTask in templateTasks) { + if (templateTask.isEnabled && !idToSet.contains(templateTask.providerId)) { + val effectiveTemplateTask = if (isDisableTemplateTasks) { + val clone = templateTask.clone() + clone.isEnabled = false + clone + } + else { + templateTask + } + result.add(i, effectiveTemplateTask) + i++ + } + } + return result +} + +internal fun getTemplateBeforeRunTasks(templateConfiguration: RunConfiguration): List> { + return templateConfiguration.beforeRunTasks.nullize() ?: getHardcodedBeforeRunTasks(templateConfiguration) +} + +internal fun getHardcodedBeforeRunTasks(configuration: RunConfiguration): List> { + var result: MutableList>? = null + for (provider in Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, configuration.project)) { + val task = provider.createTask(configuration) ?: continue + if (task.isEnabled) { + configuration.factory.configureBeforeRunTaskDefaults(provider.id, task) + if (task.isEnabled) { + if (result == null) { + result = SmartList>() + } + result.add(task) + } + } + } + return result.orEmpty() +} \ No newline at end of file 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 5dcdd6dd5f82..5cccd76eaf5d 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -15,7 +15,6 @@ import com.intellij.openapi.components.Storage import com.intellij.openapi.components.StoragePathMacros import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.diagnostic.runAndLogException -import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.options.SchemeManager import com.intellij.openapi.options.SchemeManagerFactory import com.intellij.openapi.project.IndexNotReadyException @@ -706,7 +705,7 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi for (methodElement in child.getChildren(OPTION)) { val key = methodElement.getAttributeValue(NAME_ATTR) val provider = stringIdToBeforeRunProvider.getOrPut(key) { UnknownBeforeRunTaskProvider(key) } - val beforeRunTask = (if (provider is RunConfigurationBeforeRunProvider) provider.createTask(settings.configuration, this) else provider.createTask(settings.configuration)) ?: continue + val beforeRunTask = provider.createTask(settings.configuration) ?: continue if (beforeRunTask is PersistentStateComponent<*>) { // for PersistentStateComponent we don't write default value for enabled, so, set it to true explicitly beforeRunTask.isEnabled = true @@ -877,51 +876,6 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi return getEffectiveBeforeRunTaskList(ownTasks, templateTasks, ownIsOnlyEnabled, isDisableTemplateTasks = isDisableTemplateTasks) } - private fun getEffectiveBeforeRunTaskList(ownTasks: List>, - templateTasks: List>, - ownIsOnlyEnabled: Boolean, - isDisableTemplateTasks: Boolean): MutableList> { - val idToSet = ownTasks.mapSmartSet { it.providerId } - val result = ownTasks.filterSmartMutable { !ownIsOnlyEnabled || it.isEnabled } - var i = 0 - for (templateTask in templateTasks) { - if (templateTask.isEnabled && !idToSet.contains(templateTask.providerId)) { - val effectiveTemplateTask = if (isDisableTemplateTasks) { - val clone = templateTask.clone() - clone.isEnabled = false - clone - } - else { - templateTask - } - result.add(i, effectiveTemplateTask) - i++ - } - } - return result - } - - private fun getTemplateBeforeRunTasks(templateConfiguration: RunConfiguration): List> { - return templateConfiguration.beforeRunTasks.nullize() ?: getHardcodedBeforeRunTasks(templateConfiguration) - } - - private fun getHardcodedBeforeRunTasks(configuration: RunConfiguration): List> { - var result: MutableList>? = null - for (provider in Extensions.getExtensions(BeforeRunTaskProvider.EXTENSION_POINT_NAME, project)) { - val task = provider.createTask(configuration) ?: continue - if (task.isEnabled) { - configuration.factory.configureBeforeRunTaskDefaults(provider.id, task) - if (task.isEnabled) { - if (result == null) { - result = SmartList>() - } - result.add(task) - } - } - } - return result.orEmpty() - } - fun shareConfiguration(settings: RunnerAndConfigurationSettings, value: Boolean) { if (settings.isShared == value) { return