diff options
author | Anindya Chatterjee <anidotnet@gmail.com> | 2017-06-09 16:14:27 +0530 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2017-06-09 13:44:27 +0300 |
commit | 443191d0cc75079099278596c686c29d18cf9a01 (patch) | |
tree | acf6f84d5ed23ebeecf100cf825652c7710103ae | |
parent | 7f4c67ae6f847ee8a5594413b0ece899e3956300 (diff) | |
download | pf4j-443191d0cc75079099278596c686c29d18cf9a01.tar.gz pf4j-443191d0cc75079099278596c686c29d18cf9a01.zip |
Kotlin plugin example added and README updated for Kotlin. (#146)
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | demo_gradle/plugins/plugin3/build.gradle | 49 | ||||
-rw-r--r-- | demo_gradle/plugins/plugin3/src/main/kotlin/ro/fortsoft/pf4j/demo/kotlin/KotlinPlugin.kt | 46 | ||||
-rw-r--r-- | demo_gradle/settings.gradle | 4 |
4 files changed, 105 insertions, 1 deletions
@@ -223,6 +223,13 @@ The `maven-compiler-plugin` can be configured to do this like so: </plugin> ``` +### Kotlin + +PF4J can be used in Kotlin project as well. One has to use the Kotlin annotation processing tool +[**kapt**](https://kotlinlang.org/docs/reference/kapt.html) for the plugin project written in Kotlin. +The demo_gradle project contains one plugin project _plugin3_ written in Kotlin for demonstration. + + Plugin assembly ------------------------------ After you developed a plugin the next step is to deploy it in your application. For this task, one option is to create a zip file with a structure described in section [How to use](https://github.com/decebals/pf4j/blob/master/README.md#how-to-use) from the beginning of the document. diff --git a/demo_gradle/plugins/plugin3/build.gradle b/demo_gradle/plugins/plugin3/build.gradle new file mode 100644 index 0000000..8596512 --- /dev/null +++ b/demo_gradle/plugins/plugin3/build.gradle @@ -0,0 +1,49 @@ +buildscript { + ext.kotlin_version = '1.1.2-2' + + repositories { + mavenCentral() + } + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +jar { + baseName = 'KotlinPlugin' + version = '0.1.0' + manifest { + attributes 'Plugin-Class' : 'ro.fortsoft.pf4j.demo.kotlin.KotlinPlugin', + 'Plugin-Id' : 'KotlinPlugin', + 'Plugin-Version' : '1.0.0', + 'Plugin-Provider' : 'Anindya Chatterjee' + } +} + +task plugin(type: Jar) { + baseName = 'KotlinPlugin' + version = '0.1.0' + into('classes'){ + with jar + } + into('lib'){ + from configurations.compile + } + extension('zip') +} +assemble.dependsOn plugin + +apply plugin: 'kotlin' +apply plugin: 'kotlin-kapt' + +repositories { + mavenCentral() +} + +dependencies { + compileOnly project(':api') + kapt 'ro.fortsoft.pf4j:pf4j:1.+' + compile 'org.apache.commons:commons-lang3:3.0' + testCompile group: 'junit', name: 'junit', version: '4.+' + compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" +} diff --git a/demo_gradle/plugins/plugin3/src/main/kotlin/ro/fortsoft/pf4j/demo/kotlin/KotlinPlugin.kt b/demo_gradle/plugins/plugin3/src/main/kotlin/ro/fortsoft/pf4j/demo/kotlin/KotlinPlugin.kt new file mode 100644 index 0000000..c6a317e --- /dev/null +++ b/demo_gradle/plugins/plugin3/src/main/kotlin/ro/fortsoft/pf4j/demo/kotlin/KotlinPlugin.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ro.fortsoft.pf4j.demo.kotlin + +import org.apache.commons.lang3.StringUtils +import ro.fortsoft.pf4j.Extension +import ro.fortsoft.pf4j.Plugin +import ro.fortsoft.pf4j.PluginWrapper +import ro.fortsoft.pf4j.demo.api.Greeting + +/** + * A sample plugin written in Kotlin + * + * @author Anindya Chatterjee + */ +class KotlinPlugin(wrapper: PluginWrapper) : Plugin(wrapper) { + + override fun start() { + println("KotlinPlugin.start()") + println(StringUtils.upperCase("KotlinPlugin")) + } + + override fun stop() { + println("KotlinPlugin.stop()") + } +} + +@Extension +class KotlinGreeting : Greeting { + override fun getGreeting(): String { + return "KotlinGreetings" + } +} diff --git a/demo_gradle/settings.gradle b/demo_gradle/settings.gradle index e76ea04..8bbcb21 100644 --- a/demo_gradle/settings.gradle +++ b/demo_gradle/settings.gradle @@ -1,4 +1,6 @@ include 'api' include 'app' include 'plugins/plugin1' -include 'plugins/plugin2'
\ No newline at end of file +include 'plugins/plugin2' +include 'plugins/plugin3' + |