com.github.yag.punner.core.Output.kt Maven / Gradle / Ivy
Go to download
Punner is a parallel JUnit test runner and maven plugin which can speed up your unit test.
package com.github.yag.punner.core
import org.slf4j.LoggerFactory
import java.io.File
object Output {
private val LOG = LoggerFactory.getLogger(Output::class.java)!!
const val OUTPUT_PATH = "punner.output-path"
internal val outputDirectory: File
internal val logDirectory: File
private val deleteLogOnExist: Boolean
init {
val outputPath = System.getProperty(OUTPUT_PATH)
if (outputPath.isNullOrBlank()) {
outputDirectory = File(System.getProperty("java.io.tmpdir"))
logDirectory = outputDirectory
deleteLogOnExist = true
} else {
outputDirectory = File(outputPath)
outputDirectory.mkdirs()
logDirectory = File(outputDirectory, "logs")
logDirectory.mkdirs()
deleteLogOnExist = false
}
LOG.debug("Use output directory: {}", outputDirectory)
}
fun logFile(className: String, methodName: String) : File {
return File(logDirectory, "$className.$methodName.log").apply {
if (deleteLogOnExist) deleteOnExit()
}
}
fun resultFile(className: String, methodName: String) : File {
return File(outputDirectory, ".$className.$methodName.result").apply {
if (deleteLogOnExist) deleteOnExit()
}
}
}