mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
project store — 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)
This commit is contained in:
@@ -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)));
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 <T> initPersistentComponent(stateSpec: State, component: PersistentStateComponent<T>, changedStorages: Set<StateStorage>?, reloadData: Boolean): String? {
|
||||
if (loadPolicy == StateLoadPolicy.NOT_LOAD) {
|
||||
return null
|
||||
}
|
||||
|
||||
val name = stateSpec.name
|
||||
val stateClass = ComponentSerializationUtil.getStateClass<T>(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
|
||||
}
|
||||
@@ -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<DefaultProjectExportableAndSaveTrigger>().project = project
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user