Skip to content

Commit

Permalink
refactor(asciidoc)!: Make AsciiDocTemplateReporter abstract
Browse files Browse the repository at this point in the history
Convert `AsciiDocTemplateReporter` to an abstract class. This allows to
simplify the constructor by making `backend` an abstract property.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Nov 9, 2024
1 parent affb9fe commit bd82abb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import org.ossreviewtoolkit.utils.ort.createOrtTempDir
* [3]: https://github.com/asciidoctor/asciidoctorj
* [4]: https://docs.asciidoctor.org/asciidoctor/latest/convert/available
*/
open class AsciiDocTemplateReporter(private val backend: String, override val type: String) : Reporter {
abstract class AsciiDocTemplateReporter : Reporter {
companion object {
private const val ASCII_DOC_FILE_PREFIX = "AsciiDoc_"
private const val ASCII_DOC_FILE_EXTENSION = "adoc"
Expand All @@ -53,6 +53,8 @@ open class AsciiDocTemplateReporter(private val backend: String, override val ty
private const val DEFECT_TEMPLATE_ID = "defect_report"
}

protected abstract val backend: String

private val templateProcessor = FreemarkerTemplateProcessor(
ASCII_DOC_TEMPLATE_DIRECTORY,
ASCII_DOC_FILE_PREFIX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ import org.ossreviewtoolkit.reporter.Reporter
* [1]: https://docbook.org
* [2]: https://freemarker.apache.org
*/
class DocBookTemplateReporter : AsciiDocTemplateReporter("docbook", "DocBookTemplate")
class DocBookTemplateReporter : AsciiDocTemplateReporter() {
override val backend = "docbook"
override val type = "DocBookTemplate"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ import org.ossreviewtoolkit.reporter.Reporter
*
* [1]: https://freemarker.apache.org
*/
class HtmlTemplateReporter : AsciiDocTemplateReporter("html", "HtmlTemplate")
class HtmlTemplateReporter : AsciiDocTemplateReporter() {
override val backend = "html"
override val type = "HtmlTemplate"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ import org.ossreviewtoolkit.reporter.Reporter
*
* [1]: https://freemarker.apache.org
*/
class ManPageTemplateReporter : AsciiDocTemplateReporter("manpage", "ManPageTemplate")
class ManPageTemplateReporter : AsciiDocTemplateReporter() {
override val backend = "manpage"
override val type = "ManPageTemplate"
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ import org.ossreviewtoolkit.reporter.Reporter
* [4]: https://github.com/asciidoctor/asciidoctorj-pdf
* [5]: https://docs.asciidoctor.org/pdf-converter/latest/theme/
*/
class PdfTemplateReporter : AsciiDocTemplateReporter("pdf", "PdfTemplate") {
class PdfTemplateReporter : AsciiDocTemplateReporter() {
companion object {
private const val OPTION_PDF_THEME_FILE = "pdf.theme.file"
private const val OPTION_PDF_FONTS_DIR = "pdf.fonts.dir"
}

override val backend = "pdf"
override val type = "PdfTemplate"

override fun processTemplateOptions(outputDir: File, options: MutableMap<String, String>): Attributes =
Attributes.builder().apply {
val pdfTheme = options.remove(OPTION_PDF_THEME_FILE)?.let { option ->
Expand Down

0 comments on commit bd82abb

Please sign in to comment.