-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse aptos command line json output (#237)
* add aptos result json parser * remove stdIn from execute(_) * parse aptos command line json output * handle jackson exception
- Loading branch information
Showing
10 changed files
with
201 additions
and
60 deletions.
There are no files selected for viewing
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
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
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/org/move/cli/runConfigurations/aptos/AptosCompileArgs.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,36 @@ | ||
package org.move.cli.runConfigurations.aptos | ||
|
||
import org.move.cli.MoveProject | ||
import org.move.cli.externalLinter.ExternalLinter | ||
import org.move.cli.externalLinter.externalLinterSettings | ||
import org.move.cli.settings.moveSettings | ||
import java.nio.file.Path | ||
|
||
data class AptosCompileArgs( | ||
val linter: ExternalLinter, | ||
val moveProjectDirectory: Path, | ||
val extraArguments: String, | ||
val envs: Map<String, String>, | ||
val enableMove2: Boolean, | ||
val skipLatestGitDeps: Boolean, | ||
) { | ||
companion object { | ||
fun forMoveProject(moveProject: MoveProject): AptosCompileArgs { | ||
val linterSettings = moveProject.project.externalLinterSettings | ||
val moveSettings = moveProject.project.moveSettings | ||
|
||
val additionalArguments = linterSettings.additionalArguments | ||
val enviroment = linterSettings.envs | ||
val workingDirectory = moveProject.workingDirectory | ||
|
||
return AptosCompileArgs( | ||
linterSettings.tool, | ||
workingDirectory, | ||
additionalArguments, | ||
enviroment, | ||
enableMove2 = moveSettings.enableMove2, | ||
skipLatestGitDeps = moveSettings.skipFetchLatestGitDeps | ||
) | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/org/move/cli/runConfigurations/aptos/AptosExitStatus.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,35 @@ | ||
package org.move.cli.runConfigurations.aptos | ||
|
||
import com.fasterxml.jackson.core.JacksonException | ||
import com.fasterxml.jackson.databind.DeserializationFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import org.intellij.lang.annotations.Language | ||
|
||
sealed class AptosExitStatus(val message: String) { | ||
class Result(message: String): AptosExitStatus(message) | ||
class Error(message: String): AptosExitStatus(message) | ||
class Malformed(jsonText: String): AptosExitStatus(jsonText) | ||
|
||
companion object { | ||
@Throws(JacksonException::class) | ||
fun fromJson(@Language("JSON") json: String): AptosExitStatus { | ||
val parsedResult = JSON_MAPPER.readValue(json, AptosJsonResult::class.java) | ||
return when { | ||
parsedResult.Error != null -> Error(parsedResult.Error) | ||
parsedResult.Result != null -> Result(parsedResult.Result) | ||
else -> Malformed(json) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Suppress("PropertyName") | ||
private data class AptosJsonResult( | ||
val Result: String?, | ||
val Error: String? | ||
) | ||
|
||
private val JSON_MAPPER: ObjectMapper = ObjectMapper() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.registerKotlinModule() |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/org/move/cli/runConfigurations/aptos/AptosProcessOutput.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,15 @@ | ||
package org.move.cli.runConfigurations.aptos | ||
|
||
import com.intellij.execution.process.ProcessOutput | ||
import org.move.openapiext.RsProcessExecutionOrDeserializationException | ||
import org.move.stdext.RsResult | ||
|
||
typealias AptosProcessResult<T> = RsResult<AptosProcessOutput<T>, RsProcessExecutionOrDeserializationException> | ||
|
||
data class AptosProcessOutput<T>( | ||
val item: T, | ||
val output: ProcessOutput, | ||
val exitStatus: AptosExitStatus, | ||
) { | ||
fun <T, U> replaceItem(newItem: U): AptosProcessOutput<U> = AptosProcessOutput(newItem, output, exitStatus) | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/test/kotlin/org/move/cli/runConfigurations/aptos/AptosExitStatusTest.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,40 @@ | ||
package org.move.cli.runConfigurations.aptos | ||
|
||
import org.move.utils.tests.MvTestBase | ||
|
||
class AptosExitStatusTest: MvTestBase() { | ||
fun `test parse result`() { | ||
val status = AptosExitStatus.fromJson( | ||
""" | ||
{ | ||
"Result": "my result message" | ||
} | ||
""" | ||
) | ||
check(status is AptosExitStatus.Result) | ||
check(status.message == "my result message") | ||
} | ||
|
||
fun `test parse error`() { | ||
val status = AptosExitStatus.fromJson( | ||
""" | ||
{ | ||
"Error": "my error message" | ||
} | ||
""" | ||
) | ||
check(status is AptosExitStatus.Error) | ||
check(status.message == "my error message") | ||
} | ||
|
||
fun `test parse malformed`() { | ||
val status = AptosExitStatus.fromJson( | ||
""" | ||
{ | ||
"Unknown": "unknown" | ||
} | ||
""" | ||
) | ||
check(status is AptosExitStatus.Malformed) | ||
} | ||
} |