From d95b2385959e7d564e04ff71f377297321ddf14e Mon Sep 17 00:00:00 2001 From: Konstantin Wiens Date: Fri, 10 Mar 2023 12:19:35 +0100 Subject: [PATCH] #51: Provide a gradle plugin --- build.gradle.kts | 12 ++++++++++ .../CamundaBpmnDocumentationGenerator.kt | 23 +++++++++++++++++++ .../CamundaBpmnDocumentationGeneratorTest.kt | 20 ++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 src/main/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGenerator.kt create mode 100644 src/test/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGeneratorTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index 937a296..8e31898 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,6 +4,7 @@ plugins { java `maven-publish` + `java-gradle-plugin` id("com.diffplug.spotless") version "6.12.0" id("org.jetbrains.kotlin.jvm") version "1.8.10" id("org.jlleitschuh.gradle.ktlint") version "11.2.0" @@ -25,6 +26,8 @@ dependencies { compileOnly("org.apache.maven.plugin-tools:maven-plugin-annotations:3.7.1") implementation("org.freemarker:freemarker:2.3.32") dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.7.20") + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.2") } publishing { @@ -58,3 +61,12 @@ configure { ktlint() } } + +gradlePlugin { + plugins { + create("CamundaBpmnDocumentationGenerator") { + id = "info.novatec.cbdg" + implementationClass = "info.novatec.cbdg.plugin.CamundaBpmnDocumentationGenerator" + } + } +} diff --git a/src/main/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGenerator.kt b/src/main/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGenerator.kt new file mode 100644 index 0000000..cf15e5b --- /dev/null +++ b/src/main/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGenerator.kt @@ -0,0 +1,23 @@ +package info.novatec.cbdg.plugin + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.provider.Property + +interface CamundaBpmnDocumentationGeneratorConfiguration { + val message: Property +} + +class CamundaBpmnDocumentationGenerator : Plugin { + + override fun apply(project: Project) { + // Add the 'greeting' extension object + val configuration = project.extensions.create("bu", CamundaBpmnDocumentationGeneratorConfiguration::class.java) + configuration.message.convention("Bu Ga Ga!") + // Add a task that uses configuration from the extension object + + project.task("generate").doLast { + println(configuration.message.get()) + } + } +} diff --git a/src/test/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGeneratorTest.kt b/src/test/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGeneratorTest.kt new file mode 100644 index 0000000..7e46f4f --- /dev/null +++ b/src/test/kotlin/info/novatec/cbdg/plugin/CamundaBpmnDocumentationGeneratorTest.kt @@ -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 greetingTest() { + val project: Project = ProjectBuilder.builder().build() + + project.getPluginManager().apply("info.novatec.cbdg") + + assertTrue(project.getPluginManager().hasPlugin("info.novatec.cbdg")) + assertNotNull(project.getTasks().getByName("generate")) + } +}