--- /dev/null
+dependencies {
+ compile 'ro.fortsoft.pf4j:pf4j:0.4'
+ compile 'org.apache.commons:commons-lang3:3.0'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2012 Decebal Suiu
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
+ * the License. You may obtain a copy of the License in the LICENSE file, or 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.api;
+
+import ro.fortsoft.pf4j.ExtensionPoint;
+
+/**
+ * @author Decebal Suiu
+ */
+public interface Greeting extends ExtensionPoint {
+
+ public String getGreeting();
+
+}
--- /dev/null
+dependencies {
+ compile project(':api')
+ compile 'ro.fortsoft.pf4j:pf4j:0.4'
+ compile 'org.apache.commons:commons-lang3:3.0'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
+}
+
+jar {
+ baseName = 'Plugin Demo'
+ version = '0.1.0'
+}
--- /dev/null
+/*\r
+ * Copyright 2012 Decebal Suiu\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with\r
+ * the License. You may obtain a copy of the License in the LICENSE file, or at:\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on\r
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the\r
+ * specific language governing permissions and limitations under the License.\r
+ */\r
+package ro.fortsoft.pf4j.demo;\r
+\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import org.apache.commons.lang.StringUtils;\r
+\r
+import ro.fortsoft.pf4j.DefaultPluginManager;\r
+import ro.fortsoft.pf4j.PluginManager;\r
+import ro.fortsoft.pf4j.PluginWrapper;\r
+import ro.fortsoft.pf4j.demo.api.Greeting;\r
+\r
+/**\r
+ * A boot class that start the demo.\r
+ *\r
+ * @author Decebal Suiu\r
+ */\r
+public class Boot {\r
+\r
+ public static void main(String[] args) {\r
+ // print logo\r
+ printLogo();\r
+\r
+ // create the plugin manager\r
+ final PluginManager pluginManager = new DefaultPluginManager();\r
+\r
+ // load the plugins\r
+ pluginManager.loadPlugins();\r
+\r
+ // enable a disabled plugin\r
+// pluginManager.enablePlugin("welcome-plugin");\r
+\r
+ // start (active/resolved) the plugins\r
+ pluginManager.startPlugins();\r
+\r
+ // retrieves the extensions for Greeting extension point\r
+ List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);\r
+ System.out.println(String.format("Found %d extensions for extension point '%s'", greetings.size(), Greeting.class.getName()));\r
+ for (Greeting greeting : greetings) {\r
+ System.out.println(">>> " + greeting.getGreeting());\r
+ }\r
+\r
+ // print extensions from classpath (non plugin)\r
+ System.out.println(String.format("Extensions added by classpath:"));\r
+ Set<String> extensionClassNames = pluginManager.getExtensionClassNames(null);\r
+ for (String extension : extensionClassNames) {\r
+ System.out.println(" " + extension);\r
+ }\r
+\r
+ // print extensions for each started plugin\r
+ List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();\r
+ for (PluginWrapper plugin : startedPlugins) {\r
+ String pluginId = plugin.getDescriptor().getPluginId();\r
+ System.out.println(String.format("Extensions added by plugin '%s':", pluginId));\r
+ extensionClassNames = pluginManager.getExtensionClassNames(pluginId);\r
+ for (String extension : extensionClassNames) {\r
+ System.out.println(" " + extension);\r
+ }\r
+ }\r
+\r
+ // stop the plugins\r
+ pluginManager.stopPlugins();\r
+ /*\r
+ Runtime.getRuntime().addShutdownHook(new Thread() {\r
+\r
+ @Override\r
+ public void run() {\r
+ pluginManager.stopPlugins();\r
+ }\r
+\r
+ });\r
+ */\r
+ }\r
+\r
+ private static void printLogo() {\r
+ System.out.println(StringUtils.repeat("#", 40));\r
+ System.out.println(StringUtils.center("PF4J-DEMO", 40));\r
+ System.out.println(StringUtils.repeat("#", 40));\r
+ }\r
+\r
+}\r
--- /dev/null
+/*
+ * Copyright 2014 Decebal Suiu
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
+ * the License. You may obtain a copy of the License in the LICENSE file, or 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;
+
+import ro.fortsoft.pf4j.Extension;
+import ro.fortsoft.pf4j.demo.api.Greeting;
+
+/**
+ * @author Decebal Suiu
+ */
+@Extension
+public class WhazzupGreeting implements Greeting {
+
+ @Override
+ public String getGreeting() {
+ return "Whazzup";
+ }
+
+}
--- /dev/null
+log4j.rootLogger=DEBUG, Console
+
+#
+# PF4J log
+#
+log4j.logger.ro.fortsoft.pf4j=DEBUG, Console
+log4j.logger.ro.fortsoft.pf4j.PluginClassLoader=WARN, Console
+log4j.additivity.ro.fortsoft.pf4j=false
+
+#
+# Appenders
+#
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+#log4j.appender.Console.layout.conversionPattern=%-5p - %-32.32c{1} - %m\n
+log4j.appender.Console.layout.ConversionPattern=%d %p %c - %m%n
--- /dev/null
+subprojects {
+ apply plugin: 'java'
+
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ }
+
+
+ task wrapper(type: Wrapper) {
+ gradleVersion = '1.11'
+ }
+}
\ No newline at end of file
--- /dev/null
+########################################
+# - load all plugins except these
+# - add one plugin id on each line
+# - put this file in plugins folder
+########################################
+#welcome-plugin
\ No newline at end of file
--- /dev/null
+########################################
+# - load only these plugins
+# - add one plugin id on each line
+# - put this file in plugins folder
+########################################
+#welcome-plugin
\ No newline at end of file
--- /dev/null
+jar {
+ baseName = 'WelcomePlugin'
+ version = '0.1.0'
+ manifest {
+ attributes 'Plugin-Class' : 'ro.fortsoft.pf4j.demo.welcome.WelcomePlugin',
+ 'Plugin-Id' : 'WelcomePlugin',
+ 'Plugin-Version' : '1.0',
+ 'Plugin-Provider' : 'Yannick Bäumer'
+ }
+}
+
+task plugin(type: Jar) {
+ baseName = 'WelcomePlugin'
+ version = '0.1.0'
+ into('classes')
+ extension('zip')
+ with jar
+}
+
+dependencies {
+ compile project(':api')
+ compile 'ro.fortsoft.pf4j:pf4j:0.4'
+ compile 'org.apache.commons:commons-lang3:3.0'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
+}
\ No newline at end of file
--- /dev/null
+plugin.id=welcome-plugin
+plugin.class=ro.fortsoft.pf4j.demo.welcome.WelcomePlugin
+plugin.version=0.0.1
+plugin.provider=Decebal Suiu
+plugin.dependencies=
--- /dev/null
+/*
+ * Copyright 2012 Decebal Suiu
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
+ * the License. You may obtain a copy of the License in the LICENSE file, or 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.welcome;
+
+import org.apache.commons.lang.StringUtils;
+
+import ro.fortsoft.pf4j.Extension;
+import ro.fortsoft.pf4j.Plugin;
+import ro.fortsoft.pf4j.PluginWrapper;
+import ro.fortsoft.pf4j.RuntimeMode;
+import ro.fortsoft.pf4j.demo.api.Greeting;
+
+/**
+ * @author Decebal Suiu
+ */
+public class WelcomePlugin extends Plugin {
+
+ public WelcomePlugin(PluginWrapper wrapper) {
+ super(wrapper);
+ }
+
+ @Override
+ public void start() {
+ System.out.println("WelcomePlugin.start()");
+ // for testing the development mode
+ if (RuntimeMode.DEVELOPMENT.equals(wrapper.getRuntimeMode())) {
+ System.out.println(StringUtils.upperCase("WelcomePlugin"));
+ }
+ }
+
+ @Override
+ public void stop() {
+ System.out.println("WelcomePlugin.stop()");
+ }
+
+ @Extension
+ public static class WelcomeGreeting implements Greeting {
+
+ @Override
+ public String getGreeting() {
+ return "Welcome";
+ }
+
+ }
+
+}
--- /dev/null
+jar {
+ baseName = 'HelloPlugin'
+ version = '0.1.0'
+ manifest {
+ attributes 'Plugin-Class' : 'ro.fortsoft.pf4j.demo.welcome.HelloPlugin',
+ 'Plugin-Id' : 'HelloPlugin',
+ 'Plugin-Version' : '1.0',
+ 'Plugin-Provider' : 'Yannick Bäumer'
+ }
+}
+
+task plugin(type: Jar) {
+ baseName = 'HelloPlugin'
+ version = '0.1.0'
+ into('classes')
+ extension('zip')
+ with jar
+}
+
+dependencies {
+ compile project(':api')
+ compile 'ro.fortsoft.pf4j:pf4j:0.4'
+ compile 'org.apache.commons:commons-lang3:3.0'
+ testCompile group: 'junit', name: 'junit', version: '4.+'
+}
\ No newline at end of file
--- /dev/null
+plugin.id=hello-plugin
+plugin.class=ro.fortsoft.pf4j.demo.hello.HelloPlugin
+plugin.version=0.0.1
+plugin.provider=Decebal Suiu
+plugin.dependencies=
--- /dev/null
+/*
+ * Copyright 2012 Decebal Suiu
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with
+ * the License. You may obtain a copy of the License in the LICENSE file, or 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.hello;
+
+import ro.fortsoft.pf4j.Extension;
+import ro.fortsoft.pf4j.Plugin;
+import ro.fortsoft.pf4j.PluginWrapper;
+import ro.fortsoft.pf4j.demo.api.Greeting;
+
+/**
+ * A very simple plugin.
+ *
+ * @author Decebal Suiu
+ */
+public class HelloPlugin extends Plugin {
+
+ public HelloPlugin(PluginWrapper wrapper) {
+ super(wrapper);
+ }
+
+ @Override
+ public void start() {
+ System.out.println("HelloPlugin.start()");
+ }
+
+ @Override
+ public void stop() {
+ System.out.println("HelloPlugin.stop()");
+ }
+
+ @Extension(ordinal=1)
+ public static class HelloGreeting implements Greeting {
+
+ @Override
+ public String getGreeting() {
+ return "Hello";
+ }
+
+ }
+
+}
--- /dev/null
+include 'api'
+include 'app'
+include 'plugins'
\ No newline at end of file