-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...rc/main/kotlin/io/github/platan/tests_execution_chart/reporters/SingleFileReportWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.github.platan.tests_execution_chart.reporters | ||
|
||
import java.io.File | ||
|
||
class SingleFileReportWriter { | ||
|
||
fun save( | ||
report: String, | ||
taskName: String, | ||
baseDir: File, | ||
location: String, | ||
extension: String | ||
): File { | ||
val reportsDir = prepareReportsDir(baseDir, location) | ||
val reportFile = File(reportsDir, "$taskName.$extension") | ||
reportFile.createNewFile() | ||
reportFile.writeText(report) | ||
return reportFile | ||
} | ||
|
||
private fun prepareReportsDir(baseDir: File, location: String): File { | ||
val reportsDir = File(baseDir, location) | ||
reportsDir.mkdirs() | ||
return reportsDir | ||
} | ||
|
||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...kotlin/io/github/platan/tests_execution_chart/reporters/html/HtmlGanttDiagramFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.github.platan.tests_execution_chart.reporters.html | ||
|
||
import io.github.platan.tests_execution_chart.report.data.TestExecutionScheduleReport | ||
import io.github.platan.tests_execution_chart.reporters.mermaid.TestExecutionMermaidDiagramFormatter | ||
import java.net.URL | ||
|
||
private const val TEMPLATE_HTML_FILE = "template.html" | ||
private const val GRAPH_PLACEHOLDER = "@GRAPH_PLACEHOLDER@" | ||
private const val MAX_TEXT_SIZE_PLACEHOLDER = "@MAX_TEXT_SIZE@" | ||
private const val MERMAID_SRC_PLACEHOLDER = "@MERMAID_SRC@" | ||
private const val TABLE_SRC_PLACEHOLDER = "@TABLE@" | ||
|
||
class HtmlGanttDiagramFormatter { | ||
|
||
fun formatHtml( | ||
report: TestExecutionScheduleReport, | ||
scriptSrc: String, | ||
maxTextSize: Int | ||
): String { | ||
val template: String = loadTemplate(TEMPLATE_HTML_FILE) | ||
return prepareHtmlReport(report, template, scriptSrc, maxTextSize) | ||
} | ||
|
||
private fun loadTemplate(templatePath: String): String { | ||
val resource: URL? = this::class.java.classLoader.getResource(templatePath) | ||
val template: String | ||
if (resource == null) { | ||
throw RuntimeException("$templatePath not found") | ||
} else { | ||
template = resource.readText(Charsets.UTF_8) | ||
} | ||
return template | ||
} | ||
|
||
|
||
private fun prepareHtmlReport( | ||
report: TestExecutionScheduleReport, | ||
template: String, | ||
src: String, | ||
maxTextSize: Int | ||
): String { | ||
val mermaid = TestExecutionMermaidDiagramFormatter().format(report) | ||
val escapedMermaid = mermaid | ||
.replace("\\", "\\\\") | ||
// Mermaid data is put in javascript code and specified using backtick character (`). | ||
// We have to escape ` character. | ||
.replace("`", "\\`") | ||
val table = HtmlTableFormatter().format(report) | ||
return template | ||
.replace(GRAPH_PLACEHOLDER, escapedMermaid) | ||
.replace(MERMAID_SRC_PLACEHOLDER, src) | ||
.replace(MAX_TEXT_SIZE_PLACEHOLDER, maxTextSize.toString()) | ||
.replace(TABLE_SRC_PLACEHOLDER, table) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters