diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2017-09-20 16:55:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-20 16:55:30 +0200 |
commit | 5916ee64d9c05a4f085f6f6562ed383ff3203e4a (patch) | |
tree | 0255541afe778984d2becf450ecbb90d97e595d7 /demo/app/src/main/java/org | |
parent | b8cd3af90f8149e5003ea1db395d67b0fa8f7066 (diff) | |
download | pf4j-5916ee64d9c05a4f085f6f6562ed383ff3203e4a.tar.gz pf4j-5916ee64d9c05a4f085f6f6562ed383ff3203e4a.zip |
Change root package from ro.fortsoft.pf4j to org.pf4j (#168)
Diffstat (limited to 'demo/app/src/main/java/org')
-rw-r--r-- | demo/app/src/main/java/org/pf4j/demo/Boot.java | 125 | ||||
-rw-r--r-- | demo/app/src/main/java/org/pf4j/demo/HowdyGreeting.java | 32 | ||||
-rw-r--r-- | demo/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java | 32 |
3 files changed, 189 insertions, 0 deletions
diff --git a/demo/app/src/main/java/org/pf4j/demo/Boot.java b/demo/app/src/main/java/org/pf4j/demo/Boot.java new file mode 100644 index 0000000..76145a4 --- /dev/null +++ b/demo/app/src/main/java/org/pf4j/demo/Boot.java @@ -0,0 +1,125 @@ +/* + * Copyright 2012 Decebal Suiu + * + * 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 org.pf4j.demo; + +import java.util.List; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; + +import org.pf4j.PluginManager; +import org.pf4j.PluginWrapper; +import org.pf4j.demo.api.Greeting; +import org.pf4j.DefaultPluginManager; +import org.pf4j.JarPluginManager; + +/** + * 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(); +// final PluginManager pluginManager = new JarPluginManager(); + + // 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("Extensions added by classpath:"); + Set<String> extensionClassNames = pluginManager.getExtensionClassNames(null); + for (String extension : extensionClassNames) { + System.out.println(" " + extension); + } + + // print extensions ids 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); + } + } + + // print the extensions instances for Greeting extension point for each started plugin + for (PluginWrapper plugin : startedPlugins) { + String pluginId = plugin.getDescriptor().getPluginId(); + System.out.println(String.format("Extensions instances added by plugin '%s' for extension point '%s':", pluginId, Greeting.class.getName())); + List<Greeting> extensions = pluginManager.getExtensions(Greeting.class, pluginId); + for (Object extension : extensions) { + System.out.println(" " + extension); + } + } + + // print extensions instances from classpath (non plugin) + System.out.println("Extensions instances added by classpath:"); + List extensions = pluginManager.getExtensions((String) null); + for (Object extension : extensions) { + System.out.println(" " + extension); + } + + // print extensions instances for each started plugin + for (PluginWrapper plugin : startedPlugins) { + String pluginId = plugin.getDescriptor().getPluginId(); + System.out.println(String.format("Extensions instances added by plugin '%s':", pluginId)); + extensions = pluginManager.getExtensions(pluginId); + for (Object extension : extensions) { + 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/app/src/main/java/org/pf4j/demo/HowdyGreeting.java b/demo/app/src/main/java/org/pf4j/demo/HowdyGreeting.java new file mode 100644 index 0000000..51888b8 --- /dev/null +++ b/demo/app/src/main/java/org/pf4j/demo/HowdyGreeting.java @@ -0,0 +1,32 @@ +/* + * Copyright 2015 Decebal Suiu + * + * 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 org.pf4j.demo; + +import org.pf4j.demo.api.Greeting; + +/** + * A Service Implementation (no @Extension) declared via Java Service Provider mechanism (using META-INF/services). + * + * @author Decebal Suiu + */ +public class HowdyGreeting implements Greeting { + + @Override + public String getGreeting() { + return "Howdy"; + } + +} diff --git a/demo/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java b/demo/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java new file mode 100644 index 0000000..c742127 --- /dev/null +++ b/demo/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014 Decebal Suiu + * + * 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 org.pf4j.demo; + +import org.pf4j.Extension; +import org.pf4j.demo.api.Greeting; + +/** + * @author Decebal Suiu + */ +@Extension +public class WhazzupGreeting implements Greeting { + + @Override + public String getGreeting() { + return "Whazzup"; + } + +} |