Skip to content

Commit

Permalink
feat: adapt windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhangli committed Jan 4, 2023
1 parent fcf1c4a commit 2e5064e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pluginName = go-kratos-plugin
pluginVersion = 0.0.7

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 222.*
pluginSinceBuild = 221.*
pluginUntilBuild = 223.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#intellij-extension
platformType = GO
platformVersion = 2022.3
platformVersion = 2022.1

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.jaFva, com.jetbrains.php:203.4449.22
Expand All @@ -22,4 +22,4 @@ gradleVersion = 7.5.1
runIde.autoReloadPlugins=true
# Opt-out flag for bundling Kotlin standard library -> https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
# suppress inspection "UnusedProperty"
kotlin.stdlib.default.dependency = false
kotlin.stdlib.default.dependency = false
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,20 @@ public fun runAndLog(project: Project, cmds: List<String>){
public fun runAndLog(project: Project, cmd: GeneralCommandLine){
runAndLog(project, cmd,true)
}
public fun runAndLog(project: Project, cmd: GeneralCommandLine,clear:Boolean?) {
val output = ExecUtil.execAndGetOutput(cmd)
WriteCommandAction.runWriteCommandAction(project) {
if(clear == true){
clearConsole(project)
}
infoConsole(project, cmd.commandLineString)
if (output.exitCode != 0) {
if (output.stdout.trim().isNotEmpty()) {
errorConsole(project, output.stdout)
}
if (output.stderr.trim().isNotEmpty()) {
errorConsole(project, output.stderr)
}
} else {
if (output.stdout.trim().isNotEmpty()) {
infoConsole(project, output.stdout)
}
if (output.stderr.trim().isNotEmpty()) {
infoConsole(project, output.stderr)
}
}
}
}

public fun runAndLog(project: Project, cmds: List<String>,clear:Boolean?) {
val cmd = GeneralCommandLine(cmds)
.withWorkDirectory(project.basePath)
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.SYSTEM)
runAndLog(project,cmd,clear)
}
public fun runAndLog(project: Project, cmd: GeneralCommandLine,clear:Boolean?) {
val output = ExecUtil.execAndGetOutput(cmd)
WriteCommandAction.runWriteCommandAction(project) {
if(clear == true){
clearConsole(project)
}
infoConsole(project, *formatCmd(cmds))
infoConsole(project, cmd.commandLineString)
if (output.exitCode != 0) {
if (output.stdout.trim().isNotEmpty()) {
errorConsole(project, output.stdout)
Expand All @@ -134,6 +114,7 @@ public fun runAndLog(project: Project, cmds: List<String>,clear:Boolean?) {
}
}


public fun infoConsole(project: Project, vararg str: String) {
val c = getConsole(project)
for (i in str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ class DirHelper {
return dir.split("/").toTypedArray()
}

fun join(dir:String,vararg target:String): String {
fun join(vararg target:String): String {
val dirs = arrayListOf<String>()
dirs.addAll(dir.split(File.separator))
dirs.addAll(target)
return dirs.joinToString(File.separator)
}

// fun join(dir:String,vararg target:String): String {
// val dirs = arrayListOf<String>()
// dirs.addAll(dir.split(File.separator))
// dirs.addAll(target)
// return dirs.joinToString(File.separator)
// }

fun cd(dir:PsiDirectory,path:String) :PsiDirectory?{
var target = dir
val paths = path.split(File.separator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ fun genPbTask(file: PsiFile): KratosTask? {
return null
}
val project = file.project
val parentPath = DirHelper.relativeToRoot(file.parent ?: return null) ?: return null
val parentPath = DirHelper.split(DirHelper.relativeToRoot(file.parent ?: return null) ?: return null)
val otherPaths = hashSetOf<String>()
otherPaths.addAll(findDependency(file))
val cmds = arrayListOf("protoc")
cmds.addAll(otherPaths)
cmds.add("--proto_path=${DirHelper.join(project.basePath!!, *DirHelper.split(parentPath))}")
cmds.add("--go_out=paths=source_relative:${DirHelper.join(project.basePath!!, *DirHelper.split(parentPath))}")
cmds.add(DirHelper.join(project.basePath!!, parentPath, file.name))
cmds.add("--proto_path=${DirHelper.join(project.basePath!!, *parentPath)}")
cmds.add("--go_out=paths=source_relative:${DirHelper.join(project.basePath!!, *parentPath)}")
cmds.add(DirHelper.join(project.basePath!!, *parentPath, file.name))
return KratosTask(
{
runAndLog(project, cmds)
Expand All @@ -81,16 +81,16 @@ fun genPbTask(file: PsiFile): KratosTask? {

fun genClientTask(file: PsiFile): KratosTask? {
val project = file.project
val parentPath = DirHelper.relativeToRoot(file.parent ?: return null) ?: return null
val parentPath = DirHelper.split(DirHelper.relativeToRoot(file.parent ?: return null) ?: return null)
val otherPaths = hashSetOf<String>()
otherPaths.addAll(findDependency(file))
val cmds = arrayListOf("protoc")
cmds.addAll(otherPaths)
cmds.add("--proto_path=${DirHelper.join(project.basePath!!, *DirHelper.split(parentPath))}")
cmds.add("--go_out=paths=source_relative:${DirHelper.join(project.basePath!!, *DirHelper.split(parentPath))}")
cmds.add("--go-http_out=paths=source_relative:${DirHelper.join(project.basePath!!, *DirHelper.split(parentPath))}")
cmds.add("--go-grpc_out=paths=source_relative:${DirHelper.join(project.basePath!!, *DirHelper.split(parentPath))}")
cmds.add(DirHelper.join(project.basePath!!, *parentPath.split("/").toTypedArray(), file.name))
cmds.add("--proto_path=${DirHelper.join(project.basePath!!, *parentPath)}")
cmds.add("--go_out=paths=source_relative:${DirHelper.join(project.basePath!!, *parentPath)}")
cmds.add("--go-http_out=paths=source_relative:${DirHelper.join(project.basePath!!, *parentPath)}")
cmds.add("--go-grpc_out=paths=source_relative:${DirHelper.join(project.basePath!!, *parentPath)}")
cmds.add(DirHelper.join(project.basePath!!, *parentPath, file.name))
return KratosTask(
{
runAndLog(project, cmds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private fun genWire(dir: PsiDirectory, config: KratosConfig): List<KratosTask>?
val documentManager = PsiDocumentManager.getInstance(project)

val exe = GoSdkUtil.findExecutableInGoPath("wire", dir.project, null) ?: return null
val cmd = GeneralCommandLine(exe.path, targetDir.virtualFile.canonicalPath)
val paths = DirHelper.split(targetDir.virtualFile.canonicalPath!!)
val cmd = GeneralCommandLine(exe.path, DirHelper.join(*paths))
.withWorkDirectory(project.basePath)
val tasks = arrayListOf<KratosTask>()

Expand Down

0 comments on commit 2e5064e

Please sign in to comment.