All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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.

There is a newer version: 0.9.17
Show newest version
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()
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy