-
Notifications
You must be signed in to change notification settings - Fork 1
/
UnknownSdkInspectionCommandLineConfigurator.kt
69 lines (54 loc) · 2.88 KB
/
UnknownSdkInspectionCommandLineConfigurator.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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.
package com.intellij.openapi.projectRoots.impl
import com.intellij.ide.CommandLineInspectionProjectConfigurator
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.withPushPop
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectBundle
import com.intellij.openapi.util.registry.Registry
import org.jetbrains.annotations.NotNull
class UnknownSdkInspectionCommandLineConfigurator : CommandLineInspectionProjectConfigurator {
companion object {
private val LOG: Logger = logger<UnknownSdkInspectionCommandLineConfigurator>()
fun configureUnknownSdks(project: Project, indicator: ProgressIndicator) {
require(!ApplicationManager.getApplication().isWriteThread) {
"The code below uses the same GUI thread to complete operations. Running from EDT would deadlock"
}
ApplicationManager.getApplication().assertIsNonDispatchThread()
indicator.withPushPop {
indicator.text = ProjectBundle.message("config.unknown.progress.scanning")
val problems = UnknownSdkTracker
.getInstance(project)
.collectUnknownSdks(UnknownSdkCollector(project), indicator)
if (problems.isEmpty()) return@withPushPop
indicator.isIndeterminate = false
for ((i, problem) in problems.withIndex()) {
val fix = problem.suggestedFixAction
if (fix == null) {
LOG.warn("Failed to resolve ${problem.sdkTypeAndNameText}: ${problem.notificationText}")
continue
}
LOG.info("Resolving ${problem.sdkTypeAndNameText}")
indicator.withPushPop {
indicator.fraction = i.toDouble() / problems.size
indicator.text = ProjectBundle.message("config.unknown.progress.configuring", problem.sdkTypeAndNameText)
fix.applySuggestionBlocking(indicator)
}
}
}
}
}
override fun getName() = "sdk"
override fun getDescription(): String = ProjectBundle.message("config.unknown.sdk.commandline.configure")
override fun isApplicable(context: CommandLineInspectionProjectConfigurator.ConfiguratorContext): Boolean =
!ApplicationManager.getApplication().isUnitTestMode
override fun configureEnvironment(context: CommandLineInspectionProjectConfigurator.ConfiguratorContext) {
Registry.get("unknown.sdk.auto").setValue(false) // forbid UnknownSdkTracker post startup activity as we run it here
}
override fun configureProject(project: Project, context: CommandLineInspectionProjectConfigurator.ConfiguratorContext) {
configureUnknownSdks(project, context.progressIndicator)
}
}