From aba1cc3d833dd63a27e6f3f791c7e7529591c7b7 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 7 Jun 2016 17:53:12 +0300 Subject: [PATCH] Minor, cleanup GenerateProtoBuf.kt --- .../generators/protobuf/GenerateProtoBuf.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt b/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt index 6622e748a8a..c2c7946e16c 100644 --- a/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt +++ b/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.generators.protobuf +import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.util.ExecUtil import java.io.File import java.util.regex.Pattern @@ -29,7 +30,7 @@ import java.util.regex.Pattern // * You can also download source and build it yourself (https://code.google.com/p/protobuf/downloads/list) // // You may need to provide custom path to protoc executable, just modify this constant: -val PROTOC_EXE = "protoc" +private const val PROTOC_EXE = "protoc" class ProtoPath(val file: String) { val outPath: String = File(file).parent @@ -80,8 +81,8 @@ fun main(args: Array) { } } -fun checkVersion() { - val processOutput = ExecUtil.execAndGetOutput(listOf(PROTOC_EXE, "--version"), null) +private fun checkVersion() { + val processOutput = ExecUtil.execAndGetOutput(GeneralCommandLine(PROTOC_EXE, "--version")) val version = processOutput.stdout.trim() if (version.isEmpty()) { @@ -92,15 +93,20 @@ fun checkVersion() { } } -fun execProtoc(protoPath: String, outPath: String) { - val processOutput = ExecUtil.execAndGetOutput(listOf(PROTOC_EXE, protoPath, "--java_out=$outPath") + PROTOBUF_PROTO_PATHS.map { "--proto_path=$it" }, null) +private fun execProtoc(protoPath: String, outPath: String) { + val commandLine = GeneralCommandLine( + listOf(PROTOC_EXE, protoPath, "--java_out=$outPath") + + PROTOBUF_PROTO_PATHS.map { "--proto_path=$it" } + ) + println("running $commandLine") + val processOutput = ExecUtil.execAndGetOutput(commandLine) print(processOutput.stdout) if (processOutput.stderr.isNotEmpty()) { throw AssertionError(processOutput.stderr) } } -fun modifyAndExecProtoc(protoPath: ProtoPath) { +private fun modifyAndExecProtoc(protoPath: ProtoPath) { val debugProtoFile = File(protoPath.file.replace(".proto", ".debug.proto")) debugProtoFile.writeText(modifyForDebug(protoPath)) debugProtoFile.deleteOnExit() @@ -108,7 +114,7 @@ fun modifyAndExecProtoc(protoPath: ProtoPath) { execProtoc(debugProtoFile.path, "build-common/test") } -fun modifyForDebug(protoPath: ProtoPath): String { +private fun modifyForDebug(protoPath: ProtoPath): String { var text = File(protoPath.file).readText() .replace("option java_outer_classname = \"${protoPath.className}\"", "option java_outer_classname = \"${protoPath.debugClassName}\"") // give different name for class