Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Line Runner API changes #381

Merged
merged 8 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Hello-zoka marked this conversation as resolved.
Show resolved Hide resolved
*/
fun run(cmd: ArrayList<String>): String {
var errorMessage = ""
fun run(cmd: ArrayList<String>): Pair<Int, String> {
Hello-zoka marked this conversation as resolved.
Show resolved Hide resolved
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
Hello-zoka marked this conversation as resolved.
Show resolved Hide resolved
}

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
Hello-zoka marked this conversation as resolved.
Show resolved Hide resolved
}

/**
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)
Hello-zoka marked this conversation as resolved.
Show resolved Hide resolved
?.groupValues
?.get(1)
?.split(".")
Expand Down
Loading