Skip to content

Commit 456971b

Browse files
committed
feat: enable and disable plugin conditionally
1 parent ca1f389 commit 456971b

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

src/main/kotlin/com/github/xepozz/testo/TestoComposerConfig.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,43 @@ package com.github.xepozz.testo
22

33
import com.github.xepozz.testo.tests.TestoFrameworkType
44
import com.github.xepozz.testo.tests.run.TestoRunConfigurationType
5+
import com.intellij.openapi.project.Project
6+
import com.intellij.openapi.vfs.VfsUtil
7+
import com.intellij.openapi.vfs.VirtualFile
58
import com.jetbrains.php.testFramework.PhpTestFrameworkComposerConfig
9+
import com.jetbrains.php.testFramework.PhpTestFrameworkConfigurationIml
10+
import com.jetbrains.php.testFramework.PhpTestFrameworkSettingsManager
11+
import kotlin.io.path.Path
612

713
class TestoComposerConfig : PhpTestFrameworkComposerConfig(TestoFrameworkType.INSTANCE, PACKAGE, RELATIVE_PATH) {
814
override fun getDefaultConfigName() = "testo.php"
915

1016
override fun getConfigurationType() = TestoRunConfigurationType.INSTANCE
1117

18+
override fun findConfigurationFile(project: Project, composerConfig: VirtualFile?): VirtualFile? {
19+
return super.findConfigurationFile(project, composerConfig)
20+
}
21+
override fun updateConfigurations(project: Project, configFile: VirtualFile?, composerConfig: VirtualFile?) {
22+
val testFrameworkSettingsManager = PhpTestFrameworkSettingsManager.getInstance(project)
23+
if (testFrameworkSettingsManager.getConfigurations(TestoFrameworkType.INSTANCE).isNotEmpty()) {
24+
return
25+
}
26+
27+
val runnableBinary = findFromComposerVendor(project, composerConfig)
28+
?.let { Path(it) }
29+
?.let { VfsUtil.findFile(it, false) }
30+
31+
val configuration = PhpTestFrameworkConfigurationIml(TestoFrameworkType.INSTANCE)
32+
configuration.executablePath = runnableBinary?.path
33+
34+
testFrameworkSettingsManager.addSettingsIfAbsent(
35+
TestoFrameworkType.INSTANCE,
36+
configuration,
37+
null,
38+
runnableBinary,
39+
)
40+
}
41+
1242
companion object Companion {
1343
private const val PACKAGE = "testo/testo"
1444
private const val RELATIVE_PATH = "bin/testo"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.github.xepozz.testo
2+
3+
import com.github.xepozz.testo.tests.TestoFrameworkType
4+
import com.intellij.openapi.project.Project
5+
import com.intellij.openapi.util.text.StringUtil
6+
import com.jetbrains.php.testFramework.PhpTestFrameworkSettingsManager
7+
8+
object TestoUtil {
9+
fun isEnabled(project: Project): Boolean =
10+
PhpTestFrameworkSettingsManager
11+
.getInstance(project)
12+
.getConfigurations(TestoFrameworkType.INSTANCE)
13+
.firstOrNull()
14+
?.let { configurations ->
15+
!configurations.isLocal || StringUtil.isNotEmpty(configurations.executablePath)
16+
}
17+
?: false
18+
}

src/main/kotlin/com/github/xepozz/testo/tests/TestoVersionDetector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object TestoVersionDetector : PhpTestFrameworkVersionDetector<String>() {
1010
override fun getVersionOptions() = arrayOf("--version", "--no-ansi")
1111

1212
public override fun parse(s: String): String {
13-
val version = s.substringAfter("Infection - PHP Mutation Testing Framework version ")
13+
val version = s.substringAfter("Testo ")
1414
if (version.isEmpty()) {
1515
throw ExecutionException(TestoBundle.message("testo.version.error"))
1616
}

src/main/kotlin/com/github/xepozz/testo/tests/run/TestoRunConfigurationProducer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.xepozz.testo.tests.run
22

3+
import com.github.xepozz.testo.TestoUtil
34
import com.github.xepozz.testo.index.TestoDataProviderUtils
45
import com.github.xepozz.testo.isTestoClass
56
import com.github.xepozz.testo.isTestoDataProviderLike
@@ -44,7 +45,7 @@ class TestoRunConfigurationProducer : PhpTestConfigurationProducer<TestoRunConfi
4445
METHOD_NAMER,
4546
METHOD,
4647
) {
47-
override fun isEnabled(project: Project) = true
48+
override fun isEnabled(project: Project) = TestoUtil.isEnabled(project)
4849

4950
override fun setupConfiguration(
5051
testRunnerSettings: PhpTestRunnerSettings,

src/main/kotlin/com/github/xepozz/testo/ui/TestoIconProvider.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.xepozz.testo.ui
22

33
import com.github.xepozz.testo.TestoIcons
4+
import com.github.xepozz.testo.TestoUtil
45
import com.github.xepozz.testo.isTestoFile
56
import com.intellij.ide.IconProvider
67
import com.intellij.openapi.util.Iconable
@@ -14,6 +15,7 @@ import javax.swing.Icon
1415
class TestoIconProvider : IconProvider() {
1516
override fun getIcon(element: PsiElement, @Iconable.IconFlags flags: Int): Icon? {
1617
val phpFile = element as? PhpFile ?: return null
18+
if (!TestoUtil.isEnabled(element.project)) return null
1719

1820
if (!phpFile.isTestoFile()) return null
1921
if (!GlobalSearchScopesCore.projectTestScope(element.project).contains(phpFile.virtualFile)) {

0 commit comments

Comments
 (0)