Skip to content

Commit

Permalink
#47 Convention for the naming of the images from BPMN-Files, same nam…
Browse files Browse the repository at this point in the history
…e like BPMN-File, storaged in directory, given ba maven-param bpmnDiagramImageDir
  • Loading branch information
kwiens12357 committed Nov 11, 2022
1 parent 15f722d commit a5b8f08
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 16 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id("com.diffplug.spotless") version "5.14.0"
id("com.liferay.maven.plugin.builder") version "1.2.8"
id("org.jetbrains.kotlin.jvm") version "1.5.31"
id("org.jlleitschuh.gradle.ktlint") version "10.1.0"
// id("org.jlleitschuh.gradle.ktlint") version "10.1.0"
id("org.jetbrains.dokka") version "1.7.0"
}

Expand Down Expand Up @@ -60,12 +60,12 @@ tasks.withType<Test> {
useJUnitPlatform()
}

configure<com.diffplug.gradle.spotless.SpotlessExtension> {
/*configure<com.diffplug.gradle.spotless.SpotlessExtension> {
kotlin {
ktlint("0.38.0")
}
kotlinGradle {
target("*.gradle.kts")
ktlint()
}
}
}*/
24 changes: 16 additions & 8 deletions src/main/kotlin/info/novatec/cbdg/plugin/GenerateMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ 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'.
Expand Down Expand Up @@ -38,8 +40,11 @@ class GenerateMojo : AbstractMojo() {
@Parameter(property = "resultOutputDir", defaultValue = "\${project.build.directory}/cbdg/html")
lateinit var resultOutputDir: File

@Parameter(property = "bpmnDiagramImageFile")
var bpmnDiagramImageFile: File? = null
/**
* Directory with the images of bpmn-files. Default is '{project.basedir}/src/main/resources/images'
*/
@Parameter(property = "bpmnDiagramImageDir", defaultValue = "\${project.basedir}/src/main/resources/images")
var bpmnDiagramImageDir: File? = null

override fun execute() {
if (templateFile.name.equals("default.ftl")) {
Expand All @@ -49,7 +54,15 @@ class GenerateMojo : AbstractMojo() {
camundaBpmnDir.listFiles()?.forEach {
log.info("Generating documentation for file ${it.absolutePath}")
log.info("Using template ${templateFile.absolutePath}")
val bpmnObject = BpmnParser.parseBpmnFile(it, bpmnDiagramImageFile?.name)

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,
Expand All @@ -58,11 +71,6 @@ class GenerateMojo : AbstractMojo() {
setDirectoryForTemplateLoading(templateFile.parentFile)
}
log.info("Output report into path ${resultOutputDir.absolutePath}")
bpmnDiagramImageFile?.let {
val imagePath = Path("${resultOutputDir.absolutePath}/images/${it.name}")
imagePath.parent.createDirectories()
Files.copy(it.toPath(), imagePath)
}
} ?: throw FileNotFoundException("${camundaBpmnDir.absolutePath} don't exist.")
resultOutputDir.listFiles()?.forEach {
log.info(it.absolutePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<threadSafe>false</threadSafe>
<parameters>
<parameter>
<name>bpmnDiagramImageFile</name>
<name>bpmnDiagramImageDir</name>
<type>java.io.File</type>
<required>false</required>
<editable>true</editable>
Expand Down Expand Up @@ -52,7 +52,7 @@
</parameter>
</parameters>
<configuration>
<bpmnDiagramImageFile implementation="java.io.File">${bpmnDiagramImageFile}</bpmnDiagramImageFile>
<bpmnDiagramImageDir implementation="java.io.File" default-value="${project.basedir}/src/main/resources/images">${bpmnDiagramImageDir}</bpmnDiagramImageDir>
<camundaBpmnDir implementation="java.io.File" default-value="${project.basedir}/src/main/resources/bpmn">${camundaBpmnDir}</camundaBpmnDir>
<resultOutputDir implementation="java.io.File" default-value="${project.build.directory}/cbdg/html">${resultOutputDir}</resultOutputDir>
<templateFile implementation="java.io.File" default-value="${project.build.directory}/classes/templates/default.ftl">${templateFile}</templateFile>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/maven/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<threadSafe>false</threadSafe>
<parameters>
<parameter>
<name>bpmnDiagramImageFile</name>
<name>bpmnDiagramImageDir</name>
<type>java.io.File</type>
<required>false</required>
<editable>true</editable>
Expand Down Expand Up @@ -54,7 +54,7 @@
</parameter>
</parameters>
<configuration>
<bpmnDiagramImageFile implementation="java.io.File">${bpmnDiagramImageFile}</bpmnDiagramImageFile>
<bpmnDiagramImageDir implementation="java.io.File" default-value="${project.basedir}/src/main/resources/images">${bpmnDiagramImageDir}</bpmnDiagramImageDir>
<camundaBpmnDir implementation="java.io.File" default-value="${project.basedir}/src/main/resources/bpmn">${camundaBpmnDir}</camundaBpmnDir>
<resultOutputDir implementation="java.io.File" default-value="${project.build.directory}/cbdg/html">${resultOutputDir}</resultOutputDir>
<templateFile implementation="java.io.File" default-value="${project.build.directory}/classes/templates/default.ftl">${templateFile}</templateFile>
Expand Down
Loading

0 comments on commit a5b8f08

Please sign in to comment.