-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
684e6ef
commit d1a61f4
Showing
8 changed files
with
136 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGenerator.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,33 @@ | ||
package info.novatec.cbdg.plugin | ||
|
||
import info.novatec.docu.generator.DocuGenerator | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.provider.Property | ||
import java.io.File | ||
|
||
class CamundaBpmnDocumentationGenerator : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
val configuration = project.extensions.create("cbdg", CamundaBpmnDocumentationGeneratorConfiguration::class.java) | ||
configuration.templateFile.convention(project.layout.buildDirectory.file("resources/main/templates/default.ftl").get().asFile) | ||
configuration.camundaBpmnDir.convention(project.layout.buildDirectory.dir("resources/main/bpmn").get().asFile) | ||
configuration.resultOutputDir.convention(project.layout.buildDirectory.dir("cbdg/html").get().asFile) | ||
configuration.bpmnDiagramImageDir?.convention(project.layout.buildDirectory.dir("resources/main/images").get().asFile) | ||
|
||
project.task("generate").doLast { | ||
DocuGenerator().parseAndGenerate( | ||
configuration.templateFile.get(), | ||
configuration.camundaBpmnDir.get(), | ||
configuration.resultOutputDir.get(), | ||
configuration.bpmnDiagramImageDir?.get() | ||
) | ||
} | ||
} | ||
} | ||
|
||
interface CamundaBpmnDocumentationGeneratorConfiguration { | ||
val templateFile: Property<File> | ||
val camundaBpmnDir: Property<File> | ||
val resultOutputDir: Property<File> | ||
val bpmnDiagramImageDir: Property<File>? | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/info/novatec/docu/generator/DocuGenerator.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,57 @@ | ||
package info.novatec.docu.generator | ||
|
||
import info.novatec.cbdg.FreeMarkerService | ||
import info.novatec.docu.parser.main.BpmnParser | ||
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 | ||
|
||
class DocuGenerator { | ||
fun parseAndGenerate( | ||
templateFile: File, | ||
camundaBpmnDir: File, | ||
resultOutputDir: File, | ||
bpmnDiagramImageDir: File? = null | ||
) { | ||
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.") | ||
} | ||
} | ||
|
||
val log = LoggerFactory.getLogger("cbdg") | ||
val parser = BpmnParser() | ||
|
||
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 = parser.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.") | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/test/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGeneratorTest.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,20 @@ | ||
package info.novatec.cbdg.plugin | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
|
||
class CamundaBpmnDocumentationGeneratorTest { | ||
|
||
@Test | ||
fun generateTest() { | ||
val project: Project = ProjectBuilder.builder().build() | ||
|
||
project.getPluginManager().apply("info.novatec.cbdg") | ||
|
||
assertTrue(project.getPluginManager().hasPlugin("info.novatec.cbdg")) | ||
assertNotNull(project.getTasks().getByName("generate")) | ||
} | ||
} |