[warmup] IJPL-29: Remove logger as a parameter of warm-up functions

GitOrigin-RevId: 800519edf6296100bae2944719e4662579c73796
This commit is contained in:
Konstantin Nisht
2022-12-28 15:30:36 +03:00
committed by intellij-monorepo-bot
parent d57c774ffe
commit d24fa4a039
13 changed files with 27 additions and 44 deletions

View File

@@ -16,7 +16,7 @@ import java.nio.file.Path
interface WarmupConfigurator {
companion object {
val EP_NAME: ExtensionPointName<WarmupConfigurator> = ExtensionPointName("com.intellij.warmupConfiguration")
val EP_NAME: ExtensionPointName<WarmupConfigurator> = ExtensionPointName("com.intellij.warmupConfigurator")
}
/**
@@ -29,11 +29,11 @@ interface WarmupConfigurator {
* Called **before** opening the project.
*
* This method helps to configure the behavior of some startup activities,
* i.e. disable auto import of build systems or specify the needed system properties.
* i.e. specifying the needed system properties.
*
* @param projectPath a path to the directory passed to warm-up process.
*/
suspend fun prepareEnvironment(projectPath: Path, logger: WarmupEventsLogger) {}
suspend fun prepareEnvironment(projectPath: Path) {}
/**
* Called **after** opening the project.
@@ -43,5 +43,5 @@ interface WarmupConfigurator {
* @return `true` if some globally visible changes to the project have been performed
* or `false` otherwise
*/
suspend fun runWarmup(project: Project, logger: WarmupEventsLogger): Boolean
suspend fun runWarmup(project: Project): Boolean
}

View File

@@ -1,12 +0,0 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.warmup
import com.intellij.openapi.util.NlsSafe
/**
* Helps to pass diagnostic messages to the user of warm-up.
*/
interface WarmupEventsLogger {
fun logError(message: @NlsSafe String)
fun logMessage(verbosityLevel: Int, message: @NlsSafe String)
}

View File

@@ -60,7 +60,7 @@
<postStartupActivity implementation="com.intellij.openapi.projectRoots.impl.UnknownSdkStartupChecker"/>
<commandLineInspectionProjectConfigurator implementation="com.intellij.openapi.projectRoots.impl.UnknownSdkInspectionCommandLineConfigurator"/>
<warmupConfigurator implementation="com.intellij.openapi.projectRoots.impl.UnknownSdkInspectionWarmupConfigurator"/>
<warmupConfigurator implementation="com.intellij.warmup.impl.UnknownSdkInspectionWarmupConfigurator"/>
<registryKey key="unknown.sdk" defaultValue="true" description="Check for unknown SDKs and provide automatic fixes or smart suggestions"/>
<registryKey key="unknown.sdk.auto" defaultValue="true" description="Checks and resolves unknown SDKs automatically on start"/>
<registryKey key="unknown.sdk.modal.jps" defaultValue="true" description="Run unknown JDK test before JPS build is started"/>

View File

@@ -12,7 +12,6 @@
<orderEntry type="module" module-name="intellij.platform.indexing" />
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
<orderEntry type="module" module-name="intellij.platform.ide" />
<orderEntry type="module" module-name="intellij.platform.core.impl" />
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
</component>

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.projectRoots.impl
package com.intellij.warmup.impl
import com.intellij.ide.warmup.WarmupConfiguratorOfCLIConfigurator
import com.intellij.openapi.projectRoots.impl.UnknownSdkInspectionCommandLineConfigurator
class UnknownSdkInspectionWarmupConfigurator : WarmupConfiguratorOfCLIConfigurator(UnknownSdkInspectionCommandLineConfigurator())

View File

