avoid getting run manager without a reason

GitOrigin-RevId: e9319ab56cd67ba125ec827b70b09189fe950c49
This commit is contained in:
Vladimir Krivosheev
2023-07-07 02:59:30 +00:00
committed by intellij-monorepo-bot
parent 515b712bef
commit ed00a296d5
2 changed files with 31 additions and 30 deletions
@@ -1,13 +1,16 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.impl
import com.intellij.openapi.project.getOpenedProjects
import com.intellij.openapi.vfs.AsyncFileListener
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.newvfs.events.*
import com.intellij.util.PathUtil
private fun isFileWithRunConfigs(path: String) = !path.contains("/.idea/") && PathUtil.getFileName(path).endsWith(".run.xml")
private class RCInArbitraryFileListener : AsyncFileListener {
override fun prepareChange(events: List<VFileEvent>): @org.jetbrains.annotations.Nullable com.intellij.openapi.vfs.AsyncFileListener.ChangeApplier? {
override fun prepareChange(events: List<VFileEvent>): @org.jetbrains.annotations.Nullable AsyncFileListener.ChangeApplier? {
val deletedRCFilePaths = mutableSetOf<String>()
val updatedRCFilePaths = mutableSetOf<String>()
@@ -17,39 +20,39 @@ private class RCInArbitraryFileListener : AsyncFileListener {
}
if (event is VFileContentChangeEvent || event is VFileCreateEvent) {
if (RunConfigurationInArbitraryFileScanner.isFileWithRunConfigs(event.path)) {
if (isFileWithRunConfigs(event.path)) {
updatedRCFilePaths.add(event.path)
deletedRCFilePaths.remove(event.path)
}
}
else if (event is VFileCopyEvent) {
if (RunConfigurationInArbitraryFileScanner.isFileWithRunConfigs(event.newParent.path + "/" + event.newChildName)) {
if (isFileWithRunConfigs(event.newParent.path + "/" + event.newChildName)) {
updatedRCFilePaths.add(event.path)
deletedRCFilePaths.remove(event.path)
}
}
else if (event is VFileDeleteEvent) {
if (RunConfigurationInArbitraryFileScanner.isFileWithRunConfigs(event.path)) {
if (isFileWithRunConfigs(event.path)) {
updatedRCFilePaths.remove(event.path)
deletedRCFilePaths.add(event.path)
}
}
else if (event is VFileMoveEvent) {
if (RunConfigurationInArbitraryFileScanner.isFileWithRunConfigs(event.oldPath)) {
if (isFileWithRunConfigs(event.oldPath)) {
updatedRCFilePaths.remove(event.oldPath)
deletedRCFilePaths.add(event.oldPath)
}
if (RunConfigurationInArbitraryFileScanner.isFileWithRunConfigs(event.newPath)) {
if (isFileWithRunConfigs(event.newPath)) {
updatedRCFilePaths.add(event.newPath)
deletedRCFilePaths.remove(event.newPath)
}
}
else if (event is VFilePropertyChangeEvent && event.isRename) {
if (RunConfigurationInArbitraryFileScanner.isFileWithRunConfigs(event.oldPath)) {
if (isFileWithRunConfigs(event.oldPath)) {
updatedRCFilePaths.remove(event.oldPath)
deletedRCFilePaths.add(event.oldPath)
}
if (RunConfigurationInArbitraryFileScanner.isFileWithRunConfigs(event.newPath)) {
if (isFileWithRunConfigs(event.newPath)) {
updatedRCFilePaths.add(event.newPath)
deletedRCFilePaths.remove(event.newPath)
}
@@ -4,7 +4,6 @@ package com.intellij.execution.impl
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.PathUtil
import com.intellij.util.indexing.roots.IndexableFileScanner
import com.intellij.util.indexing.roots.kind.ContentOrigin
import com.intellij.util.indexing.roots.kind.ProjectFileOrDirOrigin
@@ -13,31 +12,30 @@ import com.intellij.util.indexing.roots.kind.ProjectFileOrDirOrigin
* This class doesn't push any file properties, it is used for scanning the project for `*.run.xml` files - files with run configurations.
* This is to handle run configurations stored in arbitrary files within project content (not in .idea/runConfigurations or project.ipr file).
*/
internal class RunConfigurationInArbitraryFileScanner : IndexableFileScanner {
companion object {
fun isFileWithRunConfigs(file: VirtualFile): Boolean {
if (!file.isInLocalFileSystem || !StringUtil.endsWith(file.nameSequence, ".run.xml")) return false
var parent = file.parent
while (parent != null) {
if (StringUtil.equals(parent.nameSequence, ".idea")) return false
parent = parent.parent
}
return true
}
fun isFileWithRunConfigs(path: String) = !path.contains("/.idea/") && PathUtil.getFileName(path).endsWith(".run.xml")
}
private class RunConfigurationInArbitraryFileScanner : IndexableFileScanner {
override fun startSession(project: Project): IndexableFileScanner.ScanSession {
val runManagerImpl = RunManagerImpl.getInstanceImpl(project)
val runManager by lazy(LazyThreadSafetyMode.NONE) { RunManagerImpl.getInstanceImpl(project) }
return IndexableFileScanner.ScanSession {
if (it is ContentOrigin || it is ProjectFileOrDirOrigin)
if (it is ContentOrigin || it is ProjectFileOrDirOrigin) {
IndexableFileScanner.IndexableFileVisitor { fileOrDir ->
if (isFileWithRunConfigs(fileOrDir)) {
runManagerImpl.updateRunConfigsFromArbitraryFiles(emptyList(), listOf(fileOrDir.path))
runManager.updateRunConfigsFromArbitraryFiles(emptyList(), listOf(fileOrDir.path))
}
}
else null
}
else {
null
}
}
}
}
}
private fun isFileWithRunConfigs(file: VirtualFile): Boolean {
if (!file.isInLocalFileSystem || !file.nameSequence.endsWith(".run.xml")) return false
var parent = file.parent
while (parent != null) {
if (StringUtil.equals(parent.nameSequence, ".idea")) return false
parent = parent.parent
}
return true
}