Skip to content

Commit bcf7333

Browse files
author
Mathieu
committed
πŸ‘¨β€πŸ’» update all deprecated code
1 parent fb1c0ee commit bcf7333

File tree

10 files changed

+55
-73
lines changed

10 files changed

+55
-73
lines changed

β€Žsrc/main/kotlin/debugattach/MayaAttachDebuggerProvider.ktβ€Ž

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package debugattach
22

3-
import settings.ApplicationSettings
4-
import utils.pathForPid
53
import com.intellij.execution.process.ProcessInfo
64
import com.intellij.openapi.project.Project
75
import com.intellij.openapi.projectRoots.Sdk
@@ -10,7 +8,8 @@ import com.intellij.openapi.util.Key
108
import com.intellij.openapi.util.UserDataHolder
119
import com.intellij.xdebugger.attach.*
1210
import com.jetbrains.python.sdk.PythonSdkType
13-
import com.jetbrains.python.sdk.PythonSdkUtil
11+
import settings.ApplicationSettings
12+
import utils.pathForPid
1413
import javax.swing.Icon
1514

1615
private val mayaPathsKey = Key<MutableMap<Int, String>>("mayaPathsMap")
@@ -21,31 +20,32 @@ class MayaAttachDebuggerProvider : XAttachDebuggerProvider {
2120
}
2221

2322
override fun getAvailableDebuggers(project: Project, attachHost: XAttachHost, processInfo: ProcessInfo, userData: UserDataHolder): MutableList<XAttachDebugger> {
24-
if (!processInfo.executableName.toLowerCase().contains("maya")) return mutableListOf()
23+
if (!processInfo.executableName.lowercase().contains("maya")) return mutableListOf()
2524

2625
val exePath = processInfo.executableCannonicalPath.let {
2726
if (it.isPresent) it.get() else pathForPid(processInfo.pid) ?: return mutableListOf()
28-
}.toLowerCase()
27+
}.lowercase()
2928

3029
val currentSdk = ApplicationSettings.INSTANCE.mayaSdkMapping.values.firstOrNull {
31-
exePath.contains(it.mayaPath.toLowerCase())
30+
exePath.contains(it.mayaPath.lowercase())
3231
} ?: return mutableListOf()
3332

3433
val mayaPathMap = userData.getUserData(mayaPathsKey) ?: mutableMapOf()
3534
mayaPathMap[processInfo.pid] = currentSdk.mayaPath
3635
userData.putUserData(mayaPathsKey, mayaPathMap)
3736

38-
PythonSdkUtil.findSdkByPath(currentSdk.mayaPyPath)?.let {
39-
return mutableListOf(MayaAttachDebugger(it, currentSdk))
37+
val sdk = currentSdk.sdk
38+
if (sdk != null) {
39+
return mutableListOf(MayaAttachDebugger(sdk, currentSdk))
4040
}
41-
4241
return mutableListOf()
4342
}
4443

4544
override fun isAttachHostApplicable(attachHost: XAttachHost): Boolean = attachHost is LocalAttachHost
4645
}
4746

4847
private class MayaAttachDebugger(sdk: Sdk, private val mayaSdk: ApplicationSettings.SdkInfo) : XAttachDebugger {
48+
private val mySdk: Sdk = sdk
4949
private val mySdkHome: String? = sdk.homePath
5050
private val myName: String = "${PythonSdkType.getInstance().getVersionString(sdk)} ($mySdkHome)"
5151

@@ -54,7 +54,7 @@ private class MayaAttachDebugger(sdk: Sdk, private val mayaSdk: ApplicationSetti
5454
}
5555

5656
override fun attachDebugSession(project: Project, attachHost: XAttachHost, processInfo: ProcessInfo) {
57-
val runner = MayaAttachToProcessDebugRunner(project, processInfo.pid, mySdkHome, mayaSdk)
57+
val runner = MayaAttachToProcessDebugRunner(project, processInfo.pid, mySdk, mayaSdk)
5858
runner.launch()
5959
}
6060
}
@@ -69,18 +69,10 @@ private class MayaAttachGroup : XAttachProcessPresentationGroup {
6969
return mayaPaths[processInfo.pid] ?: processInfo.executableDisplayName
7070
}
7171

