Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiens12357 committed May 12, 2023
1 parent 7e9c4ac commit 2e081ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 44 deletions.
11 changes: 6 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@
<version>${maven.plugin-tools.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.32</version>
</dependency>
<dependency>
<groupId>info.novatec</groupId>
<artifactId>camunda-bpmn-documentation-generator</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
Expand Down
49 changes: 10 additions & 39 deletions src/main/kotlin/info/novatec/cbdg/plugin/GenerateMojo.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)
}
}

0 comments on commit 2e081ca

Please sign in to comment.