aboutsummaryrefslogtreecommitdiffstats
path: root/demo/gradle/app
diff options
context:
space:
mode:
authorSebastian Schuberth <sschuberth@users.noreply.github.com>2024-06-23 21:59:16 +0200
committerGitHub <noreply@github.com>2024-06-23 22:59:16 +0300
commitacf0a9f26190c49f508c5b187e9f2c671874d90d (patch)
tree51bb14d9e752983b752c1da97ec8910f5160d0c7 /demo/gradle/app
parent1f303dafb976fb9121da871973a293d09fdee755 (diff)
downloadpf4j-acf0a9f26190c49f508c5b187e9f2c671874d90d.tar.gz
pf4j-acf0a9f26190c49f508c5b187e9f2c671874d90d.zip
Consolidate demo projects in the "demo" directory (#584)
Diffstat (limited to 'demo/gradle/app')
-rw-r--r--demo/gradle/app/.gitignore1
-rw-r--r--demo/gradle/app/build.gradle35
-rw-r--r--demo/gradle/app/src/main/java/org/pf4j/demo/Boot.java112
-rw-r--r--demo/gradle/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java32
-rw-r--r--demo/gradle/app/src/main/resources/log4j.properties16
5 files changed, 196 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..eaab92a
--- /dev/null
+++ b/demo/gradle/app/build.gradle
@@ -0,0 +1,35 @@
+apply plugin: 'application'
+
+mainClassName = 'org.pf4j.demo.Boot'
+run {
+ systemProperty 'pf4j.pluginsDir', '../build/plugins'
+}
+
+dependencies {
+ implementation project(':api')
+ implementation group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}"
+ annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}")
+ implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
+ implementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
+
+ testImplementation group: 'junit', name: 'junit', version: '4.+'
+}
+
+task uberjar(type: Jar, dependsOn: ['compileJava']) {
+ zip64 true
+ from configurations.runtimeClasspath.asFileTree.files.collect {
+ exclude "META-INF/*.SF"
+ exclude "META-INF/*.DSA"
+ exclude "META-INF/*.RSA"
+ zipTree(it)
+ }
+ from files(sourceSets.main.output.classesDirs)
+ from files(sourceSets.main.resources)
+ manifest {
+ attributes 'Main-Class': mainClassName
+ }
+
+ archiveBaseName = "${project.name}-plugin-demo"
+ archiveClassifier = "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
new file mode 100644
index 0000000..ebc5c31
--- /dev/null
+++ b/demo/gradle/app/src/main/java/org/pf4j/demo/Boot.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2012-present the original author or authors.
+ *
+ * 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.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;
+import org.pf4j.PluginManager;
+import org.pf4j.PluginWrapper;
+import org.pf4j.demo.api.Greeting;
+
+import java.util.List;
+
+/**
+ * A boot class that start the demo.
+ *
+ * @author Decebal Suiu
+ */
+public class Boot {
+ private static final Logger logger = LoggerFactory.getLogger(Boot.class);
+
+ public static void main(String[] args) {
+ // print logo
+ printLogo();
+
+ // create the plugin manager
+ 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();
+
+ // enable a disabled plugin
+// pluginManager.enablePlugin("welcome-plugin");
+
+ // start (active/resolved) the plugins
+ pluginManager.startPlugins();
+
+ logger.info("Plugindirectory: ");
+ logger.info("\t" + System.getProperty("pf4j.pluginsDir", "plugins") + "\n");
+
+ // retrieves the extensions for Greeting extension point
+ List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);
+ logger.info(String.format("Found %d extensions for extension point '%s'", greetings.size(), Greeting.class.getName()));
+ for (Greeting greeting : greetings) {
+ logger.info(">>> " + greeting.getGreeting());
+ }
+
+ // // print extensions from classpath (non plugin)
+ // logger.info(String.format("Extensions added by classpath:"));
+ // Set<String> extensionClassNames = pluginManager.getExtensionClassNames(null);
+ // for (String extension : extensionClassNames) {
+ // logger.info(" " + extension);
+ // }
+
+ // print extensions for each started plugin
+ List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
+ for (PluginWrapper plugin : startedPlugins) {
+ String pluginId = plugin.getDescriptor().getPluginId();
+ logger.info(String.format("Extensions added by plugin '%s':", pluginId));
+ // extensionClassNames = pluginManager.getExtensionClassNames(pluginId);
+ // for (String extension : extensionClassNames) {
+ // logger.info(" " + extension);
+ // }
+ }
+
+ // stop the plugins
+ pluginManager.stopPlugins();
+ /*
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+
+ @Override
+ public void run() {
+ pluginManager.stopPlugins();
+ }
+
+ });
+ */
+ }
+
+ private static void printLogo() {
+ logger.info(StringUtils.repeat("#", 40));
+ logger.info(StringUtils.center("PF4J-DEMO", 40));
+ logger.info(StringUtils.repeat("#", 40));
+ }
+
+}
diff --git a/demo/gradle/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java b/demo/gradle/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java
new file mode 100644
index 0000000..1341b77
--- /dev/null
+++ b/demo/gradle/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2012-present the original author or authors.
+ *
+ * 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";
+ }
+
+}
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..f42e226
--- /dev/null
+++ b/demo/gradle/app/src/main/resources/log4j.properties
@@ -0,0 +1,16 @@
+log4j.rootLogger=DEBUG, Console
+
+#
+# PF4J log
+#
+log4j.logger.org.pf4j=DEBUG, Console
+log4j.logger.org.pf4j.PluginClassLoader=WARN, Console
+log4j.additivity.org.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