generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mock): init for run mock serivce
- Loading branch information
Showing
8 changed files
with
73 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
66 changes: 66 additions & 0 deletions
66
toolsets/mock/src/main/kotlin/com/phodal/shire/wiremock/provider/WiremockFunctionProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.phodal.shire.wiremock.provider | ||
|
||
import com.intellij.execution.RunManager | ||
import com.intellij.execution.actions.ConfigurationContext | ||
import com.intellij.json.psi.JsonFile | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiManager | ||
import com.phodal.shirecore.provider.function.ToolchainFunctionProvider | ||
import com.phodal.shirecore.runner.ConfigurationRunner | ||
|
||
enum class WiremockFunction(val funName: String) { | ||
Mock("mock") | ||
; | ||
|
||
companion object { | ||
fun fromString(value: String): WiremockFunction? { | ||
return values().firstOrNull { it.funName == value } | ||
} | ||
} | ||
} | ||
|
||
|
||
class WiremockFunctionProvider : ToolchainFunctionProvider, ConfigurationRunner { | ||
override fun isApplicable(project: Project, funcName: String): Boolean { | ||
return WiremockFunction.values().any { it.funName == funcName } | ||
} | ||
|
||
override fun execute(project: Project, funcName: String, args: List<Any>, allVariables: Map<String, Any?>): Any { | ||
val wiremockFunction = WiremockFunction.fromString(funcName) | ||
?: throw IllegalArgumentException("Shire[Wiremock]: Invalid Wiremock function name") | ||
|
||
return when (wiremockFunction) { | ||
WiremockFunction.Mock -> { | ||
if (args.isEmpty()) { | ||
return "ShireError[Wiremock]: No args found" | ||
} | ||
|
||
val mockFilepath = args.first() | ||
val mockFile = project.baseDir.findFileByRelativePath(mockFilepath.toString()) | ||
?: throw IllegalArgumentException("ShireError[Wiremock]: No file found") | ||
|
||
val jsonFile = PsiManager.getInstance(project).findFile(mockFile) as? JsonFile | ||
?: throw IllegalArgumentException("ShireError[Wiremock]: No file found") | ||
|
||
runMock(project, jsonFile) | ||
} | ||
} | ||
} | ||
|
||
private fun runMock(project: Project, mockFile: JsonFile): Any { | ||
val configurationSettings = | ||
ConfigurationContext(mockFile).configurationsFromContext?.firstOrNull()?.configurationSettings | ||
?: return "Please install Wiremock plugin" | ||
|
||
val runManager = RunManager.getInstance(project) | ||
// val configure = runManager.allConfigurationsList.firstOrNull() ?: return "Please install Wiremock plugin" | ||
runManager.selectedConfiguration = configurationSettings | ||
|
||
configurationSettings.isActivateToolWindowBeforeRun = true | ||
|
||
val runContext = createRunContext() | ||
executeRunConfigures(project, configurationSettings, runContext, null, null) | ||
|
||
return "ShireError[Wiremock]: No file found" | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/resources/com.phodal.shire.wiremock.xml → .../main/resources/com.phodal.shire.mock.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
...s/wiremock/src/main/kotlin/com/phodal/shire/wiremock/provider/WiremockFunctionProvider.kt
This file was deleted.
Oops, something went wrong.