Create working example of external module

This commit is contained in:
2020-03-09 21:12:15 +01:00
parent dcdecee28f
commit 8ca966b376
9 changed files with 113 additions and 29 deletions

View File

@@ -15,6 +15,9 @@ repositories {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
compileOnly(group: 'org.pf4j', name: 'pf4j', version: "3.2.0") {
exclude group: "org.slf4j"
}
}
compileKotlin {

View File

@@ -0,0 +1,11 @@
package io.smnp.ext
import io.smnp.callable.function.Function
import io.smnp.callable.method.Method
import org.pf4j.ExtensionPoint
interface ModuleDefinition : ExtensionPoint {
fun modulePath(): String
fun functions(): List<Function>
fun methods(): List<Method>
}

View File

@@ -10,7 +10,6 @@ subprojects {
}
}
// plugin location
ext.pluginsDir = rootProject.buildDir.path + '/modules'
group 'io.bartek'

View File

@@ -1,25 +0,0 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm'
}
group 'io.bartek'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

61
modules/lang/build.gradle Normal file
View File

@@ -0,0 +1,61 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm'
id 'kotlin-kapt'
}
group 'io.bartek'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
jar {
manifest {
attributes 'Plugin-Id': "${pluginId}",
'Plugin-Class': "${pluginClass}",
'Plugin-Version': "${pluginVersion}",
'Plugin-Provider': "${pluginProvider}",
'Plugin-Dependencies': "${pluginDependencies}"
}
}
task plugin(type: Jar) {
archiveBaseName = "plugin-${pluginId}"
into('classes') {
with jar
}
into('lib') {
from configurations.compile
}
archiveExtension = 'zip'
}
task assemblePlugin(type: Copy) {
from plugin
into pluginsDir
}
dependencies {
// compileOnly important!!! We do not want to put the api into the zip file since the main program has it already!
compileOnly project(':api')
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
kapt(group: 'org.pf4j', name: 'pf4j', version: "3.2.0")
compileOnly(group: 'org.pf4j', name: 'pf4j', version: "3.2.0") {
exclude group: "org.slf4j"
}
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
testCompile group: 'junit', name: 'junit', version: '4.+'
}

View File

@@ -0,0 +1,7 @@
version=0.0.1
pluginVersion=0.1
pluginId=smnp.lang
pluginClass=
pluginProvider=Bartłomiej Pluta
pluginDependencies=

View File

@@ -0,0 +1,16 @@
package io.smnp.ext.lang
import io.smnp.callable.function.Function
import io.smnp.callable.function.FunctionDefinitionTool
import io.smnp.callable.signature.Signature.Companion.vararg
import io.smnp.type.matcher.Matcher.Companion.allTypes
import io.smnp.type.model.Value
class DisplayFunction : Function("println") {
override fun define(new: FunctionDefinitionTool) {
new function vararg(allTypes()) define { _, v ->
println(v.joinToString("") { it.toString() })
Value.void()
}
}
}

View File

@@ -0,0 +1,14 @@
package io.smnp.ext.lang
import io.smnp.callable.method.Method
import io.smnp.ext.ModuleDefinition
import org.pf4j.Extension
@Extension
class LangModule : ModuleDefinition {
override fun modulePath() = "smnp.io"
override fun functions() = listOf(DisplayFunction())
override fun methods() = emptyList<Method>()
}

View File

@@ -3,6 +3,4 @@ include 'api'
include 'app'
include 'modules'
//include 'modules:A'
//include 'modules:B'
//include 'modules:C'
include 'modules:lang'