mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
IJPL-136 cleanup
GitOrigin-RevId: 43808d0552ba6b2ce58f27e9eae6d043e817f2ae
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bc582dbc44
commit
0e46c68bcd
@@ -1,5 +1,6 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("ReplaceJavaStaticMethodWithKotlinAnalog")
|
||||
@file:Suppress("ReplaceJavaStaticMethodWithKotlinAnalog", "ReplaceGetOrSet")
|
||||
@file:ApiStatus.Internal
|
||||
|
||||
package com.intellij.configurationStore
|
||||
|
||||
@@ -29,7 +30,7 @@ import java.nio.file.Path
|
||||
|
||||
const val APP_CONFIG: String = "\$APP_CONFIG\$"
|
||||
|
||||
@ApiStatus.Internal
|
||||
@VisibleForTesting
|
||||
@Suppress("NonDefaultConstructor")
|
||||
open class ApplicationStoreImpl(private val app: Application) : ComponentStoreWithExtraComponents(), ApplicationStoreJpsContentReader {
|
||||
override val storageManager: ApplicationStateStorageManager = ApplicationStateStorageManager(
|
||||
@@ -129,8 +130,7 @@ class ApplicationStateStorageManager(pathMacroManager: PathMacroManager? = null,
|
||||
}
|
||||
else {
|
||||
// APP_CONFIG is the first macro
|
||||
return macros[0].value.resolve(collapsedPath)
|
||||
}
|
||||
return macros.get(0).value.resolve(collapsedPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
|
||||
override suspend fun save(forceSavingAllSettings: Boolean) {
|
||||
val result = SaveResult()
|
||||
doSave(result, forceSavingAllSettings)
|
||||
doSave(saveResult = result, forceSavingAllSettings = forceSavingAllSettings)
|
||||
result.rethrow()
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
for (name in names) {
|
||||
val start = System.currentTimeMillis()
|
||||
try {
|
||||
val info = components[name] ?: continue
|
||||
val info = components.get(name) ?: continue
|
||||
var currentModificationCount = -1L
|
||||
|
||||
if (info.lastSaved != -1) {
|
||||
@@ -293,10 +293,12 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
}
|
||||
}
|
||||
|
||||
commitComponent(sessionManager = sessionManager,
|
||||
info = info,
|
||||
componentName = name,
|
||||
modificationCountChanged = modificationCountChanged)
|
||||
commitComponent(
|
||||
sessionManager = sessionManager,
|
||||
info = info,
|
||||
componentName = name,
|
||||
modificationCountChanged = modificationCountChanged,
|
||||
)
|
||||
info.updateModificationCount(currentModificationCount)
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
@@ -653,9 +655,11 @@ abstract class ComponentStoreImpl : IComponentStore {
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun <T> getStorageSpecs(component: PersistentStateComponent<T>,
|
||||
stateSpec: State,
|
||||
operation: StateStorageOperation): List<Storage> {
|
||||
protected open fun <T> getStorageSpecs(
|
||||
component: PersistentStateComponent<T>,
|
||||
stateSpec: State,
|
||||
operation: StateStorageOperation,
|
||||
): List<Storage> {
|
||||
val storages = getWithPerOsStorages(stateSpec.storages)
|
||||
if (storages.size == 1 || component is StateStorageChooserEx) {
|
||||
return storages.toList()
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import java.io.InputStream
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
|
||||
@Internal
|
||||
class CompoundStreamProvider : StreamProvider {
|
||||
private val providers = ContainerUtil.createConcurrentList<StreamProvider>()
|
||||
private val providerListModificationCount = AtomicInteger()
|
||||
internal class CompoundStreamProvider : StreamProvider {
|
||||
private val providers = CopyOnWriteArrayList<StreamProvider>()
|
||||
|
||||
override val saveStorageDataOnReload: Boolean // true by default
|
||||
// true by default
|
||||
override val saveStorageDataOnReload: Boolean
|
||||
get() = !providers.any { !it.saveStorageDataOnReload }
|
||||
|
||||
override val enabled: Boolean
|
||||
@@ -21,24 +18,29 @@ class CompoundStreamProvider : StreamProvider {
|
||||
override val isExclusive: Boolean
|
||||
get() = providers.any { it.isExclusive }
|
||||
|
||||
val isExclusivelyEnabled: Boolean
|
||||
get() = enabled && isExclusive
|
||||
override fun isApplicable(fileSpec: String, roamingType: RoamingType): Boolean {
|
||||
return providers.any { it.isApplicable(fileSpec = fileSpec, roamingType = roamingType) }
|
||||
}
|
||||
|
||||
override fun isApplicable(fileSpec: String, roamingType: RoamingType): Boolean = providers.any { it.isApplicable(fileSpec, roamingType) }
|
||||
override fun read(fileSpec: String, roamingType: RoamingType, consumer: (InputStream?) -> Unit): Boolean {
|
||||
return providers.any { it.read(fileSpec = fileSpec, roamingType = roamingType, consumer = consumer) }
|
||||
}
|
||||
|
||||
override fun read(fileSpec: String, roamingType: RoamingType, consumer: (InputStream?) -> Unit): Boolean = providers.any { it.read(fileSpec, roamingType, consumer) }
|
||||
|
||||
override fun processChildren(path: String,
|
||||
roamingType: RoamingType,
|
||||
filter: Function1<String, Boolean>,
|
||||
processor: Function3<String, InputStream, Boolean, Boolean>): Boolean {
|
||||
return providers.any { it.processChildren(path, roamingType, filter, processor) }
|
||||
override fun processChildren(
|
||||
path: String,
|
||||
roamingType: RoamingType,
|
||||
filter: Function1<String, Boolean>,
|
||||
processor: Function3<String, InputStream, Boolean, Boolean>,
|
||||
): Boolean {
|
||||
return providers.any {
|
||||
it.processChildren(path = path, roamingType = roamingType, filter = filter, processor = processor)
|
||||
}
|
||||
}
|
||||
|
||||
override fun write(fileSpec: String, content: ByteArray, roamingType: RoamingType) {
|
||||
providers.forEach {
|
||||
if (it.isApplicable(fileSpec, roamingType)) {
|
||||
it.write(fileSpec, content, roamingType)
|
||||
for (provider in providers) {
|
||||
if (provider.isApplicable(fileSpec, roamingType)) {
|
||||
provider.write(fileSpec = fileSpec, content = content, roamingType = roamingType)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,8 +48,8 @@ class CompoundStreamProvider : StreamProvider {
|
||||
override fun delete(fileSpec: String, roamingType: RoamingType): Boolean = providers.any { it.delete(fileSpec, roamingType) }
|
||||
|
||||
override fun deleteIfObsolete(fileSpec: String, roamingType: RoamingType) {
|
||||
providers.forEach {
|
||||
it.deleteIfObsolete(fileSpec, roamingType)
|
||||
for (provider in providers) {
|
||||
provider.deleteIfObsolete(fileSpec, roamingType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,13 +60,11 @@ class CompoundStreamProvider : StreamProvider {
|
||||
else {
|
||||
providers.add(provider)
|
||||
}
|
||||
providerListModificationCount.getAndIncrement()
|
||||
}
|
||||
|
||||
fun removeStreamProvider(aClass: Class<out StreamProvider>) {
|
||||
providers.removeAll(aClass::isInstance)
|
||||
providerListModificationCount.getAndIncrement()
|
||||
}
|
||||
|
||||
fun getInstanceOf(aClass: Class<out StreamProvider>): StreamProvider = providers.first { aClass.isInstance(it) }
|
||||
override fun getInstanceOf(aClass: Class<out StreamProvider>): StreamProvider = providers.first { aClass.isInstance(it) }
|
||||
}
|
||||
@@ -39,18 +39,23 @@ internal class DefaultProjectStoreImpl(override val project: Project) : Componen
|
||||
get() = null
|
||||
|
||||
override fun addStreamProvider(provider: StreamProvider, first: Boolean) {
|
||||
compoundStreamProvider.addStreamProvider(provider, first)
|
||||
compoundStreamProvider.addStreamProvider(provider = provider, first = first)
|
||||
}
|
||||
|
||||
override fun removeStreamProvider(aClass: Class<out StreamProvider>) {
|
||||
compoundStreamProvider.removeStreamProvider(aClass)
|
||||
}
|
||||
|
||||
override fun getStateStorage(storageSpec: Storage): DefaultProjectStorage = storage
|
||||
override fun getStateStorage(storageSpec: Storage) = storage
|
||||
|
||||
override fun expandMacro(collapsedPath: String) = throw UnsupportedOperationException()
|
||||
|
||||
override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): DefaultProjectStorage = storage
|
||||
override fun collapseMacro(path: String): String = throw UnsupportedOperationException()
|
||||
|
||||
override val streamProvider: StreamProvider
|
||||
get() = compoundStreamProvider
|
||||
|
||||
override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation) = storage
|
||||
}
|
||||
|
||||
override fun isUseLoadedStateAsExisting(storage: StateStorage) = false
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.Nls
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
@@ -57,9 +56,7 @@ open class ExportSettingsAction : AnAction(), ActionRemoteBehaviorSpecification.
|
||||
e.presentation.isEnabled = true
|
||||
}
|
||||
|
||||
override fun getActionUpdateThread(): ActionUpdateThread {
|
||||
return ActionUpdateThread.BGT
|
||||
}
|
||||
override fun getActionUpdateThread() = ActionUpdateThread.BGT
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
ApplicationManager.getApplication().saveSettings()
|
||||
@@ -380,8 +377,7 @@ private fun loadFileContent(item: ExportableItem, storageManager: StateStorageMa
|
||||
var content: ByteArray? = null
|
||||
var errorDuringLoadingFromProvider = false
|
||||
val skipProvider = !item.roamingType.isRoamable
|
||||
val handledByProvider = !skipProvider && storageManager.compoundStreamProvider.read(item.fileSpec.rawFileSpec,
|
||||
item.roamingType) { inputStream ->
|
||||
val handledByProvider = !skipProvider && storageManager.streamProvider.read(item.fileSpec.rawFileSpec, item.roamingType) { inputStream ->
|
||||
// null stream means empty file which shouldn't be exported
|
||||
inputStream?.let {
|
||||
try {
|
||||
@@ -413,8 +409,11 @@ private fun isComponentDefined(componentName: String?, bytes: ByteArray): Boolea
|
||||
|
||||
private fun exportDirectory(item: ExportableItem, zip: Compressor, storageManager: StateStorageManagerImpl) {
|
||||
var error = false
|
||||
val success = storageManager.compoundStreamProvider.processChildren(item.fileSpec.relativePath, item.roamingType,
|
||||
{ true }) { name: String, inputStream: InputStream, _: Boolean ->
|
||||
val success = storageManager.streamProvider.processChildren(
|
||||
path = item.fileSpec.relativePath,
|
||||
roamingType = item.roamingType,
|
||||
filter = { true },
|
||||
) { name, inputStream, _ ->
|
||||
try {
|
||||
val fileName = item.fileSpec.relativePath + "/" + name
|
||||
zip.addFile(fileName, inputStream)
|
||||
@@ -437,8 +436,7 @@ private fun exportDirectory(item: ExportableItem, zip: Compressor, storageManage
|
||||
|
||||
private fun checkIfDirectoryExists(item: ExportableItem, storageManager: StateStorageManagerImpl): Boolean {
|
||||
var exists = false
|
||||
val handledByProvider = storageManager.compoundStreamProvider.processChildren(item.fileSpec.relativePath, item.roamingType,
|
||||
{ true }) { _, _, _ ->
|
||||
val handledByProvider = storageManager.streamProvider.processChildren(item.fileSpec.relativePath, item.roamingType, { true }) { _, _, _ ->
|
||||
exists = true
|
||||
false // stop processing children: now we know that the directory exists and is not empty
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("ReplacePutWithAssignment")
|
||||
@file:Suppress("ReplacePutWithAssignment", "ReplaceJavaStaticMethodWithKotlinAnalog")
|
||||
|
||||
package com.intellij.configurationStore
|
||||
|
||||
@@ -107,7 +107,7 @@ internal open class ModuleStoreImpl(module: Module) : ComponentStoreImpl(), Modu
|
||||
}
|
||||
|
||||
private class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubstitutor, module: Module)
|
||||
: StateStorageManagerImpl(rootTagName = "module", macroSubstitutor = macroSubstitutor, componentManager = module),
|
||||
: StateStorageManagerImpl(rootTagName = "module", macroSubstitutor = macroSubstitutor, componentManager = module, controller = null),
|
||||
RenameableStateStorageManager {
|
||||
override fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String {
|
||||
return StoragePathMacros.MODULE_FILE
|
||||
@@ -132,8 +132,8 @@ private class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubst
|
||||
else if (storage.file.fileName.toString() != newName) {
|
||||
// old file didn't exist or renaming failed
|
||||
val newFile = storage.file.parent.resolve(newName)
|
||||
storage.setFile(null, newFile)
|
||||
pathRenamed(newFile, null)
|
||||
storage.setFile(virtualFile = null, ioFileIfChanged = newFile)
|
||||
pathRenamed(newPath = newFile, event = null)
|
||||
}
|
||||
}
|
||||
catch (e: IOException) {
|
||||
@@ -148,7 +148,7 @@ private class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubst
|
||||
|
||||
override fun pathRenamed(newPath: Path, event: VFileEvent?) {
|
||||
try {
|
||||
setMacros(listOf(Macro(StoragePathMacros.MODULE_FILE, newPath)))
|
||||
setMacros(java.util.List.of(Macro(StoragePathMacros.MODULE_FILE, newPath)))
|
||||
}
|
||||
finally {
|
||||
val requestor = event?.requestor
|
||||
@@ -201,15 +201,15 @@ private class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubst
|
||||
usePathMacroManager: Boolean,
|
||||
rootTagName: String?
|
||||
): StateStorage {
|
||||
val provider = if (roamingType == RoamingType.DISABLED) null else compoundStreamProvider
|
||||
val provider = if (roamingType == RoamingType.DISABLED) null else streamProvider
|
||||
return TrackedFileStorage(
|
||||
storageManager = this,
|
||||
file,
|
||||
collapsedPath,
|
||||
rootTagName,
|
||||
roamingType,
|
||||
macroSubstitutor,
|
||||
provider,
|
||||
file = file,
|
||||
fileSpec = collapsedPath,
|
||||
rootElementName = rootTagName,
|
||||
roamingType = roamingType,
|
||||
pathMacroManager = macroSubstitutor,
|
||||
provider = provider,
|
||||
controller = null,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -57,14 +57,14 @@ open class ProjectWithModuleStoreImpl(project: Project) : ProjectStoreImpl(proje
|
||||
) {
|
||||
val projectSessionManager = projectSessionManager as ProjectWithModulesSaveSessionProducerManager
|
||||
|
||||
val writer = JpsStorageContentWriter(projectSessionManager, this, project)
|
||||
val writer = JpsStorageContentWriter(session = projectSessionManager, store = this, project = project)
|
||||
JpsProjectModelSynchronizer.getInstance(project).saveChangedProjectEntities(writer)
|
||||
|
||||
for (module in ModuleManager.getInstance(project).modules) {
|
||||
val moduleStore = module.getService(IComponentStore::class.java) as? ComponentStoreImpl ?: continue
|
||||
val moduleSessionManager = moduleStore.createSaveSessionProducerManager()
|
||||
moduleStore.commitComponents(forceSavingAllSettings, moduleSessionManager, saveResult)
|
||||
projectSessionManager.commitComponents(moduleStore, moduleSessionManager)
|
||||
moduleStore.commitComponents(isForce = forceSavingAllSettings, sessionManager = moduleSessionManager, saveResult = saveResult)
|
||||
projectSessionManager.commitComponents(moduleStore = moduleStore, moduleSaveSessionManager = moduleSessionManager)
|
||||
moduleSessionManager.collectSaveSessions(saveSessions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,9 @@ open class ProjectStoreImpl(final override val project: Project) : ComponentStor
|
||||
|
||||
final override var loadPolicy: StateLoadPolicy = StateLoadPolicy.LOAD
|
||||
|
||||
final override fun isOptimiseTestLoadSpeed(): Boolean = loadPolicy != StateLoadPolicy.LOAD
|
||||
final override fun isOptimiseTestLoadSpeed() = loadPolicy != StateLoadPolicy.LOAD
|
||||
|
||||
final override fun getStorageScheme(): StorageScheme = if (isDirectoryBased) StorageScheme.DIRECTORY_BASED else StorageScheme.DEFAULT
|
||||
final override fun getStorageScheme() = if (isDirectoryBased) StorageScheme.DIRECTORY_BASED else StorageScheme.DEFAULT
|
||||
|
||||
override val storageManager: StateStorageManagerImpl =
|
||||
ProjectStateStorageManager(TrackingPathMacroSubstitutorImpl(PathMacroManager.getInstance(project)), project)
|
||||
@@ -78,7 +78,9 @@ open class ProjectStoreImpl(final override val project: Project) : ComponentStor
|
||||
|
||||
final override fun getWorkspacePath(): Path = storageManager.expandMacro(StoragePathMacros.WORKSPACE_FILE)
|
||||
|
||||
final override fun clearStorages(): Unit = storageManager.clearStorages()
|
||||
final override fun clearStorages() {
|
||||
storageManager.clearStorages()
|
||||
}
|
||||
|
||||
final override fun getPathMacroManagerForDefaults(): PathMacroManager = PathMacroManager.getInstance(project)
|
||||
|
||||
@@ -151,9 +153,7 @@ open class ProjectStoreImpl(final override val project: Project) : ComponentStor
|
||||
return
|
||||
}
|
||||
|
||||
val productWorkspaceFile = PathManager.getConfigDir()
|
||||
.resolve("workspace")
|
||||
.resolve("$projectWorkspaceId.xml")
|
||||
val productWorkspaceFile = PathManager.getConfigDir().resolve("workspace/$projectWorkspaceId.xml")
|
||||
macros.add(Macro(StoragePathMacros.PRODUCT_WORKSPACE_FILE, productWorkspaceFile))
|
||||
storageManager.setMacros(macros)
|
||||
}
|
||||
@@ -167,9 +167,11 @@ open class ProjectStoreImpl(final override val project: Project) : ComponentStor
|
||||
}
|
||||
else {
|
||||
moveComponentConfiguration(
|
||||
defaultProject, element,
|
||||
defaultProject = defaultProject,
|
||||
element = element,
|
||||
storagePathResolver = { PROJECT_FILE }, // doesn't matter; any path will be resolved as projectFilePath (see `fileResolver`)
|
||||
fileResolver = { if (it == "workspace.xml") workspacePath else dirOrFile!! })
|
||||
fileResolver = { if (it == "workspace.xml") workspacePath else dirOrFile!! },
|
||||
)
|
||||
}
|
||||
}.getOrLogException(LOG)
|
||||
}
|
||||
@@ -197,7 +199,7 @@ open class ProjectStoreImpl(final override val project: Project) : ComponentStor
|
||||
path = projectFilePath
|
||||
prefix = projectName
|
||||
}
|
||||
return "${prefix}${Integer.toHexString(path.invariantSeparatorsPathString.hashCode())}"
|
||||
return "$prefix${Integer.toHexString(path.invariantSeparatorsPathString.hashCode())}"
|
||||
}
|
||||
|
||||
override fun getPresentableUrl(): String {
|
||||
@@ -211,7 +213,11 @@ open class ProjectStoreImpl(final override val project: Project) : ComponentStor
|
||||
|
||||
override fun getProjectWorkspaceId(): String? = ProjectIdManager.getInstance(project).id
|
||||
|
||||
override fun <T> getStorageSpecs(component: PersistentStateComponent<T>, stateSpec: State, operation: StateStorageOperation): List<Storage> {
|
||||
override fun <T> getStorageSpecs(
|
||||
component: PersistentStateComponent<T>,
|
||||
stateSpec: State,
|
||||
operation: StateStorageOperation,
|
||||
): List<Storage> {
|
||||
val storages = stateSpec.storages
|
||||
if (isDirectoryBased) {
|
||||
if (storages.size == 2 && ApplicationManager.getApplication().isUnitTestMode &&
|
||||
@@ -398,9 +404,15 @@ open class ProjectStoreImpl(final override val project: Project) : ComponentStor
|
||||
}
|
||||
}
|
||||
|
||||
private class ProjectStateStorageManager(macroSubstitutor: PathMacroSubstitutor, private val project: Project)
|
||||
: StateStorageManagerImpl(rootTagName = "project", macroSubstitutor = macroSubstitutor, componentManager = project)
|
||||
{
|
||||
private class ProjectStateStorageManager(
|
||||
macroSubstitutor: PathMacroSubstitutor,
|
||||
private val project: Project,
|
||||
) : StateStorageManagerImpl(
|
||||
rootTagName = "project",
|
||||
macroSubstitutor = macroSubstitutor,
|
||||
componentManager = project,
|
||||
controller = null,
|
||||
) {
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = !useBackgroundSave
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("ReplaceGetOrSet")
|
||||
@file:Suppress("ReplaceGetOrSet", "ReplaceJavaStaticMethodWithKotlinAnalog")
|
||||
@file:Internal
|
||||
|
||||
package com.intellij.configurationStore
|
||||
|
||||
@@ -21,7 +22,6 @@ import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.concurrent.read
|
||||
import kotlin.concurrent.write
|
||||
@@ -30,22 +30,26 @@ import kotlin.io.path.invariantSeparatorsPathString
|
||||
/**
|
||||
* If componentManager not specified, storage will not add file tracker
|
||||
*/
|
||||
@Internal
|
||||
open class StateStorageManagerImpl(
|
||||
@NonNls private val rootTagName: String,
|
||||
final override val macroSubstitutor: PathMacroSubstitutor? = null,
|
||||
final override val componentManager: ComponentManager?,
|
||||
private val controller: SettingsController? = null,
|
||||
private val controller: SettingsController?,
|
||||
) : StateStorageManager {
|
||||
private val virtualFileTracker = createDefaultVirtualTracker(componentManager)
|
||||
|
||||
@Volatile
|
||||
protected var macros: List<Macro> = Collections.emptyList()
|
||||
@JvmField
|
||||
protected var macros: List<Macro> = java.util.List.of()
|
||||
|
||||
@JvmField
|
||||
protected val storageLock: ReentrantReadWriteLock = ReentrantReadWriteLock()
|
||||
private val storages = HashMap<String, StateStorage>()
|
||||
|
||||
val compoundStreamProvider: CompoundStreamProvider = CompoundStreamProvider()
|
||||
override val streamProvider: StreamProvider
|
||||
get() = compoundStreamProvider
|
||||
|
||||
private val compoundStreamProvider = CompoundStreamProvider()
|
||||
|
||||
override fun addStreamProvider(provider: StreamProvider, first: Boolean) {
|
||||
compoundStreamProvider.addStreamProvider(provider = provider, first = first)
|
||||
@@ -58,7 +62,8 @@ open class StateStorageManagerImpl(
|
||||
// access under storageLock
|
||||
private var isUseVfsListener = when (componentManager) {
|
||||
null -> ThreeState.NO
|
||||
else -> ThreeState.UNSURE // unsure because depends on stream provider state
|
||||
// unsure because depends on stream provider state
|
||||
else -> ThreeState.UNSURE
|
||||
}
|
||||
|
||||
protected open val isUseXmlProlog: Boolean
|
||||
@@ -187,12 +192,14 @@ open class StateStorageManagerImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun createStateStorage(storageClass: Class<out StateStorage>,
|
||||
collapsedPath: String,
|
||||
roamingType: RoamingType,
|
||||
@Suppress("DEPRECATION", "removal") stateSplitter: Class<out StateSplitter>,
|
||||
usePathMacroManager: Boolean,
|
||||
exclusive: Boolean = false): StateStorage {
|
||||
private fun createStateStorage(
|
||||
storageClass: Class<out StateStorage>,
|
||||
collapsedPath: String,
|
||||
roamingType: RoamingType,
|
||||
@Suppress("DEPRECATION", "removal") stateSplitter: Class<out StateSplitter>,
|
||||
usePathMacroManager: Boolean,
|
||||
exclusive: Boolean = false,
|
||||
): StateStorage {
|
||||
if (storageClass != StateStorage::class.java) {
|
||||
val constructor = storageClass.constructors.first { it.parameterCount <= 3 }
|
||||
constructor.isAccessible = true
|
||||
@@ -274,17 +281,6 @@ open class StateStorageManagerImpl(
|
||||
)
|
||||
}
|
||||
|
||||
internal class TrackedDirectoryStorage(
|
||||
override val storageManager: StateStorageManagerImpl,
|
||||
dir: Path,
|
||||
@Suppress("DEPRECATION", "removal") splitter: StateSplitter,
|
||||
macroSubstitutor: PathMacroSubstitutor?
|
||||
) : DirectoryBasedStorage(dir = dir, splitter = splitter, pathMacroSubstitutor = macroSubstitutor),
|
||||
StorageVirtualFileTracker.TrackedStorage {
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = storageManager.isUseVfsForWrite
|
||||
}
|
||||
|
||||
internal class TrackedFileStorage(
|
||||
override val storageManager: StateStorageManagerImpl,
|
||||
file: Path,
|
||||
@@ -380,7 +376,7 @@ open class StateStorageManagerImpl(
|
||||
throw IllegalStateException("Cannot resolve $collapsedPath in $macros")
|
||||
}
|
||||
|
||||
fun collapseMacro(path: String): String {
|
||||
final override fun collapseMacro(path: String): String {
|
||||
for ((key, value) in macros) {
|
||||
val result = path.replace(value.invariantSeparatorsPathString, key)
|
||||
if (result !== path) {
|
||||
@@ -392,7 +388,7 @@ open class StateStorageManagerImpl(
|
||||
|
||||
final override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage? {
|
||||
val oldStorageSpec = getOldStorageSpec(component = component, componentName = componentName, operation = operation) ?: return null
|
||||
return getOrCreateStorage(oldStorageSpec, RoamingType.DEFAULT)
|
||||
return getOrCreateStorage(collapsedPath = oldStorageSpec, roamingType = RoamingType.DEFAULT)
|
||||
}
|
||||
|
||||
protected open fun getOldStorageSpec(component: Any, componentName: String, operation: StateStorageOperation): String? = null
|
||||
@@ -403,6 +399,17 @@ open class StateStorageManagerImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private class TrackedDirectoryStorage(
|
||||
override val storageManager: StateStorageManagerImpl,
|
||||
dir: Path,
|
||||
@Suppress("DEPRECATION", "removal") splitter: StateSplitter,
|
||||
macroSubstitutor: PathMacroSubstitutor?
|
||||
) : DirectoryBasedStorage(dir = dir, splitter = splitter, pathMacroSubstitutor = macroSubstitutor),
|
||||
StorageVirtualFileTracker.TrackedStorage {
|
||||
override val isUseVfsForWrite: Boolean
|
||||
get() = storageManager.isUseVfsForWrite
|
||||
}
|
||||
|
||||
fun removeMacroIfStartsWith(path: String, macro: String): String = path.removePrefix("$macro/")
|
||||
|
||||
@Suppress("DEPRECATION", "removal")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.components.PathMacroManager
|
||||
@@ -11,7 +11,8 @@ internal fun PathMacroManager?.createTrackingSubstitutor(): TrackingPathMacroSub
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
class TrackingPathMacroSubstitutorImpl(internal val macroManager: PathMacroManager) : PathMacroSubstitutor by macroManager, TrackingPathMacroSubstitutor {
|
||||
class TrackingPathMacroSubstitutorImpl(internal val macroManager: PathMacroManager)
|
||||
: PathMacroSubstitutor by macroManager, TrackingPathMacroSubstitutor {
|
||||
private val lock = Object()
|
||||
|
||||
private val macroToComponentNames = HashMap<String, MutableSet<String>>()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.configurationStore.schemeManager
|
||||
|
||||
import com.intellij.configurationStore.*
|
||||
@@ -52,15 +52,17 @@ sealed class SchemeManagerFactoryBase : SchemeManagerFactory(), SettingsSavingCo
|
||||
streamProvider != null && streamProvider.isApplicable(path, roamingType) -> null
|
||||
else -> createFileChangeSubscriber()
|
||||
}
|
||||
val manager = SchemeManagerImpl(path,
|
||||
processor,
|
||||
streamProvider ?: (componentManager?.stateStore?.storageManager as? StateStorageManagerImpl)?.compoundStreamProvider,
|
||||
ioDirectory = directoryPath ?: pathToFile(path),
|
||||
roamingType = roamingType,
|
||||
presentableName = presentableName,
|
||||
schemeNameToFileName = schemeNameToFileName,
|
||||
fileChangeSubscriber = fileChangeSubscriber,
|
||||
settingsCategory = settingsCategory)
|
||||
val manager = SchemeManagerImpl(
|
||||
path,
|
||||
processor,
|
||||
streamProvider ?: componentManager?.stateStore?.storageManager?.streamProvider,
|
||||
ioDirectory = directoryPath ?: pathToFile(path),
|
||||
roamingType = roamingType,
|
||||
presentableName = presentableName,
|
||||
schemeNameToFileName = schemeNameToFileName,
|
||||
fileChangeSubscriber = fileChangeSubscriber,
|
||||
settingsCategory = settingsCategory,
|
||||
)
|
||||
if (isAutoSave) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
managers.add(manager as SchemeManagerImpl<Scheme, Scheme>)
|
||||
|
||||
@@ -163,14 +163,15 @@ internal class ComponentStoreModificationTrackerTest {
|
||||
}
|
||||
|
||||
private class TestComponentStore(testAppConfigPath: Path) : ComponentStoreImpl() {
|
||||
private class TestStateStorageManager : StateStorageManagerImpl("application", componentManager = null) {
|
||||
private class TestStateStorageManager : StateStorageManagerImpl("application", componentManager = null, controller = null) {
|
||||
override val isUseXmlProlog = false
|
||||
|
||||
override fun normalizeFileSpec(fileSpec: String) = removeMacroIfStartsWith(super.normalizeFileSpec(fileSpec), APP_CONFIG)
|
||||
|
||||
override fun expandMacro(collapsedPath: String): Path =
|
||||
if (collapsedPath[0] == '$') super.expandMacro(collapsedPath)
|
||||
override fun expandMacro(collapsedPath: String): Path {
|
||||
return if (collapsedPath[0] == '$') super.expandMacro(collapsedPath)
|
||||
else macros[0].value.resolve(collapsedPath)
|
||||
}
|
||||
}
|
||||
|
||||
override val storageManager: StateStorageManagerImpl = TestStateStorageManager()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 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.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
@@ -23,7 +23,7 @@ class StorageManagerTest {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
storageManager = StateStorageManagerImpl("foo", componentManager = null)
|
||||
storageManager = StateStorageManagerImpl("foo", componentManager = null, controller = null)
|
||||
storageManager.setMacros(listOf(Macro(MACRO, Path.of("/temp/m1"))))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("ReplaceGetOrSet", "ReplacePutWithAssignment")
|
||||
|
||||
package com.intellij.ide.fileTemplates.impl
|
||||
|
||||
import com.intellij.configurationStore.StateStorageManagerImpl
|
||||
import com.intellij.configurationStore.StreamProvider
|
||||
import com.intellij.ide.fileTemplates.FileTemplateManager
|
||||
import com.intellij.ide.plugins.DynamicPluginListener
|
||||
@@ -13,7 +12,6 @@ import com.intellij.ide.plugins.cl.PluginAwareClassLoader
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.openapi.components.ComponentManager
|
||||
import com.intellij.openapi.components.ComponentStoreOwner
|
||||
import com.intellij.openapi.diagnostic.getOrLogException
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
@@ -47,7 +45,7 @@ private const val DESCRIPTION_EXTENSION_SUFFIX = ".$DESCRIPTION_FILE_EXTENSION"
|
||||
|
||||
/**
|
||||
* Serves as a container for all existing template manager types and loads corresponding templates lazily.
|
||||
* Reloads templates on plugins change.
|
||||
* Reloads templates on plugin change.
|
||||
*/
|
||||
internal open class FileTemplatesLoader(project: Project?) : Disposable {
|
||||
companion object {
|
||||
@@ -169,19 +167,27 @@ private fun loadConfiguration(project: Project?): LoadedConfiguration {
|
||||
val managers = HashMap<String, FTManager>(managerToDir.size)
|
||||
val streamProvider = streamProvider(project)
|
||||
for ((name, pathPrefix) in managerToDir) {
|
||||
val manager = FTManager(name, templatePath.resolve(pathPrefix), configDir.resolve(pathPrefix), result.prefixToTemplates.get(pathPrefix) ?: emptyList(),
|
||||
name == FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, streamProvider)
|
||||
val manager = FTManager(
|
||||
name,
|
||||
templatePath.resolve(pathPrefix),
|
||||
configDir.resolve(pathPrefix),
|
||||
result.prefixToTemplates.get(pathPrefix) ?: emptyList(),
|
||||
name == FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY,
|
||||
streamProvider,
|
||||
)
|
||||
manager.loadCustomizedContent()
|
||||
managers.put(name, manager)
|
||||
}
|
||||
return LoadedConfiguration(managers = managers,
|
||||
defaultTemplateDescription = result.defaultTemplateDescription,
|
||||
defaultIncludeDescription = result.defaultIncludeDescription)
|
||||
return LoadedConfiguration(
|
||||
managers = managers,
|
||||
defaultTemplateDescription = result.defaultTemplateDescription,
|
||||
defaultIncludeDescription = result.defaultIncludeDescription,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun streamProvider(project: Project?): StreamProvider {
|
||||
val componentManager: ComponentManager = project ?: ApplicationManager.getApplication()
|
||||
return ((componentManager as ComponentStoreOwner).componentStore.storageManager as StateStorageManagerImpl).compoundStreamProvider
|
||||
val componentManager = (project ?: ApplicationManager.getApplication()) as ComponentStoreOwner
|
||||
return (componentManager as ComponentStoreOwner).componentStore.storageManager.streamProvider
|
||||
}
|
||||
|
||||
private fun loadDefaultTemplates(prefixes: List<String>): FileTemplateLoadResult {
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("OVERRIDE_DEPRECATION", "ReplaceGetOrSet", "ReplacePutWithAssignment", "ReplaceJavaStaticMethodWithKotlinAnalog")
|
||||
|
||||
package com.intellij.openapi.module.impl
|
||||
|
||||
import com.intellij.configurationStore.RenameableStateStorageManager
|
||||
import com.intellij.ide.highlighter.ModuleFileType
|
||||
import com.intellij.ide.plugins.ContainerDescriptor
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptorImpl
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.components.impl.stores.IComponentStore
|
||||
import com.intellij.openapi.components.impl.stores.ModuleStore
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.getOrLogException
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager.Companion.getInstance
|
||||
import com.intellij.openapi.module.impl.scopes.ModuleScopeProviderImpl
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ex.ProjectEx
|
||||
@@ -24,11 +21,8 @@ import com.intellij.openapi.roots.ProjectModelElement
|
||||
import com.intellij.openapi.roots.ProjectModelExternalSource
|
||||
import com.intellij.openapi.ui.Queryable
|
||||
import com.intellij.openapi.util.SimpleModificationTracker
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointer
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerListener
|
||||
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.serviceContainer.ComponentManagerImpl
|
||||
import com.intellij.serviceContainer.emptyConstructorMethodType
|
||||
@@ -48,8 +42,7 @@ private val LOG: Logger
|
||||
open class ModuleImpl @ApiStatus.Internal constructor(
|
||||
name: String,
|
||||
project: Project,
|
||||
) : ComponentManagerImpl(project as ComponentManagerImpl), ModuleEx, Queryable {
|
||||
|
||||
) : ComponentManagerImpl(parent = project as ComponentManagerImpl), ModuleEx, Queryable {
|
||||
private val project: Project
|
||||
protected var imlFilePointer: VirtualFilePointer? = null
|
||||
|
||||
@@ -58,23 +51,6 @@ open class ModuleImpl @ApiStatus.Internal constructor(
|
||||
private var name: String? = null
|
||||
private val moduleScopeProvider: ModuleScopeProvider
|
||||
|
||||
@ApiStatus.Internal
|
||||
constructor(name: String, project: Project, filePath: String) : this(name = name, project = project) {
|
||||
@Suppress("LeakingThis")
|
||||
imlFilePointer = VirtualFilePointerManager.getInstance().create(
|
||||
VfsUtilCore.pathToUrl(filePath), this,
|
||||
object : VirtualFilePointerListener {
|
||||
override fun validityChanged(pointers: Array<VirtualFilePointer>) {
|
||||
if (imlFilePointer == null) return
|
||||
val virtualFile = imlFilePointer!!.file
|
||||
if (virtualFile != null) {
|
||||
(store as ModuleStore).setPath(path = virtualFile.toNioPath(), virtualFile = virtualFile, isNew = false)
|
||||
getInstance(this@ModuleImpl.project).incModificationCount()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
constructor(name: String, project: Project, virtualFilePointer: VirtualFilePointer?) : this(name, project) {
|
||||
imlFilePointer = virtualFilePointer
|
||||
@@ -106,10 +82,12 @@ open class ModuleImpl @ApiStatus.Internal constructor(
|
||||
// because there are a lot of modules and no need to measure each one
|
||||
registerComponents()
|
||||
if (!isPersistent) {
|
||||
registerService(IComponentStore::class.java,
|
||||
NonPersistentModuleStore::class.java,
|
||||
fakeCorePluginDescriptor,
|
||||
true)
|
||||
registerService(
|
||||
serviceInterface = IComponentStore::class.java,
|
||||
implementation = NonPersistentModuleStore::class.java,
|
||||
pluginDescriptor = fakeCorePluginDescriptor,
|
||||
override = true,
|
||||
)
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
createComponents()
|
||||
@@ -179,9 +157,7 @@ open class ModuleImpl @ApiStatus.Internal constructor(
|
||||
super.dispose()
|
||||
}
|
||||
|
||||
override fun getContainerDescriptor(pluginDescriptor: IdeaPluginDescriptorImpl): ContainerDescriptor {
|
||||
return pluginDescriptor.moduleContainerDescriptor
|
||||
}
|
||||
override fun getContainerDescriptor(pluginDescriptor: IdeaPluginDescriptorImpl) = pluginDescriptor.moduleContainerDescriptor
|
||||
|
||||
override fun getProject(): Project = project
|
||||
|
||||
@@ -243,7 +219,7 @@ open class ModuleImpl @ApiStatus.Internal constructor(
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return if (name == null) "Module (not initialized)" else "Module: '" + getName() + "'" + if (isDisposed) " (disposed)" else ""
|
||||
return if (name == null) "Module (not initialized)" else "Module: '${getName()}'${if (isDisposed) " (disposed)" else ""}"
|
||||
}
|
||||
|
||||
override fun putInfo(info: MutableMap<in String, in String>) {
|
||||
@@ -251,39 +227,32 @@ open class ModuleImpl @ApiStatus.Internal constructor(
|
||||
info.put("name", getName())
|
||||
}
|
||||
|
||||
override fun debugString(short: Boolean): String {
|
||||
return if (short) {
|
||||
javaClass.simpleName
|
||||
override fun debugString(short: Boolean): String = if (short) javaClass.simpleName else super.debugString(short = false)
|
||||
}
|
||||
|
||||
@State(name = "DeprecatedModuleOptionManager", useLoadedStateAsExisting = false)
|
||||
internal class DeprecatedModuleOptionManager(private val module: Module)
|
||||
: SimpleModificationTracker(), PersistentStateComponent<DeprecatedModuleOptionManager.State?>, ProjectModelElement {
|
||||
override fun getExternalSource(): ProjectModelExternalSource? {
|
||||
if (state.options.size > 1 || state.options.size == 1 && !state.options.containsKey(Module.ELEMENT_TYPE)) {
|
||||
return null
|
||||
}
|
||||
else {
|
||||
super.debugString(short)
|
||||
return ExternalProjectSystemRegistry.getInstance().getExternalSource(module)
|
||||
}
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
@State(name = "DeprecatedModuleOptionManager", useLoadedStateAsExisting = false)
|
||||
class DeprecatedModuleOptionManager internal constructor(private val module: Module)
|
||||
: SimpleModificationTracker(), PersistentStateComponent<DeprecatedModuleOptionManager.State?>, ProjectModelElement {
|
||||
override fun getExternalSource(): ProjectModelExternalSource? {
|
||||
if (state.options.size > 1 || state.options.size == 1 && !state.options.containsKey(Module.ELEMENT_TYPE)) {
|
||||
return null
|
||||
}
|
||||
else {
|
||||
return ExternalProjectSystemRegistry.getInstance().getExternalSource(module)
|
||||
}
|
||||
}
|
||||
class State {
|
||||
@Property(surroundWithTag = false)
|
||||
@MapAnnotation(surroundKeyWithTag = false, surroundValueWithTag = false, surroundWithTag = false, entryTagName = "option")
|
||||
val options: MutableMap<String, String?> = HashMap()
|
||||
}
|
||||
|
||||
class State {
|
||||
@Property(surroundWithTag = false)
|
||||
@MapAnnotation(surroundKeyWithTag = false, surroundValueWithTag = false, surroundWithTag = false, entryTagName = "option")
|
||||
val options: MutableMap<String, String?> = HashMap()
|
||||
}
|
||||
private var state = State()
|
||||
|
||||
private var state = State()
|
||||
override fun getState(): State = state
|
||||
override fun getState(): State = state
|
||||
|
||||
override fun loadState(state: State) {
|
||||
this.state = state
|
||||
}
|
||||
override fun loadState(state: State) {
|
||||
this.state = state
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.module.impl
|
||||
|
||||
import com.intellij.configurationStore.DummyStreamProvider
|
||||
import com.intellij.configurationStore.SaveSessionProducer
|
||||
import com.intellij.configurationStore.StateStorageManager
|
||||
import com.intellij.configurationStore.StreamProvider
|
||||
@@ -58,6 +59,11 @@ private object NonPersistentStateStorageManager : StateStorageManager {
|
||||
override fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage? = null
|
||||
|
||||
override fun expandMacro(collapsedPath: String): Path = Path.of(collapsedPath)
|
||||
|
||||
override fun collapseMacro(path: String): String = path
|
||||
|
||||
override val streamProvider: StreamProvider
|
||||
get() = DummyStreamProvider
|
||||
}
|
||||
|
||||
private object NonPersistentStateStorage : StateStorage {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.workspaceModel.ide.impl.legacyBridge.module
|
||||
|
||||
import com.intellij.configurationStore.RenameableStateStorageManager
|
||||
@@ -12,6 +12,7 @@ import com.intellij.openapi.application.WriteAction
|
||||
import com.intellij.openapi.components.PathMacroManager
|
||||
import com.intellij.openapi.components.impl.ModulePathMacroManager
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.impl.DeprecatedModuleOptionManager
|
||||
import com.intellij.openapi.module.impl.ModuleImpl
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.TestModuleProperties
|
||||
@@ -128,10 +129,12 @@ internal class ModuleBridgeImpl(
|
||||
precomputedExtensionModel: PrecomputedExtensionModel?,
|
||||
app: Application?,
|
||||
listenerCallbacks: MutableList<in Runnable>?) {
|
||||
super.registerComponents(modules = modules,
|
||||
app = app,
|
||||
precomputedExtensionModel = precomputedExtensionModel,
|
||||
listenerCallbacks = listenerCallbacks)
|
||||
super.registerComponents(
|
||||
modules = modules,
|
||||
app = app,
|
||||
precomputedExtensionModel = precomputedExtensionModel,
|
||||
listenerCallbacks = listenerCallbacks,
|
||||
)
|
||||
if (corePlugin == null) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ open class ProjectImpl(parent: ComponentManagerImpl, filePath: Path, projectName
|
||||
: ClientAwareComponentManager(parent), ProjectEx, ProjectStoreOwner {
|
||||
companion object {
|
||||
@Internal
|
||||
@JvmField
|
||||
val RUN_START_UP_ACTIVITIES: Key<Boolean> = Key.create("RUN_START_UP_ACTIVITIES")
|
||||
|
||||
@JvmField
|
||||
@@ -95,16 +96,19 @@ open class ProjectImpl(parent: ComponentManagerImpl, filePath: Path, projectName
|
||||
// ("await" means "project component loading activity is completed only when all such services are completed")
|
||||
internal fun CoroutineScope.schedulePreloadServices(project: ProjectImpl) {
|
||||
launch(CoroutineName("project service preloading (sync)")) {
|
||||
project.preloadServices(modules = PluginManagerCore.getPluginSet().getEnabledModules(),
|
||||
activityPrefix = "project ",
|
||||
syncScope = this,
|
||||
onlyIfAwait = project.isLight,
|
||||
asyncScope = project.asyncPreloadServiceScope)
|
||||
project.preloadServices(
|
||||
modules = PluginManagerCore.getPluginSet().getEnabledModules(),
|
||||
activityPrefix = "project ",
|
||||
syncScope = this,
|
||||
onlyIfAwait = project.isLight,
|
||||
asyncScope = project.asyncPreloadServiceScope,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// used by Rider
|
||||
@Suppress("LeakingThis")
|
||||
@Internal
|
||||
@JvmField
|
||||
val asyncPreloadServiceScope: CoroutineScope = getCoroutineScope().childScope(supervisor = false)
|
||||
@@ -158,14 +162,14 @@ open class ProjectImpl(parent: ComponentManagerImpl, filePath: Path, projectName
|
||||
|
||||
override fun isInitialized(): Boolean {
|
||||
val containerState = containerState.get()
|
||||
if ((containerState < ContainerState.COMPONENT_CREATED || containerState >= ContainerState.DISPOSE_IN_PROGRESS)
|
||||
|| isTemporarilyDisposed
|
||||
|| !isOpen
|
||||
if ((containerState < ContainerState.COMPONENT_CREATED || containerState >= ContainerState.DISPOSE_IN_PROGRESS) ||
|
||||
isTemporarilyDisposed ||
|
||||
!isOpen
|
||||
) {
|
||||
return false
|
||||
}
|
||||
else if (ApplicationManager.getApplication().isUnitTestMode && getUserData(RUN_START_UP_ACTIVITIES) == false) {
|
||||
// if test asks to not run RUN_START_UP_ACTIVITIES, it means "ignore start-up activities", but project considered as initialized
|
||||
// if test asks to not run RUN_START_UP_ACTIVITIES, it means "ignore start-up activities", but the project considered as initialized
|
||||
return true
|
||||
}
|
||||
else {
|
||||
@@ -384,6 +388,7 @@ open class ProjectImpl(parent: ComponentManagerImpl, filePath: Path, projectName
|
||||
}
|
||||
|
||||
runInAutoSaveDisabledMode {
|
||||
@Suppress("DEPRECATION")
|
||||
runUnderModalProgressIfIsEdt {
|
||||
saveSettings(componentManager = this@ProjectImpl)
|
||||
}
|
||||
|
||||
@@ -438,7 +438,7 @@
|
||||
<registryKey defaultValue="true" key="workspace.model.test.properties.bridge" restartRequired="true"
|
||||
description="Provides bridges for TestModuleProperties via WorkspaceModel"/>
|
||||
|
||||
<moduleService serviceImplementation="com.intellij.openapi.module.impl.ModuleImpl$DeprecatedModuleOptionManager"/>
|
||||
<moduleService serviceImplementation="com.intellij.openapi.module.impl.DeprecatedModuleOptionManager"/>
|
||||
<moduleService serviceInterface="com.intellij.openapi.components.PathMacroManager"
|
||||
serviceImplementation="com.intellij.openapi.components.impl.ModulePathMacroManager"/>
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import java.io.InputStream
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Internal
|
||||
interface StreamProvider {
|
||||
/**
|
||||
* Whether it is enabled.
|
||||
@@ -55,4 +55,28 @@ interface StreamProvider {
|
||||
*/
|
||||
fun deleteIfObsolete(fileSpec: String, roamingType: RoamingType) {
|
||||
}
|
||||
|
||||
fun getInstanceOf(aClass: Class<out StreamProvider>): StreamProvider = throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@Internal
|
||||
object DummyStreamProvider : StreamProvider {
|
||||
override val isExclusive: Boolean
|
||||
get() = true
|
||||
|
||||
override fun write(fileSpec: String, content: ByteArray, roamingType: RoamingType) {
|
||||
}
|
||||
|
||||
override fun read(fileSpec: String, roamingType: RoamingType, consumer: (InputStream?) -> Unit): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun processChildren(
|
||||
path: String,
|
||||
roamingType: RoamingType,
|
||||
filter: (name: String) -> Boolean,
|
||||
processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean,
|
||||
): Boolean = true
|
||||
|
||||
override fun delete(fileSpec: String, roamingType: RoamingType): Boolean = true
|
||||
}
|
||||
@@ -27,6 +27,11 @@ interface StateStorageManager {
|
||||
|
||||
fun expandMacro(collapsedPath: String): Path
|
||||
|
||||
fun collapseMacro(path: String): String
|
||||
|
||||
@get:Internal
|
||||
val streamProvider: StreamProvider
|
||||
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
@Deprecated(level = DeprecationLevel.ERROR, message = "Use expandMacro(collapsedPath)", replaceWith = ReplaceWith("expandMacro(collapsedPath)"))
|
||||
fun expandMacros(collapsedPath: String): String = expandMacro(collapsedPath).invariantSeparatorsPathString
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.components.impl.stores;
|
||||
|
||||
import com.intellij.openapi.components.StorageScheme;
|
||||
@@ -43,7 +43,7 @@ public interface IProjectStore extends IComponentStore {
|
||||
boolean isProjectFile(@NotNull VirtualFile file);
|
||||
|
||||
/**
|
||||
* The directory of project configuration files for directory-based project or null for file-based.
|
||||
* The directory of project configuration files for a directory-based project or null for file-based.
|
||||
*/
|
||||
@Nullable Path getDirectoryStorePath();
|
||||
|
||||
|
||||
@@ -155,9 +155,9 @@ abstract class ComponentManagerImpl(
|
||||
}
|
||||
|
||||
private val scopeHolder = ScopeHolder(
|
||||
parentScope,
|
||||
additionalContext + this.asContextElement(),
|
||||
containerName = debugString(true),
|
||||
parentScope = parentScope,
|
||||
additionalContext = additionalContext + this.asContextElement(),
|
||||
containerName = debugString(short = true),
|
||||
)
|
||||
|
||||
open val supportedSignaturesOfLightServiceConstructors: List<MethodType> = java.util.List.of(
|
||||
|
||||
@@ -61,7 +61,7 @@ class JbSettingsImporter(private val configDirPath: Path,
|
||||
// Same applies to the Keymap manager.
|
||||
// So far, it doesn't look like there's a viable way to detect those, so we just hardcode them.
|
||||
suspend fun importOptionsAfterRestart(categories: Set<SettingsCategory>, pluginIds: Set<String>) {
|
||||
val storageManager = componentStore.storageManager as StateStorageManagerImpl
|
||||
val storageManager = componentStore.storageManager
|
||||
val (components, files) = findComponentsAndFiles()
|
||||
withExternalStreamProvider(arrayOf(storageManager)) {
|
||||
val componentManagerImpl = ApplicationManager.getApplication() as ComponentManagerImpl
|
||||
@@ -429,24 +429,6 @@ class JbSettingsImporter(private val configDirPath: Path,
|
||||
CustomConfigMigrationOption.MigrateFromCustomPlace(configDirPath).writeConfigMarkerFile(PathManager.getConfigDir())
|
||||
}
|
||||
|
||||
internal class DummyStreamProvider : StreamProvider {
|
||||
override val isExclusive = true
|
||||
|
||||
override fun write(fileSpec: String, content: ByteArray, roamingType: RoamingType) {}
|
||||
|
||||
override fun read(fileSpec: String, roamingType: RoamingType, consumer: (InputStream?) -> Unit): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun processChildren(path: String,
|
||||
roamingType: RoamingType,
|
||||
filter: (name: String) -> Boolean,
|
||||
processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean) = true
|
||||
|
||||
override fun delete(fileSpec: String, roamingType: RoamingType): Boolean = true
|
||||
|
||||
}
|
||||
|
||||
internal class ImportStreamProvider(private val configDirPath: Path) : StreamProvider {
|
||||
override val isExclusive = false
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.settingsRepository.actions
|
||||
|
||||
import com.intellij.configurationStore.StateStorageManagerImpl
|
||||
import com.intellij.openapi.actionSystem.ActionPlaces
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
@@ -56,7 +55,7 @@ internal class ConfigureIcsAction : DumbAwareAction() {
|
||||
return
|
||||
}
|
||||
|
||||
e.presentation.isEnabledAndVisible = icsManager.isActive || !(application.stateStore.storageManager as StateStorageManagerImpl).compoundStreamProvider.isExclusivelyEnabled
|
||||
e.presentation.isEnabledAndVisible = icsManager.isActive || !(application.stateStore.storageManager).streamProvider.let { it.isExclusive && it.enabled }
|
||||
if (!e.presentation.isEnabledAndVisible && ActionPlaces.MAIN_MENU == e.place) {
|
||||
e.presentation.isVisible = true
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("ReplaceGetOrSet")
|
||||
|
||||
package org.jetbrains.settingsRepository
|
||||
|
||||
import com.intellij.configurationStore.*
|
||||
@@ -8,6 +10,7 @@ import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.openapi.components.stateStore
|
||||
import com.intellij.util.containers.forEachGuaranteed
|
||||
import com.intellij.util.io.directoryStreamIfExists
|
||||
import org.jetbrains.annotations.VisibleForTesting
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.NoSuchFileException
|
||||
import java.nio.file.Path
|
||||
@@ -15,8 +18,9 @@ import kotlin.io.path.invariantSeparatorsPathString
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.readBytes
|
||||
|
||||
fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager.getApplication()!!.stateStore.storageManager as StateStorageManagerImpl) {
|
||||
val streamProvider = storageManager.compoundStreamProvider.getInstanceOf(IcsManager.IcsStreamProvider::class.java) as IcsManager.IcsStreamProvider
|
||||
@VisibleForTesting
|
||||
fun copyLocalConfig(storageManager: StateStorageManager = ApplicationManager.getApplication()!!.stateStore.storageManager) {
|
||||
val streamProvider = storageManager.streamProvider.getInstanceOf(IcsManager.IcsStreamProvider::class.java) as IcsManager.IcsStreamProvider
|
||||
|
||||
val fileToItems = getExportableItemsFromLocalStorage(getExportableComponentsMap(false), storageManager)
|
||||
fileToItems.keys.forEachGuaranteed { file ->
|
||||
@@ -25,7 +29,7 @@ fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager
|
||||
val absolutePath = file.toAbsolutePath().invariantSeparatorsPathString
|
||||
fileSpec = normalizeFileSpec(storageManager, absolutePath)
|
||||
if (fileSpec == absolutePath) {
|
||||
// we have not experienced such problem yet, but we are just aware
|
||||
// we have not experienced such a problem yet, but we are just aware
|
||||
val canonicalPath = file.toRealPath().invariantSeparatorsPathString
|
||||
if (canonicalPath != absolutePath) {
|
||||
fileSpec = normalizeFileSpec(storageManager, absolutePath)
|
||||
@@ -39,15 +43,15 @@ fun copyLocalConfig(storageManager: StateStorageManagerImpl = ApplicationManager
|
||||
val roamingType = fileToItems.get(file)?.firstOrNull()?.roamingType ?: RoamingType.DEFAULT
|
||||
if (file.isRegularFile()) {
|
||||
val fileBytes = file.readBytes()
|
||||
streamProvider.doSave(fileSpec, fileBytes, roamingType)
|
||||
streamProvider.doSave(fileSpec = fileSpec, content = fileBytes, roamingType = roamingType)
|
||||
}
|
||||
else {
|
||||
saveDirectory(file, fileSpec, roamingType, streamProvider)
|
||||
saveDirectory(parent = file, parentFileSpec = fileSpec, roamingType = roamingType, streamProvider = streamProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun normalizeFileSpec(storageManager: StateStorageManagerImpl, absolutePath: String): String {
|
||||
private fun normalizeFileSpec(storageManager: StateStorageManager, absolutePath: String): String {
|
||||
return removeMacroIfStartsWith(removeMacroIfStartsWith(storageManager.collapseMacro(absolutePath), ROOT_CONFIG), APP_CONFIG)
|
||||
}
|
||||
|
||||
@@ -57,10 +61,10 @@ private fun saveDirectory(parent: Path, parentFileSpec: String, roamingType: Roa
|
||||
val childFileSpec = "$parentFileSpec/${file.fileName}"
|
||||
if (file.isRegularFile()) {
|
||||
val fileBytes = Files.readAllBytes(file)
|
||||
streamProvider.doSave(childFileSpec, fileBytes, roamingType)
|
||||
streamProvider.doSave(fileSpec = childFileSpec, content = fileBytes, roamingType = roamingType)
|
||||
}
|
||||
else {
|
||||
saveDirectory(file, childFileSpec, roamingType, streamProvider)
|
||||
saveDirectory(parent = file, parentFileSpec = childFileSpec, roamingType = roamingType, streamProvider = streamProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.intellij.settingsSync.config
|
||||
|
||||
import com.intellij.configurationStore.StateStorageManagerImpl
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.ide.DataManager
|
||||
import com.intellij.ide.plugins.InstalledPluginsState
|
||||
@@ -255,16 +254,16 @@ internal class SettingsSyncConfigurable : BoundConfigurable(message("title.setti
|
||||
|
||||
private fun settingsRepositoryIsEnabled(): Boolean {
|
||||
return !SettingsSyncSettings.getInstance().syncEnabled &&
|
||||
(ApplicationManager.getApplication().stateStore.storageManager as StateStorageManagerImpl).compoundStreamProvider.isExclusivelyEnabled
|
||||
(ApplicationManager.getApplication().stateStore.storageManager).streamProvider.let { it.enabled && it.isExclusive }
|
||||
}
|
||||
|
||||
override fun serverStateCheckFinished(updateResult: UpdateResult) {
|
||||
when (updateResult) {
|
||||
override fun serverStateCheckFinished(state: UpdateResult) {
|
||||
when (state) {
|
||||
NoFileOnServer, FileDeletedFromServer -> showEnableSyncDialog(null)
|
||||
is Success -> showEnableSyncDialog(updateResult.settingsSnapshot.getState())
|
||||
is Success -> showEnableSyncDialog(state.settingsSnapshot.getState())
|
||||
is Error -> {
|
||||
if (updateResult != SettingsSyncEnabler.State.CANCELLED) {
|
||||
showError(message("notification.title.update.error"), updateResult.message)
|
||||
if (state != SettingsSyncEnabler.State.CANCELLED) {
|
||||
showError(message("notification.title.update.error"), state.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user