72-
override fun getProcessDisplayText(project: Project, info: ProcessInfo, userData: UserDataHolder): String {
73-
return getItemDisplayText(project, info, userData)
74-
}
75-
7672
override fun getItemIcon(project: Project, processInfo: ProcessInfo, userData: UserDataHolder): Icon {
7773
return IconLoader.getIcon("/icons/MayaCharm_ToolWindow.png", this::class.java)
7874
}
7975

80-
override fun getProcessIcon(project: Project, info: ProcessInfo, userData: UserDataHolder): Icon {
81-
return getItemIcon(project, info, userData)
82-
}
83-
8476
override fun getGroupName(): String {
8577
return "Maya"
8678
}

β€Žsrc/main/kotlin/debugattach/MayaAttachToProcessCliState.ktβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.execution.process.ProcessHandler
66
import com.intellij.execution.runners.ExecutionEnvironment
77
import com.intellij.execution.runners.ExecutionEnvironmentBuilder
88
import com.intellij.openapi.project.Project
9+
import com.intellij.openapi.projectRoots.Sdk
910
import com.jetbrains.python.PythonHelper
1011
import com.jetbrains.python.debugger.attach.PyAttachToProcessCommandLineState
1112
import com.jetbrains.python.run.PythonConfigurationType
@@ -19,7 +20,7 @@ import java.nio.file.Paths
1920
class MayaAttachToProcessCliState(runConfig: PythonRunConfiguration, env: ExecutionEnvironment) :
2021
PythonScriptCommandLineState(runConfig, env) {
2122
companion object {
22-
fun create(project: Project, sdkPath: String, port: Int, pid: Int, mayaSdk: ApplicationSettings.SdkInfo): MayaAttachToProcessCliState {
23+
fun create(project: Project, sdk: Sdk, port: Int, pid: Int, mayaSdk: ApplicationSettings.SdkInfo): MayaAttachToProcessCliState {
2324
val conf =
2425
PythonConfigurationType.getInstance().factory.createTemplateConfiguration(project) as PythonRunConfiguration
2526
val env = ExecutionEnvironmentBuilder.create(project, DefaultDebugExecutor.getDebugExecutorInstance(), conf)
@@ -32,7 +33,7 @@ class MayaAttachToProcessCliState(runConfig: PythonRunConfiguration, env: Execut
3233
PythonEnvUtil.addToPythonPath(conf.envs, listOf(env.project.basePath))
3334

3435
conf.workingDirectory = env.project.basePath
35-
conf.sdkHome = sdkPath
36+
conf.sdkHome = sdk.homePath
3637
conf.isUseModuleSdk = false
3738
conf.scriptName = Paths.get(projectSettings.pythonCachePath.toString(), "attach_pydevd.py").toString()
3839
conf.scriptParameters = "--port $port --pid $pid --mcPort $mcPort --pydevPath \"$debuggerPath\""

β€Žsrc/main/kotlin/debugattach/MayaAttachToProcessDebugRunner.ktβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package debugattach
33
import MayaBundle as Loc
44
import com.intellij.openapi.fileEditor.FileDocumentManager
55
import com.intellij.openapi.project.Project
6+
import com.intellij.openapi.projectRoots.Sdk
67
import com.intellij.openapi.ui.Messages
78
import com.intellij.openapi.util.IconLoader
89
import com.intellij.xdebugger.XDebugProcess
@@ -20,9 +21,9 @@ import java.net.ServerSocket
2021
class MayaAttachToProcessDebugRunner(
2122
private val project: Project,
2223
private val pid: Int,
23-
private val sdkPath: String?,
24+
private val sdk: Sdk?,
2425
private val mayaSdk: ApplicationSettings.SdkInfo
25-
) : PyAttachToProcessDebugRunner(project, pid, sdkPath) {
26+
) : PyAttachToProcessDebugRunner(project, pid, sdk) {
2627

2728
override fun launch(): XDebugSession? {
2829
FileDocumentManager.getInstance().saveAllDocuments()
@@ -46,7 +47,7 @@ class MayaAttachToProcessDebugRunner(
4647

4748
private fun launchRemoteDebugServer(): XDebugSession? {
4849
val serverSocket = getDebuggerSocket() ?: return null
49-
val state = MayaAttachToProcessCliState.create(project, sdkPath!!, serverSocket.localPort, pid, mayaSdk)
50+
val state = MayaAttachToProcessCliState.create(project, sdk!!, serverSocket.localPort, pid, mayaSdk)
5051
val result = state.execute(state.environment.executor, this)
5152

5253
val icon = IconLoader.getIcon("/icons/MayaCharm_ToolWindow.png", this::class.java)
Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,26 @@
11
package flavors
22

3-
import com.intellij.openapi.projectRoots.Sdk
43
import com.intellij.openapi.util.io.FileUtil
54
import com.intellij.openapi.vfs.VirtualFile
6-
import com.jetbrains.python.psi.LanguageLevel
5+
import com.jetbrains.python.sdk.flavors.PyFlavorData
76
import com.jetbrains.python.sdk.flavors.PythonFlavorProvider
87
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor
9-
import icons.PythonIcons
8+
import com.jetbrains.python.psi.icons.PythonPsiApiIcons
109
import java.io.File
1110
import javax.swing.Icon
1211

13-
class MayaSdkFlavor private constructor() : PythonSdkFlavor() {
14-
override fun isValidSdkHome(path: String): Boolean {
15-
val file = File(path)
16-
return file.isFile && isValidSdkPath(file) || isMayaFolder(file)
17-
}
18-
19-
override fun isValidSdkPath(file: File): Boolean {
20-
val name = FileUtil.getNameWithoutExtension(file).toLowerCase()
21-
return name.startsWith("mayapy")
22-
}
23-
24-
override fun getVersionOption(): String {
25-
return "--version"
26-
}
27-
28-
override fun getLanguageLevelFromVersionString(version: String?): LanguageLevel {
29-
if (version != null && version.startsWith(verStringPrefix)) {
30-
return LanguageLevel.fromPythonVersion(version.substring(verStringPrefix.length))
31-
?: LanguageLevel.getDefault()
32-
}
33-
return LanguageLevel.getDefault()
34-
}
35-
36-
override fun getLanguageLevel(sdk: Sdk): LanguageLevel {
37-
return getLanguageLevelFromVersionString(sdk.versionString)
38-
}
39-
40-
override fun getLanguageLevel(sdkHome: String): LanguageLevel {
41-
val version = getVersionString(sdkHome)
42-
return getLanguageLevelFromVersionString(version)
12+
class MayaSdkFlavor private constructor() : PythonSdkFlavor<PyFlavorData.Empty>() {
13+
override fun isValidSdkPath(pathStr: String): Boolean {
14+
val name = FileUtil.getNameWithoutExtension(pathStr).lowercase()
15+
return name.startsWith("mayapy") || isMayaFolder(File(pathStr))
4316
}
4417

4518
override fun getName(): String {
4619
return "Maya Python"
4720
}
4821

4922
override fun getIcon(): Icon {
50-
return PythonIcons.Python.Python
23+
return PythonPsiApiIcons.Python
5124
}
5225

5326
override fun getSdkPath(path: VirtualFile): VirtualFile? {
@@ -69,5 +42,5 @@ class MayaSdkFlavor private constructor() : PythonSdkFlavor() {
6942
}
7043

7144
class MayaFlavorProvider : PythonFlavorProvider {
72-
override fun getFlavor(platformIndependent: Boolean): PythonSdkFlavor = MayaSdkFlavor.INSTANCE
45+
override fun getFlavor(platformIndependent: Boolean): PythonSdkFlavor<PyFlavorData.Empty> = MayaSdkFlavor.INSTANCE
7346
}

β€Žsrc/main/kotlin/logconsole/LogWindow.ktβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LogWindow : ToolWindowFactory, DumbAware {
1717
val port = ProjectSettings.getInstance(project).selectedSdk?.port ?: 4434
1818

1919
val contentManager = toolWindow.contentManager
20-
val contentFactory = ContentFactory.SERVICE.getInstance()
20+
val contentFactory = ContentFactory.getInstance()
2121
val mayaLogPath = PathManager.getPluginTempPath() + String.format(LOG_FILENAME_STRING, port)
2222

2323
val console = LogConsole(

β€Žsrc/main/kotlin/mayacomms/MayaCommandInterface.ktβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import resources.PythonStrings
55
import com.intellij.notification.Notifications
66
import com.intellij.openapi.application.PathManager
77
import com.intellij.util.io.createDirectories
8-
import com.intellij.util.io.exists
8+
import kotlin.io.path.exists
99
import java.io.*
1010
import java.net.Socket
1111
import java.nio.file.Paths

β€Žsrc/main/kotlin/mayacomms/MayaFunctions.ktβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package mayacomms
22

33
import com.intellij.openapi.util.SystemInfo
4-
import com.intellij.util.io.exists
4+
import kotlin.io.path.exists
55
import java.nio.file.Paths
66

77
private const val mayaExecutableNameWin = "maya.exe"

β€Žsrc/main/kotlin/run/MayaCharmDebugRunner.ktβ€Ž

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.intellij.xdebugger.XDebugSession
1414
import com.intellij.xdebugger.XDebuggerManager
1515
import com.jetbrains.python.debugger.PyDebugRunner
1616
import com.jetbrains.python.debugger.PyLocalPositionConverter
17-
import com.jetbrains.python.sdk.PythonSdkUtil
1817
import debugattach.MayaAttachToProcessCliState
1918
import java.net.ServerSocket
2019

@@ -46,15 +45,15 @@ class MayaCharmDebugRunner : PyDebugRunner() {
4645
return
4746
}
4847

49-
val sdk = PythonSdkUtil.findSdkByPath(sdkInfo.mayaPyPath)
48+
val sdk = sdkInfo.sdk
5049
if (sdk == null) {
5150
MayaNotifications.mayaInstanceNotFound(sdkInfo.mayaPath, environment.project)
5251
return
5352
}
5453

5554
val serverSocket = ServerSocket(0) // port 0 forces the ServerSocket to choose its own free port
5655
val cliState =
57-
MayaAttachToProcessCliState.create(environment.project, sdk.homePath!!, serverSocket.localPort, process.pid, sdkInfo)
56+
MayaAttachToProcessCliState.create(environment.project, sdk, serverSocket.localPort, process.pid, sdkInfo)
5857
val executionResult = cliState.execute(environment.executor, this)
5958

6059
XDebuggerManager.getInstance(environment.project).startSession(environment, object : XDebugProcessStarter() {

β€Žsrc/main/kotlin/settings/ApplicationSettings.ktβ€Ž

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import mayacomms.mayaFromMayaPy
44
import mayacomms.mayaPyExecutableName
55

66
import com.intellij.openapi.components.*
7+
import com.intellij.openapi.projectRoots.Sdk
78
import com.jetbrains.python.sdk.PythonSdkUtil
89
import java.util.*
910

@@ -19,6 +20,9 @@ class ApplicationSettings : PersistentStateComponent<ApplicationSettings.State>
1920
data class SdkInfo(var mayaPyPath: String = "", var port: Int = -1) {
2021
val mayaPath: String
2122
get() = mayaFromMayaPy(mayaPyPath) ?: ""
23+
24+
val sdk: Sdk?
25+
get() = INSTANCE.findByPath(mayaPyPath)
2226
}
2327

2428
data class State(var mayaSdkMapping: SdkPortMap = mutableMapOf())
@@ -33,14 +37,23 @@ class ApplicationSettings : PersistentStateComponent<ApplicationSettings.State>
3337
init {
3438
val mayaSdk =
3539
PythonSdkUtil.getAllLocalCPythons().filter { it.homePath?.endsWith(mayaPyExecutableName) ?: false }
36-
val homePaths = mayaSdk.map { it.homePath!! }
3740

38-
for (path in homePaths) {
41+
for (sdk in mayaSdk) {
42+
val path = sdk.homePath!!
3943
mayaSdkMapping[path] = SdkInfo(path, -1)
4044
}
4145
assignEmptyPorts()
4246
}
4347

48+
fun findByPath(path: String): Sdk? {
49+
for (sdk in PythonSdkUtil.getAllSdks()) {
50+
if (sdk.homePath.equals(path)) {
51+
return sdk
52+
}
53+
}
54+
return null
55+
}
56+
4457
var mayaSdkMapping: SdkPortMap
4558
get() = myState.mayaSdkMapping
4659
set(value) {
@@ -54,11 +67,11 @@ class ApplicationSettings : PersistentStateComponent<ApplicationSettings.State>
5467
override fun loadState(state: State) {
5568
val mayaPySdks =
5669
PythonSdkUtil.getAllLocalCPythons().filter { x -> x.homePath?.endsWith(mayaPyExecutableName) ?: false }
57-
val homePaths = mayaPySdks.map { it.homePath!! }
5870

5971
mayaSdkMapping.clear()
6072

61-
for (path in homePaths) {
73+
for (sdk in mayaPySdks) {
74+
val path = sdk.homePath!!
6275
if (state.mayaSdkMapping.containsKey(path)) {
6376
mayaSdkMapping[path] = state.mayaSdkMapping[path]!!
6477
continue
@@ -82,8 +95,11 @@ class ApplicationSettings : PersistentStateComponent<ApplicationSettings.State>
8295
mayaSdkMapping.remove(path)
8396
}
8497

85-
for (path in toAdd) {
86-
mayaSdkMapping[path] = SdkInfo(path, -1)
98+
for (sdk in mayaSdk) {
99+
val path = sdk.homePath!!
100+
if (path in toAdd) {
101+
mayaSdkMapping[path] = SdkInfo(path, -1)
102+
}
87103
}
88104
assignEmptyPorts()
89105
}

β€Žsrc/main/kotlin/settings/ui/SdkTable.ktβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class SdkTablePanel(private val project: Project) :
5353
val selectedSdk = dialog.getOrCreateSdk() ?: return null
5454
SdkConfigurationUtil.addSdk(selectedSdk)
5555

56-
selectedSdk.homePath?.let {
56+
selectedSdk.let {
5757
val unusedPort = ApplicationSettings.INSTANCE.getUnusedPort()
5858
onChanged(this)
59-
return ApplicationSettings.SdkInfo(it, unusedPort)
59+
return ApplicationSettings.SdkInfo(it.homePath!!, unusedPort)
6060
}
6161
return null
6262
}
@@ -69,7 +69,7 @@ class SdkTablePanel(private val project: Project) :
6969
) == 0
7070

7171
if (result) {
72-
val sdk = PythonSdkUtil.findSdkByPath(sdkInfo.mayaPyPath) ?: return false
72+
val sdk = sdkInfo.sdk ?: return false
7373
SdkConfigurationUtil.removeSdk(sdk)
7474
}
7575
onChanged(this)

0 commit comments

Comments
Β (0)