Skip to content

Commit

Permalink
CommandLineRunner API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Iurii Zaitsev committed Oct 9, 2024
1 parent 1aef6ec commit 3afa350
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@ class JavaTestCompiler(
println("javac found at '${javaCompile.absolutePath}'")

// compile file
val errorMsg = CommandLineRunner.run(
val executionResult = CommandLineRunner.run(
arrayListOf(
javaCompile.absolutePath,
"-cp",
classPaths,
path,
),
)
val executionMsg = executionResult.second

log.info { "Error message: '$errorMsg'" }
log.info { "Execution result: '${executionMsg}'" }
// create .class file path
val classFilePath = path.replace(".java", ".class")

// check is .class file exists
return Pair(File(classFilePath).exists(), errorMsg)
return Pair(File(classFilePath).exists() && (executionResult.first == 0), executionMsg)
}

override fun getClassPaths(buildPath: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@ class KotlinTestCompiler(libPaths: List<String>, junitLibPaths: List<String>) :
// TODO find the kotlinc if it is not in PATH
val classPaths = "\"${getClassPaths(projectBuildPath)}\""
// Compile file
val errorMsg = CommandLineRunner.run(
val executionResult = CommandLineRunner.run(
arrayListOf(
"kotlinc",
"-cp",
classPaths,
path,
),
)
val executionMsg = executionResult.second
val execSuccessful = executionResult.first == 0

if (errorMsg.isNotEmpty()) {
log.info { "Error message: '$errorMsg'" }
if (errorMsg.contains("kotlinc: command not found'")) {
throw RuntimeException(errorMsg)
if (!execSuccessful) {
log.info { "Error message: '$executionMsg'" }
if (executionMsg.contains("kotlinc: command not found'")) {
throw RuntimeException(executionMsg)
}
}

// No need to save the .class file for kotlin, so checking the error message is enough
return Pair(errorMsg.isBlank(), errorMsg)
// TODO `.class` files are not saving for Kotlin
return Pair(execSuccessful, executionMsg)
}

override fun getClassPaths(buildPath: String): String = commonPath.plus(buildPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class CommandLineRunner {
protected val log = KotlinLogging.logger {}

/**
* Executes a command line process and returns the output as a string.
* Executes a command line process
*
* @param cmd The command line arguments as an ArrayList of strings.
* @return The output of the command line process as a string.
* @return A pair containing exit value and a string message containing execution results
*/
fun run(cmd: ArrayList<String>): String {
var errorMessage = ""
fun run(cmd: ArrayList<String>): Pair<Int, String> {
var executionMsg = ""

/**
* Since Windows does not provide bash, use cmd or similar default command line interpreter
Expand All @@ -37,12 +37,11 @@ class CommandLineRunner {
var line: String?

while (reader.readLine().also { line = it } != null) {
errorMessage += line
executionMsg += line
}

process.waitFor()

return errorMessage
return Pair(process.exitValue(), executionMsg)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TestProcessor(
} else {
"-javaagent:$jacocoAgentLibraryPath=destfile=$dataFileName.exec,append=false"
}
val testExecutionError = CommandLineRunner.run(
val testExecutionResult = CommandLineRunner.run(
arrayListOf(
javaRunner.absolutePath,
javaAgentFlag,
Expand All @@ -110,7 +110,7 @@ class TestProcessor(
),
)

log.info("Test execution error message: $testExecutionError")
log.info("Test execution message: ${testExecutionResult.second}")

// Prepare the command for generating the Jacoco report
val command = mutableListOf(
Expand Down Expand Up @@ -140,7 +140,7 @@ class TestProcessor(

CommandLineRunner.run(command as ArrayList<String>)

return testExecutionError
return if (testExecutionResult.first == 0) "" else testExecutionResult.second
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EvoSuiteProcessManager(
if (ToolUtils.isProcessStopped(errorMonitor, indicator)) return null

val regex = Regex("version \"(.*?)\"")
val version = regex.find(CommandLineRunner.run(arrayListOf(evoSuiteSettingsState.javaPath, "-version")))
val version = regex.find(CommandLineRunner.run(arrayListOf(evoSuiteSettingsState.javaPath, "-version")).second)
?.groupValues
?.get(1)
?.split(".")
Expand Down

0 comments on commit 3afa350

Please sign in to comment.