mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-09-14 04:42:17 +02:00
feat(connector): improve capturing VDMJ
This commit is contained in:
parent
ad8b36678d
commit
db775bfdea
@ -0,0 +1,7 @@
|
|||||||
|
package io.anthonyberg.connector.models
|
||||||
|
|
||||||
|
import com.fujitsu.vdmj.ExitStatus
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class VDMJExpression(val output: String, val exitStatus: ExitStatus)
|
@ -1,20 +1,21 @@
|
|||||||
package io.anthonyberg.connector.vdmj
|
package io.anthonyberg.connector.vdmj
|
||||||
|
|
||||||
import com.fujitsu.vdmj.Settings
|
import com.fujitsu.vdmj.Settings
|
||||||
import com.fujitsu.vdmj.VDMJMain
|
|
||||||
import com.fujitsu.vdmj.config.Properties
|
import com.fujitsu.vdmj.config.Properties
|
||||||
|
import com.fujitsu.vdmj.messages.Console
|
||||||
|
import com.fujitsu.vdmj.messages.ConsolePrintWriter
|
||||||
|
import com.fujitsu.vdmj.plugins.EventHub
|
||||||
import com.fujitsu.vdmj.plugins.Lifecycle
|
import com.fujitsu.vdmj.plugins.Lifecycle
|
||||||
import com.fujitsu.vdmj.plugins.VDMJ
|
import com.fujitsu.vdmj.plugins.VDMJ
|
||||||
|
import io.anthonyberg.connector.models.VDMJExpression
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.PrintStream
|
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import kotlin.io.path.pathString
|
import kotlin.io.path.pathString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the VDM Model
|
* Handler for the VDM Model
|
||||||
*/
|
*/
|
||||||
class VDMJ : VDMJMain {
|
fun vdmjExecute(expression: String): VDMJExpression {
|
||||||
fun run(expression: String): String {
|
|
||||||
Settings.mainClass = VDMJ::class.java
|
Settings.mainClass = VDMJ::class.java
|
||||||
Properties.init()
|
Properties.init()
|
||||||
|
|
||||||
@ -22,21 +23,33 @@ class VDMJ : VDMJMain {
|
|||||||
|
|
||||||
// Create a ByteArrayOutputStream to capture the output
|
// Create a ByteArrayOutputStream to capture the output
|
||||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
val printStream = PrintStream(byteArrayOutputStream)
|
val printStream = ConsolePrintWriter(byteArrayOutputStream)
|
||||||
|
|
||||||
val oldOut = System.out
|
// Save the old PrintStreams
|
||||||
|
val oldOut = Console.out
|
||||||
|
val oldErr = Console.err
|
||||||
|
|
||||||
// Redirect System.out to the PrintStream
|
// Redirect Console's PrintStreams to the new PrintStream
|
||||||
System.setOut(printStream)
|
Console.out = printStream
|
||||||
|
Console.err = printStream
|
||||||
|
|
||||||
// TODO add exitStatus handling if something went wrong
|
// TODO check if there is actually a memory leak or if it is just Java
|
||||||
var exitStatus = lifecycle.run()
|
val exitStatus = lifecycle.run()
|
||||||
|
|
||||||
// Reset System.out to the old output stream
|
// Reset Console's PrintStreams to the old PrintStreams
|
||||||
System.setOut(oldOut)
|
Console.out = oldOut
|
||||||
|
Console.err = oldErr
|
||||||
|
|
||||||
// Convert the captured output to a string
|
// Convert the captured output to a string
|
||||||
val output = byteArrayOutputStream.toString()
|
val console = byteArrayOutputStream.toString()
|
||||||
|
|
||||||
|
// Reset the ByteArrayOutputStream
|
||||||
|
byteArrayOutputStream.reset()
|
||||||
|
|
||||||
|
// Resets VDMJ's EventHub after closing lifecycle
|
||||||
|
EventHub.reset()
|
||||||
|
|
||||||
|
val output = VDMJExpression(output = console, exitStatus = exitStatus)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@ -54,5 +67,3 @@ class VDMJ : VDMJMain {
|
|||||||
|
|
||||||
return Lifecycle(vdmArgs)
|
return Lifecycle(vdmArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user