summaryrefslogtreecommitdiffstats
path: root/demo_gradle
diff options
context:
space:
mode:
authorCesar Andres <cesar.vera-bernal@lucidworks.com>2017-10-21 15:52:17 -0500
committerDecebal Suiu <decebal.suiu@gmail.com>2017-10-21 23:52:17 +0300
commit468abf3490028bbce5cf748d76cc22b73dab2d15 (patch)
tree47c6695bf579388858c789f7d71741247bf4cc18 /demo_gradle
parent42aaee15591e241add08323c76f4f813867f996b (diff)
downloadpf4j-468abf3490028bbce5cf748d76cc22b73dab2d15.tar.gz
pf4j-468abf3490028bbce5cf748d76cc22b73dab2d15.zip
ISSUE-169: fix gradle demo (#177)
Diffstat (limited to 'demo_gradle')
-rw-r--r--demo_gradle/README.md62
-rw-r--r--demo_gradle/api/build.gradle5
-rw-r--r--demo_gradle/app/build.gradle31
-rw-r--r--demo_gradle/app/src/main/java/org/pf4j/demo/Boot.java14
-rw-r--r--demo_gradle/build.gradle30
-rw-r--r--demo_gradle/gradle.properties2
-rw-r--r--demo_gradle/plugins/build.gradle32
-rw-r--r--demo_gradle/plugins/plugin1/build.gradle38
-rw-r--r--demo_gradle/plugins/plugin1/gradle.properties6
-rw-r--r--demo_gradle/plugins/plugin1/plugin.properties5
-rw-r--r--demo_gradle/plugins/plugin2/build.gradle38
-rw-r--r--demo_gradle/plugins/plugin2/gradle.properties6
-rw-r--r--demo_gradle/plugins/plugin2/plugin.properties5
-rw-r--r--demo_gradle/plugins/plugin3/build.gradle55
-rw-r--r--demo_gradle/plugins/plugin3/gradle.properties6
-rw-r--r--demo_gradle/settings.gradle9
16 files changed, 198 insertions, 146 deletions
diff --git a/demo_gradle/README.md b/demo_gradle/README.md
new file mode 100644
index 0000000..6851fc0
--- /dev/null
+++ b/demo_gradle/README.md
@@ -0,0 +1,62 @@
+# PF4J Gradle Demo
+
+This demo assumes that you know the basics of Gradle (Please look at [gradle](https://gradle.org/) for more info)
+
+### Setup/Build
+
+1. Clone the repo
+2. Go to demo_gradle `cd demo_gradle`
+3. run `gradle build`
+
+* This will produce one jar, named app-plugin-demo-uberjar.jar, located in the `app/build/libs/` directory and three plugins zips located in `build/plugins` directory.
+* The plugins are `plugin-hello-plugin-0.0.1.zip`, `plugin-KotlinPlugin-1.0.0.zip` and `plugin-welcome-plugin-0.0.1.zip`
+
+### Run the demo
+
+1. Run
+
+```
+ java -jar -Dpf4j.pluginsDir=build/plugins app/build/libs/app-plugin-demo-uberjar.jar
+```
+
+* pf4j.pluginsDir: is where the plugins are located
+
+2. The demo's output should look similar to: (Please see `Boot#main()` for more details)
+```
+demo_gradle $ java -jar -Dpf4j.pluginsDir=build/plugins app/build/libs/app-plugin-demo-uberjar.jar
+[main] INFO org.pf4j.demo.Boot - ########################################
+[main] INFO org.pf4j.demo.Boot - PF4J-DEMO
+[main] INFO org.pf4j.demo.Boot - ########################################
+[main] INFO org.pf4j.DefaultPluginStatusProvider - Enabled plugins: []
+[main] INFO org.pf4j.DefaultPluginStatusProvider - Disabled plugins: []
+[main] INFO org.pf4j.DefaultPluginManager - PF4J version 0.0.0 in 'deployment' mode
+[main] INFO org.pf4j.AbstractPluginManager - Plugin 'welcome-plugin@0.0.1' resolved
+[main] INFO org.pf4j.AbstractPluginManager - Plugin 'KotlinPlugin@1.0.0' resolved
+[main] INFO org.pf4j.AbstractPluginManager - Plugin 'hello-plugin@0.0.1' resolved
+[main] INFO org.pf4j.AbstractPluginManager - Start plugin 'welcome-plugin@0.0.1'
+[main] INFO org.pf4j.demo.welcome.WelcomePlugin - WelcomePlugin.start()
+[main] INFO org.pf4j.demo.welcome.WelcomePlugin - WELCOMEPLUGIN
+[main] INFO org.pf4j.AbstractPluginManager - Start plugin 'KotlinPlugin@1.0.0'
+[main] INFO org.pf4j.demo.kotlin.KotlinPlugin - KotlinPlugin.start()
+[main] INFO org.pf4j.demo.kotlin.KotlinPlugin - KOTLINPLUGIN
+[main] INFO org.pf4j.AbstractPluginManager - Start plugin 'hello-plugin@0.0.1'
+[main] INFO org.pf4j.demo.hello.HelloPlugin - HelloPlugin.start()
+[main] INFO org.pf4j.demo.Boot - Plugindirectory:
+[main] INFO org.pf4j.demo.Boot - build/plugins
+
+[main] INFO org.pf4j.demo.Boot - Found 3 extensions for extension point 'org.pf4j.demo.api.Greeting'
+[main] INFO org.pf4j.demo.Boot - >>> Whazzup
+[main] INFO org.pf4j.demo.Boot - >>> Welcome
+[main] INFO org.pf4j.demo.Boot - >>> Hello
+[main] INFO org.pf4j.demo.Boot - Extensions added by plugin 'welcome-plugin':
+[main] INFO org.pf4j.demo.Boot - Extensions added by plugin 'KotlinPlugin':
+[main] INFO org.pf4j.demo.Boot - Extensions added by plugin 'hello-plugin':
+[main] INFO org.pf4j.AbstractPluginManager - Stop plugin 'hello-plugin@0.0.1'
+[main] INFO org.pf4j.demo.hello.HelloPlugin - HelloPlugin.stop()
+[main] INFO org.pf4j.AbstractPluginManager - Stop plugin 'KotlinPlugin@1.0.0'
+[main] INFO org.pf4j.demo.kotlin.KotlinPlugin - KotlinPlugin.stop()
+[main] INFO org.pf4j.AbstractPluginManager - Stop plugin 'welcome-plugin@0.0.1'
+[main] INFO org.pf4j.demo.welcome.WelcomePlugin - WelcomePlugin.stop()
+
+```
+
diff --git a/demo_gradle/api/build.gradle b/demo_gradle/api/build.gradle
index 12a46bf..0d3ca62 100644
--- a/demo_gradle/api/build.gradle
+++ b/demo_gradle/api/build.gradle
@@ -1,5 +1,6 @@
dependencies {
- compile 'org.pf4j:pf4j:2.0.0-SNAPSHOT'
- compile 'org.apache.commons:commons-lang3:3.0'
+ compile group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}"
+ compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
+
testCompile group: 'junit', name: 'junit', version: '4.+'
}
diff --git a/demo_gradle/app/build.gradle b/demo_gradle/app/build.gradle
index 9f3d5a4..4761092 100644
--- a/demo_gradle/app/build.gradle
+++ b/demo_gradle/app/build.gradle
@@ -3,14 +3,29 @@ apply plugin: 'application'
mainClassName = 'org.pf4j.demo.Boot'
dependencies {
- compile project(':api')
- compile 'org.pf4j:pf4j:2.0.0-SNAPSHOT'
- compile 'org.apache.commons:commons-lang3:3.5'
- testCompile group: 'junit', name: 'junit', version: '4.+'
- compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
+ compile project(':api')
+ compile group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}"
+ compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
+ compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
+
+ testCompile group: 'junit', name: 'junit', version: '4.+'
}
-jar {
- baseName = 'Plugin Demo'
- version = '0.1.0'
+task uberjar(type: Jar, dependsOn: ['compileJava']) {
+ zip64 true
+ from configurations.runtime.asFileTree.files.collect {
+ exclude "META-INF/*.SF"
+ exclude "META-INF/*.DSA"
+ exclude "META-INF/*.RSA"
+ zipTree(it)
+ }
+ from files(sourceSets.main.output.classesDir)
+ from files(sourceSets.main.resources)
+ manifest {
+ attributes 'Main-Class': mainClassName
+ }
+
+ baseName = "${project.name}-plugin-demo"
+ classifier = "uberjar"
}
+
diff --git a/demo_gradle/app/src/main/java/org/pf4j/demo/Boot.java b/demo_gradle/app/src/main/java/org/pf4j/demo/Boot.java
index 46261d6..9343f4a 100644
--- a/demo_gradle/app/src/main/java/org/pf4j/demo/Boot.java
+++ b/demo_gradle/app/src/main/java/org/pf4j/demo/Boot.java
@@ -16,6 +16,9 @@
package org.pf4j.demo;
import org.apache.commons.lang3.StringUtils;
+import org.pf4j.CompoundPluginDescriptorFinder;
+import org.pf4j.ManifestPluginDescriptorFinder;
+import org.pf4j.PropertiesPluginDescriptorFinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.pf4j.DefaultPluginManager;
@@ -38,7 +41,16 @@ public class Boot {
printLogo();
// create the plugin manager
- final PluginManager pluginManager = new DefaultPluginManager();
+ final PluginManager pluginManager = new DefaultPluginManager() {
+ @Override
+ protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
+ return new CompoundPluginDescriptorFinder()
+ // Demo is using the Manifest file
+ // PropertiesPluginDescriptorFinder is commented out just to avoid error log
+ //.add(new PropertiesPluginDescriptorFinder())
+ .add(new ManifestPluginDescriptorFinder());
+ }
+ };
// load the plugins
pluginManager.loadPlugins();
diff --git a/demo_gradle/build.gradle b/demo_gradle/build.gradle
index d86746d..9968360 100644
--- a/demo_gradle/build.gradle
+++ b/demo_gradle/build.gradle
@@ -1,26 +1,14 @@
subprojects {
- apply plugin: 'java'
+ apply plugin: 'java'
- repositories {
- mavenLocal()
- mavenCentral()
- }
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ }
}
+// plugin location
+ext.pluginsDir = rootProject.buildDir.path + '/plugins'
+
+task build(dependsOn: [':app:uberjar'])
-task copyPlugins() {
- doLast {
- delete 'app/plugins'
- mkdir 'app/plugins'
- subprojects.each { p ->
- if (p.path.contains(":plugins/")) {
- System.out.println("Copying plugin from " + p.path);
- copy {
- from p.projectDir.toString() + '/build/libs'
- into 'app/plugins'
- include '*.zip'
- }
- }
- }
- }
-}
diff --git a/demo_gradle/gradle.properties b/demo_gradle/gradle.properties
new file mode 100644
index 0000000..177f36b
--- /dev/null
+++ b/demo_gradle/gradle.properties
@@ -0,0 +1,2 @@
+# PF4J
+pf4jVersion=2.0.0
diff --git a/demo_gradle/plugins/build.gradle b/demo_gradle/plugins/build.gradle
new file mode 100644
index 0000000..104b17d
--- /dev/null
+++ b/demo_gradle/plugins/build.gradle
@@ -0,0 +1,32 @@
+subprojects {
+ jar {
+ manifest {
+ attributes 'Plugin-Class': "${pluginClass}",
+ 'Plugin-Id': "${pluginId}",
+ 'Plugin-Version': "${version}",
+ 'Plugin-Provider': "${pluginProvider}"
+ }
+ }
+
+ task plugin(type: Jar) {
+ baseName = "plugin-${pluginId}"
+ into('classes') {
+ with jar
+ }
+ into('lib') {
+ from configurations.compile
+ }
+ extension('zip')
+ }
+
+ task assemblePlugin(type: Copy) {
+ from plugin
+ into pluginsDir
+ }
+}
+
+task assemblePlugins(type: Copy) {
+ dependsOn subprojects.assemblePlugin
+}
+
+build.dependsOn project.tasks.assemblePlugins
diff --git a/demo_gradle/plugins/plugin1/build.gradle b/demo_gradle/plugins/plugin1/build.gradle
index 6a9d507..69791a7 100644
--- a/demo_gradle/plugins/plugin1/build.gradle
+++ b/demo_gradle/plugins/plugin1/build.gradle
@@ -1,33 +1,9 @@
-jar {
- baseName = 'WelcomePlugin'
- version = '0.1.0'
- manifest {
- attributes 'Plugin-Class': 'org.pf4j.demo.welcome.WelcomePlugin',
- 'Plugin-Id': 'WelcomePlugin',
- 'Plugin-Version': '1.0.0',
- 'Plugin-Provider': 'Decebal Suiu'
- }
-}
-
-task plugin(type: Jar) {
- baseName = 'WelcomePlugin'
- version = '0.1.0'
- into('classes') {
- with jar
- }
- into('lib') {
- from configurations.compile
- }
- extension('zip')
-}
-assemble.dependsOn plugin
-
dependencies {
- compileOnly project(':api')
- // compileOnly important!!! We do not want to put the api into the zip file since the main program has it already!
- compile('org.pf4j:pf4j:2.0.0-SNAPSHOT') {
- exclude group: "org.slf4j"
- }
- compile 'org.apache.commons:commons-lang3:3.5'
- testCompile group: 'junit', name: 'junit', version: '4.+'
+ // compileOnly important!!! We do not want to put the api into the zip file since the main program has it already!
+ compileOnly project(':api')
+ compileOnly(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") {
+ exclude group: "org.slf4j"
+ }
+ compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
}
diff --git a/demo_gradle/plugins/plugin1/gradle.properties b/demo_gradle/plugins/plugin1/gradle.properties
new file mode 100644
index 0000000..2edd800
--- /dev/null
+++ b/demo_gradle/plugins/plugin1/gradle.properties
@@ -0,0 +1,6 @@
+version=0.0.1
+
+pluginId=welcome-plugin
+pluginClass=org.pf4j.demo.welcome.WelcomePlugin
+pluginProvider=Decebal Suiu
+pluginDependencies=
diff --git a/demo_gradle/plugins/plugin1/plugin.properties b/demo_gradle/plugins/plugin1/plugin.properties
deleted file mode 100644
index 9da9bcc..0000000
--- a/demo_gradle/plugins/plugin1/plugin.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-plugin.id=welcome-plugin
-plugin.class=org.pf4j.demo.welcome.WelcomePlugin
-plugin.version=0.0.1
-plugin.provider=Decebal Suiu
-plugin.dependencies=
diff --git a/demo_gradle/plugins/plugin2/build.gradle b/demo_gradle/plugins/plugin2/build.gradle
index da75a55..69791a7 100644
--- a/demo_gradle/plugins/plugin2/build.gradle
+++ b/demo_gradle/plugins/plugin2/build.gradle
@@ -1,33 +1,9 @@
-jar {
- baseName = 'HelloPlugin'
- version = '0.1.0'
- manifest {
- attributes 'Plugin-Class': 'org.pf4j.demo.hello.HelloPlugin',
- 'Plugin-Id': 'HelloPlugin',
- 'Plugin-Version': '1.0.0',
- 'Plugin-Provider': 'Decebal Suiu'
- }
-}
-
-task plugin(type: Jar) {
- baseName = 'HelloPlugin'
- version = '0.1.0'
- into('classes') {
- with jar
- }
- into('lib') {
- from configurations.compile
- }
- extension('zip')
-}
-assemble.dependsOn plugin
-
dependencies {
- compileOnly project(':api')
- // compileOnly important!!! We do not want to put the api into the zip file since the main program has it already!
- compile('org.pf4j:pf4j:2.0.0-SNAPSHOT') {
- exclude group: "org.slf4j"
- }
- compile 'org.apache.commons:commons-lang3:3.5'
- testCompile group: 'junit', name: 'junit', version: '4.+'
+ // compileOnly important!!! We do not want to put the api into the zip file since the main program has it already!
+ compileOnly project(':api')
+ compileOnly(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") {
+ exclude group: "org.slf4j"
+ }
+ compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
}
diff --git a/demo_gradle/plugins/plugin2/gradle.properties b/demo_gradle/plugins/plugin2/gradle.properties
new file mode 100644
index 0000000..ef70127
--- /dev/null
+++ b/demo_gradle/plugins/plugin2/gradle.properties
@@ -0,0 +1,6 @@
+version=0.0.1
+
+pluginId=hello-plugin
+pluginClass=org.pf4j.demo.hello.HelloPlugin
+pluginProvider=Decebal Suiu
+pluginDependencies=
diff --git a/demo_gradle/plugins/plugin2/plugin.properties b/demo_gradle/plugins/plugin2/plugin.properties
deleted file mode 100644
index 60b6f33..0000000
--- a/demo_gradle/plugins/plugin2/plugin.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-plugin.id=hello-plugin
-plugin.class=org.pf4j.demo.hello.HelloPlugin
-plugin.version=0.0.1
-plugin.provider=Decebal Suiu
-plugin.dependencies=
diff --git a/demo_gradle/plugins/plugin3/build.gradle b/demo_gradle/plugins/plugin3/build.gradle
index 69afeab..c360e23 100644
--- a/demo_gradle/plugins/plugin3/build.gradle
+++ b/demo_gradle/plugins/plugin3/build.gradle
@@ -1,51 +1,28 @@
buildscript {
- ext.kotlin_version = '1.1.2-2'
+ 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': 'org.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')
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
}
-assemble.dependsOn plugin
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
repositories {
- mavenCentral()
+ mavenCentral()
}
dependencies {
- compileOnly project(':api')
- kapt('org.pf4j:pf4j:2.0.0-SNAPSHOT') {
- exclude group: "org.slf4j"
- }
- compile 'org.apache.commons:commons-lang3:3.5'
- testCompile group: 'junit', name: 'junit', version: '4.+'
- compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
+ compileOnly project(':api')
+ compileOnly(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") {
+ exclude group: "org.slf4j"
+ }
+ compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
+ compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
+
+ testCompile group: 'junit', name: 'junit', version: '4.+'
}
diff --git a/demo_gradle/plugins/plugin3/gradle.properties b/demo_gradle/plugins/plugin3/gradle.properties
new file mode 100644
index 0000000..a04b609
--- /dev/null
+++ b/demo_gradle/plugins/plugin3/gradle.properties
@@ -0,0 +1,6 @@
+version=1.0.0
+
+pluginId=KotlinPlugin
+pluginClass=org.pf4j.demo.kotlin.KotlinPlugin
+pluginProvider=Anindya Chatterjee
+pluginDependencies=
diff --git a/demo_gradle/settings.gradle b/demo_gradle/settings.gradle
index 7ee71ba..828e80a 100644
--- a/demo_gradle/settings.gradle
+++ b/demo_gradle/settings.gradle
@@ -1,5 +1,8 @@
include 'api'
include 'app'
-include 'plugins/plugin1'
-include 'plugins/plugin2'
-include 'plugins/plugin3'
+
+include 'plugins'
+
+include 'plugins:plugin1'
+include 'plugins:plugin2'
+include 'plugins:plugin3'