Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pluginGroup=com.github.pyvenvmanage
pluginName=PyVenv Manage 2
pluginRepositoryUrl=https://github.com/pyvenvmanage/PyVenvManage
pluginSinceBuild=262
pluginVersion=2.4.0-dev
pluginVersion=2.4.1-dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.pyvenvmanage

import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.notification.NotificationAction
import com.intellij.notification.NotificationGroupManager
import com.intellij.notification.NotificationType
Expand Down Expand Up @@ -28,20 +30,9 @@ class PythonRequiredStartupActivity : ProjectActivity {
).notify(project)
}

private fun isPythonPluginAvailable(): Boolean {
val pythonModuleId = PluginId.getId("com.intellij.modules.python")
val pythonCoreId = PluginId.getId("PythonCore")
return (
com.intellij.ide.plugins.PluginManagerCore
.getPlugin(pythonModuleId) != null &&
!com.intellij.ide.plugins.PluginManagerCore
.isDisabled(pythonModuleId)
) ||
(
com.intellij.ide.plugins.PluginManagerCore
.getPlugin(pythonCoreId) != null &&
!com.intellij.ide.plugins.PluginManagerCore
.isDisabled(pythonCoreId)
)
}
private fun isPythonPluginAvailable(): Boolean =
isEnabled(PluginId.getId("com.intellij.modules.python")) || isEnabled(PluginId.getId("PythonCore"))

private fun isEnabled(id: PluginId): Boolean =
PluginManager.isPluginInstalled(id) && !PluginManagerCore.isDisabled(id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

import com.intellij.ide.plugins.IdeaPluginDescriptor
import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.notification.Notification
import com.intellij.notification.NotificationAction
Expand Down Expand Up @@ -45,6 +45,7 @@ class PythonRequiredStartupActivityTest {
pythonCoreId = PluginId.getId("PythonCore")

mockkStatic(NotificationGroupManager::class)
mockkStatic(PluginManager::class)
mockkStatic(PluginManagerCore::class)
mockkObject(PyVenvManageSettings)

Expand All @@ -61,15 +62,15 @@ class PythonRequiredStartupActivityTest {
@AfterEach
fun tearDown() {
unmockkStatic(NotificationGroupManager::class)
unmockkStatic(PluginManager::class)
unmockkStatic(PluginManagerCore::class)
unmockkObject(PyVenvManageSettings)
}

@Test
fun `does not show notification when python module is available`(): Unit =
runBlocking {
val pythonPlugin: IdeaPluginDescriptor = mockk(relaxed = true)
every { PluginManagerCore.getPlugin(pythonModuleId) } returns pythonPlugin
every { PluginManager.isPluginInstalled(pythonModuleId) } returns true
every { PluginManagerCore.isDisabled(pythonModuleId) } returns false

PythonRequiredStartupActivity().execute(project)
Expand All @@ -80,9 +81,8 @@ class PythonRequiredStartupActivityTest {
@Test
fun `does not show notification when PythonCore plugin is available`(): Unit =
runBlocking {
val pythonCorePlugin: IdeaPluginDescriptor = mockk(relaxed = true)
every { PluginManagerCore.getPlugin(pythonModuleId) } returns null
every { PluginManagerCore.getPlugin(pythonCoreId) } returns pythonCorePlugin
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns true
every { PluginManagerCore.isDisabled(pythonCoreId) } returns false

PythonRequiredStartupActivity().execute(project)
Expand All @@ -93,8 +93,8 @@ class PythonRequiredStartupActivityTest {
@Test
fun `shows warning notification when python is not available`(): Unit =
runBlocking {
every { PluginManagerCore.getPlugin(pythonModuleId) } returns null
every { PluginManagerCore.getPlugin(pythonCoreId) } returns null
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false

PythonRequiredStartupActivity().execute(project)

Expand All @@ -111,10 +111,9 @@ class PythonRequiredStartupActivityTest {
@Test
fun `shows warning when python plugin exists but is disabled`(): Unit =
runBlocking {
val disabledPlugin: IdeaPluginDescriptor = mockk(relaxed = true)
every { PluginManagerCore.getPlugin(pythonModuleId) } returns disabledPlugin
every { PluginManager.isPluginInstalled(pythonModuleId) } returns true
every { PluginManagerCore.isDisabled(pythonModuleId) } returns true
every { PluginManagerCore.getPlugin(pythonCoreId) } returns null
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false

PythonRequiredStartupActivity().execute(project)

Expand All @@ -124,8 +123,8 @@ class PythonRequiredStartupActivityTest {
@Test
fun `does not show notification when warning was dismissed`(): Unit =
runBlocking {
every { PluginManagerCore.getPlugin(pythonModuleId) } returns null
every { PluginManagerCore.getPlugin(pythonCoreId) } returns null
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false
every { settings.dismissedPythonWarning } returns true

PythonRequiredStartupActivity().execute(project)
Expand All @@ -136,8 +135,8 @@ class PythonRequiredStartupActivityTest {
@Test
fun `notification includes dont show again action`(): Unit =
runBlocking {
every { PluginManagerCore.getPlugin(pythonModuleId) } returns null
every { PluginManagerCore.getPlugin(pythonCoreId) } returns null
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false

PythonRequiredStartupActivity().execute(project)

Expand All @@ -147,8 +146,8 @@ class PythonRequiredStartupActivityTest {
@Test
fun `dont show again action sets dismissed flag and expires notification`(): Unit =
runBlocking {
every { PluginManagerCore.getPlugin(pythonModuleId) } returns null
every { PluginManagerCore.getPlugin(pythonCoreId) } returns null
every { PluginManager.isPluginInstalled(pythonModuleId) } returns false
every { PluginManager.isPluginInstalled(pythonCoreId) } returns false

val actionSlot = slot<NotificationAction>()
every { notification.addAction(capture(actionSlot)) } returns notification
Expand Down
Loading