mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ModuleStoreBase for upsource
move getStorageSpecs to ProjectStoreBase for upsource
This commit is contained in:
@@ -21,27 +21,11 @@ import java.io.File
|
|||||||
|
|
||||||
private val MODULE_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(StoragePathMacros.MODULE_FILE, false)
|
private val MODULE_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(StoragePathMacros.MODULE_FILE, false)
|
||||||
|
|
||||||
private open class ModuleStoreImpl(module: Module, private val pathMacroManager: PathMacroManager) : ComponentStoreImpl() {
|
private open class ModuleStoreImpl(module: Module, private val pathMacroManager: PathMacroManager) : ModuleStoreBase() {
|
||||||
override val project = module.project
|
override val project = module.project
|
||||||
|
|
||||||
override val storageManager = ModuleStateStorageManager(pathMacroManager.createTrackingSubstitutor(), module)
|
override val storageManager = ModuleStateStorageManager(pathMacroManager.createTrackingSubstitutor(), module)
|
||||||
|
|
||||||
override fun <T> getStorageSpecs(component: PersistentStateComponent<T>, stateSpec: State, operation: StateStorageOperation): Array<out Storage> {
|
|
||||||
val storages = stateSpec.storages
|
|
||||||
if (storages.isEmpty()) {
|
|
||||||
return arrayOf(MODULE_FILE_STORAGE_ANNOTATION)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return super.getStorageSpecs(component, stateSpec, operation)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setPath(path: String) {
|
|
||||||
if (!storageManager.addMacro(StoragePathMacros.MODULE_FILE, path)) {
|
|
||||||
storageManager.getCachedFileStorages(listOf(StoragePathMacros.MODULE_FILE)).firstOrNull()?.setFile(null, File(path))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override final fun getPathMacroManagerForDefaults() = pathMacroManager
|
override final fun getPathMacroManagerForDefaults() = pathMacroManager
|
||||||
|
|
||||||
private class TestModuleStore(module: Module, pathMacroManager: PathMacroManager) : ModuleStoreImpl(module, pathMacroManager) {
|
private class TestModuleStore(module: Module, pathMacroManager: PathMacroManager) : ModuleStoreImpl(module, pathMacroManager) {
|
||||||
@@ -59,3 +43,24 @@ private open class ModuleStoreImpl(module: Module, private val pathMacroManager:
|
|||||||
get() = moduleComponentLoadPolicy ?: (project.stateStore as ComponentStoreImpl).loadPolicy
|
get() = moduleComponentLoadPolicy ?: (project.stateStore as ComponentStoreImpl).loadPolicy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// used in upsource
|
||||||
|
abstract class ModuleStoreBase : ComponentStoreImpl() {
|
||||||
|
override abstract val storageManager: StateStorageManagerImpl
|
||||||
|
|
||||||
|
override final fun <T> getStorageSpecs(component: PersistentStateComponent<T>, stateSpec: State, operation: StateStorageOperation): Array<out Storage> {
|
||||||
|
val storages = stateSpec.storages
|
||||||
|
if (storages.isEmpty()) {
|
||||||
|
return arrayOf(MODULE_FILE_STORAGE_ANNOTATION)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return super.getStorageSpecs(component, stateSpec, operation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setPath(path: String) {
|
||||||
|
if (!storageManager.addMacro(StoragePathMacros.MODULE_FILE, path)) {
|
||||||
|
storageManager.getCachedFileStorages(listOf(StoragePathMacros.MODULE_FILE)).firstOrNull()?.setFile(null, File(path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,6 +71,9 @@ abstract class ProjectStoreBase(override final val project: ProjectImpl) : Compo
|
|||||||
|
|
||||||
override abstract val storageManager: StateStorageManagerImpl
|
override abstract val storageManager: StateStorageManagerImpl
|
||||||
|
|
||||||
|
protected val isDirectoryBased: Boolean
|
||||||
|
get() = scheme == StorageScheme.DIRECTORY_BASED
|
||||||
|
|
||||||
override final fun setOptimiseTestLoadSpeed(value: Boolean) {
|
override final fun setOptimiseTestLoadSpeed(value: Boolean) {
|
||||||
// we don't load default state in tests as app store does because
|
// we don't load default state in tests as app store does because
|
||||||
// 1) we should not do it
|
// 1) we should not do it
|
||||||
@@ -151,6 +154,64 @@ abstract class ProjectStoreBase(override final val project: ProjectImpl) : Compo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun <T> getStorageSpecs(component: PersistentStateComponent<T>, stateSpec: State, operation: StateStorageOperation): Array<out Storage> {
|
||||||
|
val storages = stateSpec.storages
|
||||||
|
if (storages.isEmpty()) {
|
||||||
|
return arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDirectoryBased) {
|
||||||
|
var result: MutableList<Storage>? = null
|
||||||
|
for (storage in storages) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
if (storage.path != PROJECT_FILE) {
|
||||||
|
if (result == null) {
|
||||||
|
result = SmartList()
|
||||||
|
}
|
||||||
|
result.add(storage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.isNullOrEmpty()) {
|
||||||
|
return arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result!!.sortWith(deprecatedComparator)
|
||||||
|
// if we create project from default, component state written not to own storage file, but to project file,
|
||||||
|
// we don't have time to fix it properly, so, ancient hack restored
|
||||||
|
result.add(DEPRECATED_PROJECT_FILE_STORAGE_ANNOTATION)
|
||||||
|
return result.toTypedArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var result: MutableList<Storage>? = null
|
||||||
|
// FlexIdeProjectLevelCompilerOptionsHolder, FlexProjectLevelCompilerOptionsHolderImpl and CustomBeanRegistry
|
||||||
|
var hasOnlyDeprecatedStorages = true
|
||||||
|
for (storage in storages) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
if (storage.path == PROJECT_FILE || storage.path == StoragePathMacros.WORKSPACE_FILE) {
|
||||||
|
if (result == null) {
|
||||||
|
result = SmartList()
|
||||||
|
}
|
||||||
|
result.add(storage)
|
||||||
|
if (!storage.deprecated) {
|
||||||
|
hasOnlyDeprecatedStorages = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result.isNullOrEmpty()) {
|
||||||
|
return arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (hasOnlyDeprecatedStorages) {
|
||||||
|
result!!.add(PROJECT_FILE_STORAGE_ANNOTATION)
|
||||||
|
}
|
||||||
|
result!!.sortWith(deprecatedComparator)
|
||||||
|
return result.toTypedArray()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private open class ProjectStoreImpl(project: ProjectImpl, private val pathMacroManager: PathMacroManager) : ProjectStoreBase(project) {
|
private open class ProjectStoreImpl(project: ProjectImpl, private val pathMacroManager: PathMacroManager) : ProjectStoreBase(project) {
|
||||||
@@ -199,9 +260,6 @@ private open class ProjectStoreImpl(project: ProjectImpl, private val pathMacroM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val isDirectoryBased: Boolean
|
|
||||||
get() = scheme == StorageScheme.DIRECTORY_BASED
|
|
||||||
|
|
||||||
private fun saveProjectName() {
|
private fun saveProjectName() {
|
||||||
if (!isDirectoryBased) {
|
if (!isDirectoryBased) {
|
||||||
return
|
return
|
||||||
@@ -285,64 +343,6 @@ private open class ProjectStoreImpl(project: ProjectImpl, private val pathMacroM
|
|||||||
|
|
||||||
protected open fun beforeSave(readonlyFiles: List<Pair<SaveSession, VirtualFile>>) {
|
protected open fun beforeSave(readonlyFiles: List<Pair<SaveSession, VirtualFile>>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <T> getStorageSpecs(component: PersistentStateComponent<T>, stateSpec: State, operation: StateStorageOperation): Array<out Storage> {
|
|
||||||
val storages = stateSpec.storages
|
|
||||||
if (storages.isEmpty()) {
|
|
||||||
return arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDirectoryBased) {
|
|
||||||
var result: MutableList<Storage>? = null
|
|
||||||
for (storage in storages) {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
if (storage.path != PROJECT_FILE) {
|
|
||||||
if (result == null) {
|
|
||||||
result = SmartList()
|
|
||||||
}
|
|
||||||
result.add(storage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.isNullOrEmpty()) {
|
|
||||||
return arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result!!.sortWith(deprecatedComparator)
|
|
||||||
// if we create project from default, component state written not to own storage file, but to project file,
|
|
||||||
// we don't have time to fix it properly, so, ancient hack restored
|
|
||||||
result.add(DEPRECATED_PROJECT_FILE_STORAGE_ANNOTATION)
|
|
||||||
return result.toTypedArray()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var result: MutableList<Storage>? = null
|
|
||||||
// FlexIdeProjectLevelCompilerOptionsHolder, FlexProjectLevelCompilerOptionsHolderImpl and CustomBeanRegistry
|
|
||||||
var hasOnlyDeprecatedStorages = true
|
|
||||||
for (storage in storages) {
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
if (storage.path == PROJECT_FILE || storage.path == StoragePathMacros.WORKSPACE_FILE) {
|
|
||||||
if (result == null) {
|
|
||||||
result = SmartList()
|
|
||||||
}
|
|
||||||
result.add(storage)
|
|
||||||
if (!storage.deprecated) {
|
|
||||||
hasOnlyDeprecatedStorages = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result.isNullOrEmpty()) {
|
|
||||||
return arrayOf(PROJECT_FILE_STORAGE_ANNOTATION)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (hasOnlyDeprecatedStorages) {
|
|
||||||
result!!.add(PROJECT_FILE_STORAGE_ANNOTATION)
|
|
||||||
}
|
|
||||||
result!!.sortWith(deprecatedComparator)
|
|
||||||
return result.toTypedArray()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun dropUnableToSaveProjectNotification(project: Project, readOnlyFiles: Array<VirtualFile>) {
|
private fun dropUnableToSaveProjectNotification(project: Project, readOnlyFiles: Array<VirtualFile>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user