diff --git a/platform/execution-impl/src/com/intellij/execution/impl/RCInArbitraryFileListener.kt b/platform/execution-impl/src/com/intellij/execution/impl/RCInArbitraryFileListener.kt index 0f57b46157ba..42b88ef7864e 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/RCInArbitraryFileListener.kt +++ b/platform/execution-impl/src/com/intellij/execution/impl/RCInArbitraryFileListener.kt @@ -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): @org.jetbrains.annotations.Nullable com.intellij.openapi.vfs.AsyncFileListener.ChangeApplier? { + override fun prepareChange(events: List): @org.jetbrains.annotations.Nullable AsyncFileListener.ChangeApplier? { val deletedRCFilePaths = mutableSetOf() val updatedRCFilePaths = mutableSetOf() @@ -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) } diff --git a/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurationInArbitraryFileScanner.kt b/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurationInArbitraryFileScanner.kt index 98c3f83b8504..d6ab4c661ae8 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurationInArbitraryFileScanner.kt +++ b/platform/execution-impl/src/com/intellij/execution/impl/RunConfigurationInArbitraryFileScanner.kt @@ -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 + } } } -} \ No newline at end of file +} + +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 +}