You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
provs/src/main/kotlin/io/provs/processors/Processor.kt

55 lines
1.6 KiB
Kotlin

package io.provs.processors
interface Processor {
fun x(vararg args: String): ProcessResult
fun xNoLog(vararg args: String): ProcessResult
fun close() {}
}
data class ProcessResult(val exitCode: Int, val out: String? = null, val err: String? = null, val ex: Exception? = null, val args: Array<out String> = emptyArray()) {
private fun success(): Boolean {
return (exitCode == 0)
}
fun argsToString() : String {
return args.joinToString(
separator = ", ",
prefix = "[",
postfix = "]",
limit = 4,
truncated = " ..."
)
}
override fun toString(): String {
return "--->>> ProcessResult: ${if (success()) "Succeeded" else "FAILED"} -- Code: $exitCode, ${if (!out.isNullOrEmpty()) "Out: $out, " else ""}${if (!err.isNullOrEmpty()) "Err: $err" else ""}" + argsToString()
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as ProcessResult
if (exitCode != other.exitCode) return false
if (out != other.out) return false
if (err != other.err) return false
if (ex != other.ex) return false
if (!args.contentEquals(other.args)) return false
return true
}
override fun hashCode(): Int {
var result = exitCode
result = 31 * result + (out?.hashCode() ?: 0)
result = 31 * result + (err?.hashCode() ?: 0)
result = 31 * result + ex.hashCode()
result = 31 * result + args.contentHashCode()
return result
}
}