mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract BeforeRunTaskHelper to simplify RunManagerImpl
This commit is contained in:
@@ -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<BeforeRunTask<*>>, templateTasks: List<BeforeRunTask<*>>, ownIsOnlyEnabled: Boolean, isDisableTemplateTasks: Boolean): MutableList<BeforeRunTask<*>> {
|
||||
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<BeforeRunTask<*>> {
|
||||
return templateConfiguration.beforeRunTasks.nullize() ?: getHardcodedBeforeRunTasks(templateConfiguration)
|
||||
}
|
||||
|
||||
internal fun getHardcodedBeforeRunTasks(configuration: RunConfiguration): List<BeforeRunTask<*>> {
|
||||
var result: MutableList<BeforeRunTask<*>>? = 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<BeforeRunTask<*>>()
|
||||
}
|
||||
result.add(task)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.orEmpty()
|
||||
}
|
||||
@@ -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<BeforeRunTask<*>>,
|
||||
templateTasks: List<BeforeRunTask<*>>,
|
||||
ownIsOnlyEnabled: Boolean,
|
||||
isDisableTemplateTasks: Boolean): MutableList<BeforeRunTask<*>> {
|
||||
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<BeforeRunTask<*>> {
|
||||
return templateConfiguration.beforeRunTasks.nullize() ?: getHardcodedBeforeRunTasks(templateConfiguration)
|
||||
}
|
||||
|
||||
private fun getHardcodedBeforeRunTasks(configuration: RunConfiguration): List<BeforeRunTask<*>> {
|
||||
var result: MutableList<BeforeRunTask<*>>? = 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<BeforeRunTask<*>>()
|
||||
}
|
||||
result.add(task)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.orEmpty()
|
||||
}
|
||||
|
||||
fun shareConfiguration(settings: RunnerAndConfigurationSettings, value: Boolean) {
|
||||
if (settings.isShared == value) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user