From 0286eee84336ff0785a11b7bedba670e945a4223 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sat, 12 Sep 2015 11:50:41 +0200 Subject: [PATCH] =?UTF-8?q?project=20store=20=E2=80=94=20we=20don't=20load?= =?UTF-8?q?=20default=20state=20in=20tests=20as=20app=20store=20does=20bec?= =?UTF-8?q?ause=201)=20we=20should=20not=20do=20it=20=202)=20it=20was=20so?= =?UTF-8?q?=20before,=20so,=20we=20preserve=20old=20behavior=20(otherwise?= =?UTF-8?q?=20RunManager=20will=20load=20template=20run=20configurations)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intellij/execution/ConfigurationsTest.java | 17 ++++++++++++++++- .../src/ApplicationStoreImpl.kt | 5 +++-- .../src/ComponentStoreImpl.kt | 16 ++++++++++++---- .../src/DefaultProjectStoreImpl.kt | 5 +++-- .../src/ModuleStoreImpl.kt | 9 ++++----- .../src/ProjectStoreImpl.kt | 14 ++++++++------ 6 files changed, 46 insertions(+), 20 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/execution/ConfigurationsTest.java b/java/java-tests/testSrc/com/intellij/execution/ConfigurationsTest.java index 1aecb65638f9..39d4f6380f0f 100644 --- a/java/java-tests/testSrc/com/intellij/execution/ConfigurationsTest.java +++ b/java/java-tests/testSrc/com/intellij/execution/ConfigurationsTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2015 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.intellij.execution; import com.intellij.execution.application.ApplicationConfigurable; @@ -135,7 +150,7 @@ public class ConfigurationsTest extends BaseConfigurationTestCase { PsiClass testA = findTestA(getModule1()); JUnitConfiguration configuration = createConfiguration(testA); JavaParameters parameters = checkCanRun(configuration); - CHECK.empty(parameters.getVMParametersList().getList()); + assertEmpty(parameters.getVMParametersList().getList()); final SegmentedOutputStream notifications = new SegmentedOutputStream(System.out); assertTrue(JUnitStarter.checkVersion(parameters.getProgramParametersList().getArray(), new PrintStream(notifications))); diff --git a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt index 1b3a19d0dda8..e3f7c89d51a1 100644 --- a/platform/configuration-store-impl/src/ApplicationStoreImpl.kt +++ b/platform/configuration-store-impl/src/ApplicationStoreImpl.kt @@ -37,8 +37,9 @@ class ApplicationPathMacroManager : BasePathMacroManager(null) class ApplicationStoreImpl(private val application: Application, pathMacroManager: PathMacroManager) : ComponentStoreImpl() { override val storageManager = ApplicationStorageManager(application, pathMacroManager) - override val isLoadComponentState: Boolean - get() = !application.isUnitTestMode() + // number of app components require some state, so, we load default state in test mode + override val loadPolicy: StateLoadPolicy + get() = if (application.isUnitTestMode()) StateLoadPolicy.LOAD_ONLY_DEFAULT else StateLoadPolicy.LOAD override fun setPath(path: String) { storageManager.addMacro(ROOT_CONFIG, path) diff --git a/platform/configuration-store-impl/src/ComponentStoreImpl.kt b/platform/configuration-store-impl/src/ComponentStoreImpl.kt index 0184580eb18c..1ed883a1dd28 100644 --- a/platform/configuration-store-impl/src/ComponentStoreImpl.kt +++ b/platform/configuration-store-impl/src/ComponentStoreImpl.kt @@ -61,8 +61,8 @@ abstract class ComponentStoreImpl : IComponentStore { protected open val project: Project? get() = null - open val isLoadComponentState: Boolean - get() = true + open val loadPolicy: StateLoadPolicy + get() = StateLoadPolicy.LOAD abstract val storageManager: StateStorageManager @@ -199,7 +199,7 @@ abstract class ComponentStoreImpl : IComponentStore { val componentName = ComponentManagerImpl.getComponentName(component) doAddComponent(componentName, component) - if (!isLoadComponentState) { + if (loadPolicy != StateLoadPolicy.LOAD) { return null } @@ -230,6 +230,10 @@ abstract class ComponentStoreImpl : IComponentStore { } private fun initPersistentComponent(stateSpec: State, component: PersistentStateComponent, changedStorages: Set?, reloadData: Boolean): String? { + if (loadPolicy == StateLoadPolicy.NOT_LOAD) { + return null + } + val name = stateSpec.name val stateClass = ComponentSerializationUtil.getStateClass(component.javaClass) if (!stateSpec.defaultStateAsResource && LOG.isDebugEnabled() && getDefaultState(component, name, stateClass) != null) { @@ -237,7 +241,7 @@ abstract class ComponentStoreImpl : IComponentStore { } val defaultState = if (stateSpec.defaultStateAsResource) getDefaultState(component, name, stateClass) else null - if (isLoadComponentState) { + if (loadPolicy == StateLoadPolicy.LOAD) { val storageSpecs = getStorageSpecs(component, stateSpec, StateStorageOperation.READ) val storageChooser = component as? StateStorageChooserEx for (storageSpec in storageSpecs) { @@ -456,4 +460,8 @@ abstract class ComponentStoreImpl : IComponentStore { return errors } } +} + +enum class StateLoadPolicy { + LOAD, LOAD_ONLY_DEFAULT, NOT_LOAD } \ No newline at end of file diff --git a/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt b/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt index f8cb55a1103c..11f74ad2a33f 100644 --- a/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/DefaultProjectStoreImpl.kt @@ -30,8 +30,9 @@ class DefaultProjectStoreImpl(override val project: ProjectImpl, private val pat val FILE_SPEC = "${StoragePathMacros.APP_CONFIG}/project.default.xml" } - override val isLoadComponentState: Boolean - get() = !ApplicationManager.getApplication().isUnitTestMode() + // see note about default state in project store + override val loadPolicy: StateLoadPolicy + get() = if (ApplicationManager.getApplication().isUnitTestMode()) StateLoadPolicy.NOT_LOAD else StateLoadPolicy.LOAD init { service().project = project diff --git a/platform/configuration-store-impl/src/ModuleStoreImpl.kt b/platform/configuration-store-impl/src/ModuleStoreImpl.kt index 6d7ac4bc1f55..6d3258086673 100644 --- a/platform/configuration-store-impl/src/ModuleStoreImpl.kt +++ b/platform/configuration-store-impl/src/ModuleStoreImpl.kt @@ -19,7 +19,6 @@ import com.intellij.openapi.components.PathMacroManager import com.intellij.openapi.components.StoragePathMacros import com.intellij.openapi.components.stateStore import com.intellij.openapi.module.Module -import com.intellij.util.ThreeState import java.io.File open private class ModuleStoreImpl(module: Module, private val pathMacroManager: PathMacroManager) : ComponentStoreImpl() { @@ -37,16 +36,16 @@ open private class ModuleStoreImpl(module: Module, private val pathMacroManager: } private class TestModuleStore(module: Module, pathMacroManager: PathMacroManager) : ModuleStoreImpl(module, pathMacroManager) { - private var isLoadModuleComponentState = ThreeState.UNSURE + private var moduleComponentLoadPolicy: StateLoadPolicy? = null override fun setPath(path: String) { super.setPath(path) if (File(path).exists()) { - isLoadModuleComponentState = ThreeState.YES + moduleComponentLoadPolicy = StateLoadPolicy.LOAD } } - override val isLoadComponentState: Boolean - get() = if (isLoadModuleComponentState == ThreeState.UNSURE) (project.stateStore as ProjectStoreImpl).isLoadComponentState else isLoadModuleComponentState.toBoolean() + override val loadPolicy: StateLoadPolicy + get() = moduleComponentLoadPolicy ?: (project.stateStore as ProjectStoreImpl).loadPolicy } \ No newline at end of file diff --git a/platform/configuration-store-impl/src/ProjectStoreImpl.kt b/platform/configuration-store-impl/src/ProjectStoreImpl.kt index 4bbd82b22556..e1451172af55 100644 --- a/platform/configuration-store-impl/src/ProjectStoreImpl.kt +++ b/platform/configuration-store-impl/src/ProjectStoreImpl.kt @@ -51,16 +51,19 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM private var presentableUrl: String? = null - override var isLoadComponentState = true + override var loadPolicy = StateLoadPolicy.LOAD init { assert(!project.isDefault()) } - override final fun isOptimiseTestLoadSpeed() = !isLoadComponentState + override final fun isOptimiseTestLoadSpeed() = loadPolicy != StateLoadPolicy.LOAD override final fun setOptimiseTestLoadSpeed(value: Boolean) { - isLoadComponentState = !value + // we don't load default state in tests as app store does because + // 1) we should not do it + // 2) it was so before, so, we preserve old behavior (otherwise RunManager will load template run configurations) + loadPolicy = if (value) StateLoadPolicy.NOT_LOAD else StateLoadPolicy.LOAD } override final fun getPathMacroManagerForDefaults() = pathMacroManager @@ -84,7 +87,7 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM if (ApplicationManager.getApplication().isUnitTestMode()) { // load state only if there are existing files - isLoadComponentState = File(filePath).exists() + setOptimiseTestLoadSpeed(!File(filePath).exists()) } } else { @@ -106,7 +109,7 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM if (ApplicationManager.getApplication().isUnitTestMode()) { // load state only if there are existing files - isLoadComponentState = dirStore.exists() + setOptimiseTestLoadSpeed(!dirStore.exists()) } } @@ -147,7 +150,6 @@ open class ProjectStoreImpl(override val project: ProjectImpl, private val pathM } catch (ignored: IOException) { } - } }