diff --git a/pom.xml b/pom.xml index 95484b1..d3f9929 100644 --- a/pom.xml +++ b/pom.xml @@ -44,16 +44,16 @@ ${maven.plugin-tools.version} provided - - org.freemarker - freemarker - 2.3.32 - info.novatec camunda-bpmn-documentation-generator 2.0-SNAPSHOT + + org.slf4j + slf4j-api + 2.0.7 + org.jetbrains.kotlin kotlin-test-junit diff --git a/src/main/kotlin/info/novatec/cbdg/plugin/GenerateMojo.kt b/src/main/kotlin/info/novatec/cbdg/plugin/GenerateMojo.kt index d97de2b..5b5137f 100644 --- a/src/main/kotlin/info/novatec/cbdg/plugin/GenerateMojo.kt +++ b/src/main/kotlin/info/novatec/cbdg/plugin/GenerateMojo.kt @@ -1,25 +1,18 @@ package info.novatec.cbdg.plugin -import info.novatec.cbdg.FreeMarkerService -import info.novatec.docu.parser.main.BpmnParser +import info.novatec.docu.generator.DocuGenerator import org.apache.maven.plugin.AbstractMojo import org.apache.maven.plugins.annotations.Mojo import org.apache.maven.plugins.annotations.Parameter +import org.slf4j.Logger +import org.slf4j.LoggerFactory import java.io.File -import java.io.FileNotFoundException -import java.io.FileOutputStream -import java.nio.file.Files -import java.nio.file.StandardCopyOption -import kotlin.io.path.Path -import kotlin.io.path.createDirectories -import kotlin.io.path.exists /** * Mojo - Class for cbdg-plugin. Calls by Maven-command 'mvn cbdg:generate'. */ @Mojo(name = "generate") class GenerateMojo : AbstractMojo() { - /** * Default usage is the templates/default.ftl from Jar-File. * To use it, it will be created in Build-Dir of the target project the empty file default.ftl @@ -47,34 +40,12 @@ class GenerateMojo : AbstractMojo() { var bpmnDiagramImageDir: File? = null override fun execute() { - if (templateFile.name.equals("default.ftl")) { - FileOutputStream(templateFile, false).use { javaClass.classLoader.getResourceAsStream("templates/default.ftl") - ?.transferTo(it) ?: throw FileNotFoundException("templates/default.ftl don't exist.")} - } - - camundaBpmnDir.listFiles()?.forEach { - log.info("Generating documentation for file ${it.absolutePath}") - log.info("Using template ${templateFile.absolutePath}") - - val imageSrcPath = Path("${bpmnDiagramImageDir?.absolutePath}/${it.nameWithoutExtension}.png") - val imageTargetPath = Path("${resultOutputDir.absolutePath}/images/${it.nameWithoutExtension}.png") - imageTargetPath.parent.createDirectories() - if (imageSrcPath.exists()) { - Files.copy(imageSrcPath, imageTargetPath, StandardCopyOption.REPLACE_EXISTING) - } - - val bpmnObject = BpmnParser.parseBpmnFile(it, "${it.nameWithoutExtension}.png") - FreeMarkerService.writeTemplate( - bpmnObject, - templateFile.name, - "${resultOutputDir.absolutePath}/${it.nameWithoutExtension}.html" - ) { - setDirectoryForTemplateLoading(templateFile.parentFile) - } - log.info("Output report into path ${resultOutputDir.absolutePath}") - } ?: throw FileNotFoundException("${camundaBpmnDir.absolutePath} don't exist.") - resultOutputDir.listFiles()?.forEach { - log.info("Output: " + it.absolutePath) - } ?: throw FileNotFoundException("${resultOutputDir.absolutePath} don't exist.") + DocuGenerator.parseAndGenerate( + LoggerFactory.getLogger(GenerateMojo::class.java), + templateFile, + camundaBpmnDir, + resultOutputDir, + bpmnDiagramImageDir + ) } }