aboutsummaryrefslogtreecommitdiffstats
path: root/demo_gradle/app
diff options
context:
space:
mode:
authorStix <stix@phcn.de>2015-03-01 17:24:43 +0100
committerStix <stix@phcn.de>2015-03-01 17:24:43 +0100
commit0b3ac7fa749e188abbbfd21a550183bfcbbcb8f3 (patch)
treec8a07bf4ef7957e50182e99d8d43fd721f8556cb /demo_gradle/app
parent07d115c456266ba5c0a83e393927e4264c2ff160 (diff)
downloadpf4j-0b3ac7fa749e188abbbfd21a550183bfcbbcb8f3.tar.gz
pf4j-0b3ac7fa749e188abbbfd21a550183bfcbbcb8f3.zip
added base files
Diffstat (limited to 'demo_gradle/app')
-rw-r--r--demo_gradle/app/.gitignore1
-rw-r--r--demo_gradle/app/build.gradle11
-rw-r--r--demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/Boot.java93
-rw-r--r--demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/WhazzupGreeting.java29
-rw-r--r--demo_gradle/app/src/main/resources/log4j.properties16
5 files changed, 150 insertions, 0 deletions
diff --git a/demo_gradle/app/.gitignore b/demo_gradle/app/.gitignore
new file mode 100644
index 0000000..378eac2
--- /dev/null
+++ b/demo_gradle/app/.gitignore
@@ -0,0 +1 @@
+build
diff --git a/demo_gradle/app/build.gradle b/demo_gradle/app/build.gradle
new file mode 100644
index 0000000..22145d8
--- /dev/null
+++ b/demo_gradle/app/build.gradle
@@ -0,0 +1,11 @@
+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'
+}
diff --git a/demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/Boot.java b/demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/Boot.java
new file mode 100644
index 0000000..2619531
--- /dev/null
+++ b/demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/Boot.java
@@ -0,0 +1,93 @@
+/*
+ * 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;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+
+import ro.fortsoft.pf4j.DefaultPluginManager;
+import ro.fortsoft.pf4j.PluginManager;
+import ro.fortsoft.pf4j.PluginWrapper;
+import ro.fortsoft.pf4j.demo.api.Greeting;
+
+/**
+ * A boot class that start the demo.
+ *
+ * @author Decebal Suiu
+ */
+public class Boot {
+
+ public static void main(String[] args) {
+ // print logo
+ printLogo();
+
+ // create the plugin manager
+ final PluginManager pluginManager = new DefaultPluginManager();
+
+ // load the plugins
+ pluginManager.loadPlugins();
+
+ // enable a disabled plugin
+// pluginManager.enablePlugin("welcome-plugin");
+
+ // start (active/resolved) the plugins
+ pluginManager.startPlugins();
+
+ // retrieves the extensions for Greeting extension point
+ List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);
+ System.out.println(String.format("Found %d extensions for extension point '%s'", greetings.size(), Greeting.class.getName()));
+ for (Greeting greeting : greetings) {
+ System.out.println(">>> " + greeting.getGreeting());
+ }
+
+ // print extensions from classpath (non plugin)
+ System.out.println(String.format("Extensions added by classpath:"));
+ Set<String> extensionClassNames = pluginManager.getExtensionClassNames(null);
+ for (String extension : extensionClassNames) {
+ System.out.println(" " + extension);
+ }
+
+ // print extensions for each started plugin
+ List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
+ for (PluginWrapper plugin : startedPlugins) {
+ String pluginId = plugin.getDescriptor().getPluginId();
+ System.out.println(String.format("Extensions added by plugin '%s':", pluginId));
+ extensionClassNames = pluginManager.getExtensionClassNames(pluginId);
+ for (String extension : extensionClassNames) {
+ System.out.println(" " + extension);
+ }
+ }
+
+ // stop the plugins
+ pluginManager.stopPlugins();
+ /*
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+
+ @Override
+ public void run() {
+ pluginManager.stopPlugins();
+ }
+
+ });
+ */
+ }
+
+ private static void printLogo() {
+ System.out.println(StringUtils.repeat("#", 40));
+ System.out.println(StringUtils.center("PF4J-DEMO", 40));
+ System.out.println(StringUtils.repeat("#", 40));
+ }
+
+}
diff --git a/demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/WhazzupGreeting.java b/demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/WhazzupGreeting.java
new file mode 100644
index 0000000..9cf7e35
--- /dev/null
+++ b/demo_gradle/app/src/main/java/ro/fortsoft/pf4j/demo/WhazzupGreeting.java
@@ -0,0 +1,29 @@
+/*
+ * 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";
+ }
+
+}
diff --git a/demo_gradle/app/src/main/resources/log4j.properties b/demo_gradle/app/src/main/resources/log4j.properties
new file mode 100644
index 0000000..16ce034
--- /dev/null
+++ b/demo_gradle/app/src/main/resources/log4j.properties
@@ -0,0 +1,16 @@
+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