@@ -1,14 +1,16 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.warmup
package com.intellij.warmup.impl
import com.intellij.ide.CommandLineInspectionProgressReporter
import com.intellij.ide.CommandLineInspectionProjectConfigurator
import com.intellij.ide.warmup.WarmupConfigurator
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.warmup.util.ConsoleLog
import org.jetbrains.annotations.ApiStatus
import java.nio.file.Path
import java.util.function.Predicate
@@ -22,17 +24,17 @@ import kotlin.coroutines.coroutineContext
@ApiStatus.Obsolete
abstract class WarmupConfiguratorOfCLIConfigurator(val delegate: CommandLineInspectionProjectConfigurator) : WarmupConfigurator {
override suspend fun prepareEnvironment(projectPath: Path, logger: WarmupEventsLogger) =
override suspend fun prepareEnvironment(projectPath: Path) =
withRawProgressReporter {
val context = produceConfigurationContext(projectPath, logger)
val context = produceConfigurationContext(projectPath)
blockingContext {
delegate.configureEnvironment(context)
}
}
override suspend fun runWarmup(project: Project, logger: WarmupEventsLogger): Boolean =
override suspend fun runWarmup(project: Project): Boolean =
withRawProgressReporter {
val context = produceConfigurationContext(project.guessProjectDir()?.path?.let(Path::of), logger)
val context = produceConfigurationContext(project.guessProjectDir()?.path?.let(Path::of))
blockingContext {
delegate.configureProject(project, context)
false
@@ -42,8 +44,7 @@ abstract class WarmupConfiguratorOfCLIConfigurator(val delegate: CommandLineInsp
override val name: String
get() = delegate.name
private suspend fun produceConfigurationContext(projectDir: Path?,
logger: WarmupEventsLogger): CommandLineInspectionProjectConfigurator.ConfiguratorContext {
private suspend fun produceConfigurationContext(projectDir: Path?): CommandLineInspectionProjectConfigurator.ConfiguratorContext {
val reporter = coroutineContext.rawProgressReporter
if (reporter == null) {
LOG.warn("No ProgressReporter installed to the coroutine context. Message reporting is disabled")
@@ -51,9 +52,9 @@ abstract class WarmupConfiguratorOfCLIConfigurator(val delegate: CommandLineInsp
return object : CommandLineInspectionProjectConfigurator.ConfiguratorContext {
override fun getLogger(): CommandLineInspectionProgressReporter = object : CommandLineInspectionProgressReporter {
override fun reportError(message: String?) = message?.let(logger::logError) ?: Unit
override fun reportError(message: String?) = message?.let { ConsoleLog.warn("PROGRESS: $it") } ?: Unit
override fun reportMessage(minVerboseLevel: Int, message: String?) = message?.let { logger.logMessage(minVerboseLevel, it) } ?: Unit
override fun reportMessage(minVerboseLevel: Int, message: String?) = message?.let { ConsoleLog.info("PROGRESS: $it") } ?: Unit
}
/**

View File

@@ -8,7 +8,6 @@ import com.intellij.ide.impl.PatchProjectUtil
import com.intellij.ide.impl.ProjectUtil
import com.intellij.ide.impl.runUnderModalProgressIfIsEdt
import com.intellij.ide.warmup.WarmupConfigurator
import com.intellij.ide.warmup.WarmupEventsLogger
import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.readAction
import com.intellij.openapi.progress.ProgressIndicator
@@ -57,7 +56,7 @@ private suspend fun importOrOpenProjectImpl(args: OpenProjectArgs): Project {
callProjectConversion(args)
callProjectConfigurators(args) {
this.prepareEnvironment(args.projectDir, listener)
this.prepareEnvironment(args.projectDir)
}
val project = runTaskAndLogTime("open project") {
@@ -75,7 +74,7 @@ private suspend fun importOrOpenProjectImpl(args: OpenProjectArgs): Project {
yieldAndWaitForDumbModeEnd(project)
callProjectConfigurators(args) {
this.runWarmup(project, listener)
this.runWarmup(project)
//the configuration may add more dumb tasks to complete
//we flush the queue to avoid a deadlock between a modal progress & invokeLater
@@ -115,14 +114,7 @@ private suspend fun importOrOpenProjectImpl(args: OpenProjectArgs): Project {
return project
}
private val listener = object : ConversionListener, WarmupEventsLogger {
override fun logError(message: String) {
LOG.warn("PROGRESS: $message")
}
override fun logMessage(verbosityLevel: Int, message: String) {
LOG.info("PROGRESS: $message")
}
private val listener = object : ConversionListener {
override fun error(message: String) {
LOG.warn("PROGRESS: $message")
@@ -174,7 +166,7 @@ private suspend fun callProjectConfigurators(
val activeConfigurators = WarmupConfigurator.EP_NAME.extensionList.filter {
if (it.name in projectArgs.disabledConfigurators) {
listener.logMessage(1, "Configurator ${it.name} is disabled in the settings")
ConsoleLog.info("Configurator ${it.name} is disabled in the settings")
false
} else {
true

View File

@@ -43,5 +43,6 @@
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.platform.diagnostic.telemetry" />
<orderEntry type="library" name="opentelemetry" level="project" />
<orderEntry type="module" module-name="intellij.platform.warmup" />
</component>
</module>

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.gradle
import com.intellij.ide.warmup.WarmupConfiguratorOfCLIConfigurator
import com.intellij.warmup.impl.WarmupConfiguratorOfCLIConfigurator
class GradleWarmupConfigurator : WarmupConfiguratorOfCLIConfigurator(GradleCommandLineProjectConfigurator())

View File

@@ -78,6 +78,7 @@
<orderEntry type="module" module-name="intellij.platform.buildScripts.downloader" />
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
<orderEntry type="module" module-name="intellij.platform.ide.core" />
<orderEntry type="module" module-name="intellij.platform.warmup" />
</component>
<component name="copyright">
<Base>

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.maven
import com.intellij.ide.warmup.WarmupConfiguratorOfCLIConfigurator
import com.intellij.warmup.impl.WarmupConfiguratorOfCLIConfigurator
class MavenWarmupConfigurator : WarmupConfiguratorOfCLIConfigurator(MavenCommandLineInspectionProjectConfigurator())

View File

@@ -1,6 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.inspections
import com.intellij.ide.warmup.WarmupConfiguratorOfCLIConfigurator
import com.intellij.warmup.impl.WarmupConfiguratorOfCLIConfigurator
class PythonPluginWarmupConfigurator : WarmupConfiguratorOfCLIConfigurator(PythonPluginCommandLineInspectionProjectConfigurator())

View File

@@ -21,5 +21,6 @@
<orderEntry type="module" module-name="intellij.platform.core.ui" />
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
<orderEntry type="module" module-name="intellij.python.community.core.impl" />
<orderEntry type="module" module-name="intellij.platform.warmup" />
</component>
</module>