[AutoSync] Address IJ-CR-160378

- drop builder as it's redundant: all fields are required and don't have default values


(cherry picked from commit 78b99e731fa2332370cc05921b3179136ac166e4)

IJ-CR-160378

GitOrigin-RevId: 0989bb831ab245a555e5a9df15ed97683bc3b09c
This commit is contained in:
Mikhail Shagvaliev
2025-04-16 12:57:41 +02:00
committed by intellij-monorepo-bot
parent fdcab2ec1c
commit 4e07bd57bb
4 changed files with 25 additions and 54 deletions

View File

@@ -15,7 +15,6 @@ import com.intellij.openapi.externalSystem.autoimport.ExternalSystemModification
import com.intellij.openapi.externalSystem.autoimport.ExternalSystemProjectTrackerSettings.AutoReloadType
import com.intellij.openapi.externalSystem.autoimport.ExternalSystemRefreshStatus.SUCCESS
import com.intellij.openapi.externalSystem.autoimport.ProjectStatus.Stamp
import com.intellij.openapi.externalSystem.autoimport.settings.BackgroundAsyncSupplier
import com.intellij.openapi.externalSystem.autoimport.update.PriorityEatUpdate
import com.intellij.openapi.externalSystem.model.ProjectSystemId
import com.intellij.openapi.externalSystem.util.ExternalSystemActivityKey
@@ -26,6 +25,7 @@ import com.intellij.openapi.observable.operation.core.whenOperationStarted
import com.intellij.openapi.observable.properties.*
import com.intellij.openapi.observable.util.set
import com.intellij.openapi.observable.util.whenDisposed
import com.intellij.openapi.progress.impl.CoreProgressManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.registry.Registry
@@ -413,7 +413,8 @@ class AutoImportProjectTracker(
private val asyncChangesProcessingProperty = AtomicBooleanProperty(
!ApplicationManager.getApplication().isHeadlessEnvironment
|| BackgroundAsyncSupplier.isAsyncInHeadless()
|| CoreProgressManager.shouldKeepTasksAsynchronousInHeadlessMode()
|| java.lang.Boolean.getBoolean("external.system.auto.import.headless.async")
)
private val isEnabledAutoReload: Boolean

View File

@@ -18,7 +18,6 @@ import com.intellij.openapi.externalSystem.autoimport.changes.FilesChangesListen
import com.intellij.openapi.externalSystem.autoimport.changes.NewFilesListener.Companion.whenNewFilesCreated
import com.intellij.openapi.externalSystem.autoimport.settings.AsyncSupplier
import com.intellij.openapi.externalSystem.autoimport.settings.BackgroundAsyncSupplier
import com.intellij.openapi.externalSystem.autoimport.settings.tracked
import com.intellij.openapi.externalSystem.service.ui.completion.cache.AsyncLocalCache
import com.intellij.openapi.externalSystem.util.calculateCrc
import com.intellij.openapi.fileEditor.FileDocumentManager
@@ -363,10 +362,12 @@ class ProjectSettingsTracker(
}
}
private val supplier = BackgroundAsyncSupplier.Builder(::getOrCollectSettingsFiles)
.shouldKeepTasksAsynchronous(::isAsyncChangesProcessing)
.build(backgroundExecutor)
.tracked(project)
private val supplier = BackgroundAsyncSupplier(
project,
supplier = AsyncSupplier.blocking(::getOrCollectSettingsFiles),
shouldKeepTasksAsynchronous = ::isAsyncChangesProcessing,
backgroundExecutor = backgroundExecutor,
)
override fun supply(parentDisposable: Disposable, consumer: (Set<String>) -> Unit) {
supplier.supply(parentDisposable) {

View File

@@ -3,63 +3,28 @@ package com.intellij.openapi.externalSystem.autoimport.settings
import com.intellij.openapi.Disposable
import com.intellij.openapi.externalSystem.util.ExternalSystemActivityKey
import com.intellij.openapi.progress.impl.CoreProgressManager
import com.intellij.openapi.progress.util.BackgroundTaskUtil
import com.intellij.openapi.project.Project
import com.intellij.platform.backend.observation.trackActivityBlocking
import com.intellij.util.application
import org.jetbrains.annotations.ApiStatus
import java.util.concurrent.Executor
@ApiStatus.Internal
class BackgroundAsyncSupplier<R>(
private val project: Project,
private val supplier: AsyncSupplier<R>,
private val shouldKeepTasksAsynchronous: () -> Boolean,
private val backgroundExecutor: Executor,
) : AsyncSupplier<R> {
companion object {
fun isAsyncInHeadless(): Boolean {
return CoreProgressManager.shouldKeepTasksAsynchronousInHeadlessMode() ||
java.lang.Boolean.getBoolean("external.system.auto.import.headless.async")
}
}
override fun supply(parentDisposable: Disposable, consumer: (R) -> Unit) {
if (shouldKeepTasksAsynchronous()) {
BackgroundTaskUtil.execute(backgroundExecutor, parentDisposable) {
supplier.supply(parentDisposable, consumer)
project.trackActivityBlocking(ExternalSystemActivityKey) {
if (shouldKeepTasksAsynchronous()) {
BackgroundTaskUtil.execute(backgroundExecutor, parentDisposable) {
supplier.supply(parentDisposable, consumer)
}
}
}
else {
supplier.supply(parentDisposable, consumer)
}
}
class Builder<R>(private val supplier: AsyncSupplier<R>) {
constructor(supplier: () -> R) : this(AsyncSupplier.blocking(supplier))
private var shouldKeepTasksAsynchronous: () -> Boolean = {
val isHeadless = application.isUnitTestMode() || application.isHeadlessEnvironment()
!isHeadless || isAsyncInHeadless()
}
fun shouldKeepTasksAsynchronous(provider: () -> Boolean) = apply {
shouldKeepTasksAsynchronous = provider
}
fun build(backgroundExecutor: Executor): AsyncSupplier<R> {
return BackgroundAsyncSupplier(supplier, shouldKeepTasksAsynchronous, backgroundExecutor)
}
}
}
@ApiStatus.Internal
fun <R> AsyncSupplier<R>.tracked(project: Project): AsyncSupplier<R> {
return object : AsyncSupplier<R> {
override fun supply(parentDisposable: Disposable, consumer: (R) -> Unit) {
project.trackActivityBlocking(ExternalSystemActivityKey) {
this@tracked.supply(parentDisposable, consumer)
else {
supplier.supply(parentDisposable, consumer)
}
}
}

View File

@@ -2,12 +2,13 @@
package org.jetbrains.idea.maven.project.auto.reload
import com.intellij.openapi.Disposable
import com.intellij.openapi.externalSystem.autoimport.AutoImportProjectTracker
import com.intellij.openapi.externalSystem.autoimport.ExternalSystemModificationType
import com.intellij.openapi.externalSystem.autoimport.ProjectStatus.Stamp
import com.intellij.openapi.externalSystem.autoimport.changes.AsyncFileChangesListener.Companion.subscribeOnVirtualFilesChanges
import com.intellij.openapi.externalSystem.autoimport.changes.FilesChangesListener
import com.intellij.openapi.externalSystem.autoimport.settings.AsyncSupplier
import com.intellij.openapi.externalSystem.autoimport.settings.BackgroundAsyncSupplier
import com.intellij.openapi.externalSystem.autoimport.settings.tracked
import com.intellij.openapi.util.io.toCanonicalPath
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.idea.maven.buildtool.MavenSyncSpec
@@ -50,9 +51,12 @@ class MavenGeneralSettingsWatcher(
}
fun subscribeOnSettingsFileChanges(parentDisposable: Disposable) {
val filesProvider = BackgroundAsyncSupplier.Builder(::collectSettingsFiles)
.build(backgroundExecutor)
.tracked(manager.project)
val filesProvider = BackgroundAsyncSupplier(
manager.project,
supplier = AsyncSupplier.blocking(::collectSettingsFiles),
shouldKeepTasksAsynchronous = { AutoImportProjectTracker.isAsyncChangesProcessing },
backgroundExecutor = backgroundExecutor,
)
subscribeOnVirtualFilesChanges(false, filesProvider, object : FilesChangesListener {
override fun onFileChange(stamp: Stamp, path: String, modificationStamp: Long, modificationType: ExternalSystemModificationType) {
val fileChangeMessage = "File change: $path, $modificationStamp, $modificationType"