diff options
Diffstat (limited to 'demo/maven')
23 files changed, 921 insertions, 0 deletions
diff --git a/demo/maven/api/pom.xml b/demo/maven/api/pom.xml new file mode 100644 index 0000000..615aa30 --- /dev/null +++ b/demo/maven/api/pom.xml @@ -0,0 +1,37 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-parent</artifactId> + <version>3.12.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>pf4j-demo-api</artifactId> + <version>3.12.0-SNAPSHOT</version> + <packaging>jar</packaging> + <name>Demo Api</name> + + <build> + <plugins> + <plugin> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.pf4j</groupId> + <artifactId>pf4j</artifactId> + <version>${project.version}</version> + <!-- !!! VERY IMPORTANT --> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> diff --git a/demo/maven/api/src/main/java/org/pf4j/demo/api/DemoPlugin.java b/demo/maven/api/src/main/java/org/pf4j/demo/api/DemoPlugin.java new file mode 100644 index 0000000..a2f76fc --- /dev/null +++ b/demo/maven/api/src/main/java/org/pf4j/demo/api/DemoPlugin.java @@ -0,0 +1,35 @@ +/* + * 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.api; + +import org.pf4j.Plugin; + +/** + * Base {@link Plugin} for all demo plugins. + * + * @author Decebal Suiu + */ +public abstract class DemoPlugin extends Plugin { + + protected final PluginContext context; + + protected DemoPlugin(PluginContext context) { + super(); + + this.context = context; + } + +} diff --git a/demo/maven/api/src/main/java/org/pf4j/demo/api/Greeting.java b/demo/maven/api/src/main/java/org/pf4j/demo/api/Greeting.java new file mode 100644 index 0000000..828d61b --- /dev/null +++ b/demo/maven/api/src/main/java/org/pf4j/demo/api/Greeting.java @@ -0,0 +1,27 @@ +/* + * 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.api; + +import org.pf4j.ExtensionPoint; + +/** + * @author Decebal Suiu + */ +public interface Greeting extends ExtensionPoint { + + String getGreeting(); + +} diff --git a/demo/maven/api/src/main/java/org/pf4j/demo/api/PluginContext.java b/demo/maven/api/src/main/java/org/pf4j/demo/api/PluginContext.java new file mode 100644 index 0000000..0a7506f --- /dev/null +++ b/demo/maven/api/src/main/java/org/pf4j/demo/api/PluginContext.java @@ -0,0 +1,39 @@ +/* + * 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.api; + +import org.pf4j.RuntimeMode; + +/** + * An instance of this class is provided to plugins in their constructor. + * It's safe for plugins to keep a reference to the instance for later use. + * This class facilitates communication with application and plugin manager. + * + * @author Decebal Suiu + */ +public class PluginContext { + + private final RuntimeMode runtimeMode; + + public PluginContext(RuntimeMode runtimeMode) { + this.runtimeMode = runtimeMode; + } + + public RuntimeMode getRuntimeMode() { + return runtimeMode; + } + +} diff --git a/demo/maven/app/pom.xml b/demo/maven/app/pom.xml new file mode 100644 index 0000000..963bb60 --- /dev/null +++ b/demo/maven/app/pom.xml @@ -0,0 +1,92 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-parent</artifactId> + <version>3.12.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>pf4j-demo-app</artifactId> + <version>3.12.0-SNAPSHOT</version> + <packaging>jar</packaging> + <name>Demo App</name> + + <properties> + <main.class>org.pf4j.demo.Boot</main.class> + </properties> + + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.3</version> + <configuration> + <descriptors> + <descriptor>src/main/assembly/assembly.xml</descriptor> + </descriptors> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>attached</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <classpathPrefix>lib/</classpathPrefix> + <mainClass>${main.class}</mainClass> + </manifest> + </archive> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.pf4j</groupId> + <artifactId>pf4j</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-api</artifactId> + <version>${project.version}</version> + </dependency> + + <!-- Logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>${slf4j.version}</version> + </dependency> + + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + </dependencies> + +</project> diff --git a/demo/maven/app/src/main/assembly/assembly.xml b/demo/maven/app/src/main/assembly/assembly.xml new file mode 100644 index 0000000..77c66b4 --- /dev/null +++ b/demo/maven/app/src/main/assembly/assembly.xml @@ -0,0 +1,37 @@ +<!-- + Describes the dist + + @author Decebal Suiu + @version 1.0 +--> +<assembly> + <id>app</id> + <formats> + <format>dir</format> + <format>zip</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <dependencySets> + <dependencySet> + <useProjectArtifact>false</useProjectArtifact> + <outputDirectory>lib</outputDirectory> + <includes> + <include>*:jar:*</include> + </includes> + </dependencySet> + </dependencySets> + <fileSets> + <fileSet> + <directory>${project.build.directory}</directory> + <outputDirectory></outputDirectory> + <includes> + <include>*.jar</include> + </includes> + <excludes> + <exclude>*-javadoc.jar</exclude> + <exclude>*-sources.jar</exclude> + </excludes> + </fileSet> + </fileSets> +</assembly> + diff --git a/demo/maven/app/src/main/java/org/pf4j/demo/Boot.java b/demo/maven/app/src/main/java/org/pf4j/demo/Boot.java new file mode 100644 index 0000000..d101104 --- /dev/null +++ b/demo/maven/app/src/main/java/org/pf4j/demo/Boot.java @@ -0,0 +1,131 @@ +/* + * 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.lang.StringUtils; +import org.pf4j.PluginManager; +import org.pf4j.PluginWrapper; +import org.pf4j.demo.api.Greeting; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Set; + +/** + * A boot class that start the demo. + * + * @author Decebal Suiu + */ +public class Boot { + + private static final Logger log = LoggerFactory.getLogger(Boot.class); + + public static void main(String[] args) { + // print logo + printLogo(); + + // create the plugin manager + PluginManager pluginManager = new DemoPluginManager(); + + // 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); + log.info("Found {} extensions for extension point '{}'", greetings.size(), Greeting.class.getName()); + for (Greeting greeting : greetings) { + log.info(">>> {}", greeting.getGreeting()); + } + + // print extensions from classpath (non plugin) + log.info("Extensions added by classpath:"); + Set<String> extensionClassNames = pluginManager.getExtensionClassNames(null); + for (String extension : extensionClassNames) { + log.info(" {}", extension); + } + + log.info("Extension classes by classpath:"); + List<Class<? extends Greeting>> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class); + for (Class<? extends Greeting> greeting : greetingsClasses) { + log.info(" Class: {}", greeting.getCanonicalName()); + } + + // print extensions ids for each started plugin + List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins(); + for (PluginWrapper plugin : startedPlugins) { + String pluginId = plugin.getDescriptor().getPluginId(); + log.info("Extensions added by plugin '{}}':", pluginId); + extensionClassNames = pluginManager.getExtensionClassNames(pluginId); + for (String extension : extensionClassNames) { + log.info(" {}", extension); + } + } + + // print the extensions instances for Greeting extension point for each started plugin + for (PluginWrapper plugin : startedPlugins) { + String pluginId = plugin.getDescriptor().getPluginId(); + log.info("Extensions instances added by plugin '{}' for extension point '{}':", pluginId, Greeting.class.getName()); + List<Greeting> extensions = pluginManager.getExtensions(Greeting.class, pluginId); + for (Object extension : extensions) { + log.info(" {}", extension); + } + } + + // print extensions instances from classpath (non plugin) + log.info("Extensions instances added by classpath:"); + List<?> extensions = pluginManager.getExtensions((String) null); + for (Object extension : extensions) { + log.info(" {}", extension); + } + + // print extensions instances for each started plugin + for (PluginWrapper plugin : startedPlugins) { + String pluginId = plugin.getDescriptor().getPluginId(); + log.info("Extensions instances added by plugin '{}':", pluginId); + extensions = pluginManager.getExtensions(pluginId); + for (Object extension : extensions) { + log.info(" {}", extension); + } + } + + // stop the plugins + pluginManager.stopPlugins(); + /* + Runtime.getRuntime().addShutdownHook(new Thread() { + + @Override + public void run() { + pluginManager.stopPlugins(); + } + + }); + */ + } + + private static void printLogo() { + log.info(StringUtils.repeat("#", 40)); + log.info(StringUtils.center("PF4J-DEMO", 40)); + log.info(StringUtils.repeat("#", 40)); + } + +} diff --git a/demo/maven/app/src/main/java/org/pf4j/demo/DemoPluginFactory.java b/demo/maven/app/src/main/java/org/pf4j/demo/DemoPluginFactory.java new file mode 100644 index 0000000..bdae2d6 --- /dev/null +++ b/demo/maven/app/src/main/java/org/pf4j/demo/DemoPluginFactory.java @@ -0,0 +1,43 @@ +/* + * 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 java.lang.reflect.Constructor; +import org.pf4j.DefaultPluginFactory; +import org.pf4j.Plugin; +import org.pf4j.PluginWrapper; +import org.pf4j.demo.api.PluginContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class DemoPluginFactory extends DefaultPluginFactory { + + private static final Logger log = LoggerFactory.getLogger(DemoPluginFactory.class); + + @Override + protected Plugin createInstance(Class<?> pluginClass, PluginWrapper pluginWrapper) { + PluginContext context = new PluginContext(pluginWrapper.getRuntimeMode()); + try { + Constructor<?> constructor = pluginClass.getConstructor(PluginContext.class); + return (Plugin) constructor.newInstance(context); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + + return null; + } + +} diff --git a/demo/maven/app/src/main/java/org/pf4j/demo/DemoPluginManager.java b/demo/maven/app/src/main/java/org/pf4j/demo/DemoPluginManager.java new file mode 100644 index 0000000..2571a3e --- /dev/null +++ b/demo/maven/app/src/main/java/org/pf4j/demo/DemoPluginManager.java @@ -0,0 +1,42 @@ +/* + * 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.DefaultExtensionFinder; +import org.pf4j.DefaultPluginFactory; +import org.pf4j.DefaultPluginManager; +import org.pf4j.ExtensionFinder; +import org.pf4j.PluginFactory; + +class DemoPluginManager extends DefaultPluginManager { + + // Use below code if you want to enable ServiceProviderExtensionFinder + /* + @Override + protected ExtensionFinder createExtensionFinder() { + DefaultExtensionFinder extensionFinder = (DefaultExtensionFinder) super.createExtensionFinder(); + extensionFinder.addServiceProviderExtensionFinder(); // to activate "HowdyGreeting" extension + + return extensionFinder; + } + */ + + @Override + protected PluginFactory createPluginFactory() { + return new DemoPluginFactory(); + } + +} diff --git a/demo/maven/app/src/main/java/org/pf4j/demo/HowdyGreeting.java b/demo/maven/app/src/main/java/org/pf4j/demo/HowdyGreeting.java new file mode 100644 index 0000000..050934d --- /dev/null +++ b/demo/maven/app/src/main/java/org/pf4j/demo/HowdyGreeting.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.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/maven/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java b/demo/maven/app/src/main/java/org/pf4j/demo/WhazzupGreeting.java new file mode 100644 index 0000000..1341b77 --- /dev/null +++ b/demo/maven/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/maven/app/src/main/resources/META-INF/services/org.pf4j.demo.api.Greeting b/demo/maven/app/src/main/resources/META-INF/services/org.pf4j.demo.api.Greeting new file mode 100644 index 0000000..615a943 --- /dev/null +++ b/demo/maven/app/src/main/resources/META-INF/services/org.pf4j.demo.api.Greeting @@ -0,0 +1 @@ +org.pf4j.demo.HowdyGreeting diff --git a/demo/maven/app/src/main/resources/simplelogger.properties b/demo/maven/app/src/main/resources/simplelogger.properties new file mode 100755 index 0000000..40302dd --- /dev/null +++ b/demo/maven/app/src/main/resources/simplelogger.properties @@ -0,0 +1,39 @@ +# SLF4J's SimpleLogger configuration file +# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err. + +# Default logging detail level for all instances of SimpleLogger. +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, defaults to "info". +org.slf4j.simpleLogger.defaultLogLevel=debug + +# Logging detail level for a SimpleLogger instance named "xxxxx". +# Must be one of ("trace", "debug", "info", "warn", or "error"). +# If not specified, the default logging detail level is used. +#org.slf4j.simpleLogger.log.xxxxx= +# !!! Uncomment below loggers when you are in trouble +#org.slf4j.simpleLogger.log.org.pf4j.PluginClassLoader=trace +#org.slf4j.simpleLogger.log.org.pf4j.AbstractExtensionFinder=trace + +# Set to true if you want the current date and time to be included in output messages. +# Default is false, and will output the number of milliseconds elapsed since startup. +#org.slf4j.simpleLogger.showDateTime=false +org.slf4j.simpleLogger.showDateTime=true + +# The date and time format to be used in the output messages. +# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat. +# If the format is not specified or is invalid, the default format is used. +# The default format is yyyy-MM-dd HH:mm:ss:SSS Z. +#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z +org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss + +# Set to true if you want to output the current thread name. +# Defaults to true. +#org.slf4j.simpleLogger.showThreadName=true + +# Set to true if you want the Logger instance name to be included in output messages. +# Defaults to true. +#org.slf4j.simpleLogger.showLogName=true + +# Set to true if you want the last component of the name to be included in output messages. +# Defaults to false. +#org.slf4j.simpleLogger.showShortLogName=false diff --git a/demo/maven/plugins/disabled.txt b/demo/maven/plugins/disabled.txt new file mode 100644 index 0000000..45f1801 --- /dev/null +++ b/demo/maven/plugins/disabled.txt @@ -0,0 +1,6 @@ +######################################## +# - load all plugins except these +# - add one plugin id on each line +# - put this file in plugins folder +######################################## +#welcome-plugin diff --git a/demo/maven/plugins/enabled.txt b/demo/maven/plugins/enabled.txt new file mode 100644 index 0000000..3d76b2f --- /dev/null +++ b/demo/maven/plugins/enabled.txt @@ -0,0 +1,6 @@ +######################################## +# - load only these plugins +# - add one plugin id on each line +# - put this file in plugins folder +######################################## +#welcome-plugin diff --git a/demo/maven/plugins/plugin1/plugin.properties b/demo/maven/plugins/plugin1/plugin.properties new file mode 100644 index 0000000..9da9bcc --- /dev/null +++ b/demo/maven/plugins/plugin1/plugin.properties @@ -0,0 +1,5 @@ +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/maven/plugins/plugin1/pom.xml b/demo/maven/plugins/plugin1/pom.xml new file mode 100644 index 0000000..5873fdd --- /dev/null +++ b/demo/maven/plugins/plugin1/pom.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-plugins</artifactId> + <version>3.12.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>pf4j-demo-plugin1</artifactId> + <version>3.12.0-SNAPSHOT</version> + <packaging>jar</packaging> + <name>Demo Plugin #1</name> + + <properties> + <plugin.id>welcome-plugin</plugin.id> + <plugin.class>org.pf4j.demo.welcome.WelcomePlugin</plugin.class> + <plugin.version>0.0.1</plugin.version> + <plugin.provider>Decebal Suiu</plugin.provider> + <plugin.dependencies /> + </properties> + + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + </dependency> + </dependencies> + +</project> diff --git a/demo/maven/plugins/plugin1/src/main/java/org/pf4j/demo/welcome/WelcomePlugin.java b/demo/maven/plugins/plugin1/src/main/java/org/pf4j/demo/welcome/WelcomePlugin.java new file mode 100644 index 0000000..3064902 --- /dev/null +++ b/demo/maven/plugins/plugin1/src/main/java/org/pf4j/demo/welcome/WelcomePlugin.java @@ -0,0 +1,58 @@ +/* + * 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.welcome; + +import org.apache.commons.lang.StringUtils; +import org.pf4j.Extension; +import org.pf4j.RuntimeMode; +import org.pf4j.demo.api.DemoPlugin; +import org.pf4j.demo.api.Greeting; +import org.pf4j.demo.api.PluginContext; + +/** + * @author Decebal Suiu + */ +public class WelcomePlugin extends DemoPlugin { + + public WelcomePlugin(PluginContext context) { + super(context); + } + + @Override + public void start() { + log.info("WelcomePlugin.start()"); + // for testing the development mode + if (RuntimeMode.DEVELOPMENT.equals(context.getRuntimeMode())) { + log.info(StringUtils.upperCase("WelcomePlugin")); + } + } + + @Override + public void stop() { + log.info("WelcomePlugin.stop()"); + } + + @Extension + public static class WelcomeGreeting implements Greeting { + + @Override + public String getGreeting() { + return "Welcome"; + } + + } + +} diff --git a/demo/maven/plugins/plugin2/plugin.properties b/demo/maven/plugins/plugin2/plugin.properties new file mode 100644 index 0000000..60b6f33 --- /dev/null +++ b/demo/maven/plugins/plugin2/plugin.properties @@ -0,0 +1,5 @@ +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/maven/plugins/plugin2/pom.xml b/demo/maven/plugins/plugin2/pom.xml new file mode 100644 index 0000000..82ed985 --- /dev/null +++ b/demo/maven/plugins/plugin2/pom.xml @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-plugins</artifactId> + <version>3.12.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>pf4j-demo-plugin2</artifactId> + <version>3.12.0-SNAPSHOT</version> + <packaging>jar</packaging> + <name>Demo Plugin #2</name> + + <properties> + <plugin.id>hello-plugin</plugin.id> + <plugin.class>org.pf4j.demo.hello.HelloPlugin</plugin.class> + <plugin.version>0.0.1</plugin.version> + <plugin.provider>Decebal Suiu</plugin.provider> + <plugin.dependencies /> + </properties> + +</project> diff --git a/demo/maven/plugins/plugin2/src/main/java/org/pf4j/demo/hello/HelloPlugin.java b/demo/maven/plugins/plugin2/src/main/java/org/pf4j/demo/hello/HelloPlugin.java new file mode 100644 index 0000000..ed67878 --- /dev/null +++ b/demo/maven/plugins/plugin2/src/main/java/org/pf4j/demo/hello/HelloPlugin.java @@ -0,0 +1,54 @@ +/* + * 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.hello; + +import org.pf4j.Extension; +import org.pf4j.demo.api.DemoPlugin; +import org.pf4j.demo.api.Greeting; +import org.pf4j.demo.api.PluginContext; + +/** + * A very simple plugin. + * + * @author Decebal Suiu + */ +public class HelloPlugin extends DemoPlugin { + + public HelloPlugin(PluginContext context) { + super(context); + } + + @Override + public void start() { + log.info("HelloPlugin.start()"); + } + + @Override + public void stop() { + log.info("HelloPlugin.stop()"); + } + + @Extension(ordinal=1) + public static class HelloGreeting implements Greeting { + + @Override + public String getGreeting() { + return "Hello"; + } + + } + +} diff --git a/demo/maven/plugins/pom.xml b/demo/maven/plugins/pom.xml new file mode 100644 index 0000000..13d41f6 --- /dev/null +++ b/demo/maven/plugins/pom.xml @@ -0,0 +1,99 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-parent</artifactId> + <version>3.12.0-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>pf4j-demo-plugins</artifactId> + <version>3.12.0-SNAPSHOT</version> + <packaging>pom</packaging> + <name>Demo Plugins Parent</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + + <!-- Override below properties in each plugin's pom.xml --> + <plugin.id /> + <plugin.class /> + <plugin.version /> + <plugin.provider /> + <plugin.dependencies /> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-assembly-plugin</artifactId> + <version>3.1.0</version> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + <finalName>${project.artifactId}-${project.version}-all</finalName> + <appendAssemblyId>false</appendAssemblyId> + <attach>false</attach> + <archive> + <manifest> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> + </manifest> + <manifestEntries> + <Plugin-Id>${plugin.id}</Plugin-Id> + <Plugin-Version>${plugin.version}</Plugin-Version> + <Plugin-Provider>${plugin.provider}</Plugin-Provider> + <Plugin-Class>${plugin.class}</Plugin-Class> + <Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies> + </manifestEntries> + </archive> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + <version>2.8.2</version> + </plugin> + </plugins> + </build> + + <modules> + <module>plugin1</module> + <module>plugin2</module> + </modules> + + <dependencies> + <dependency> + <groupId>org.pf4j</groupId> + <artifactId>pf4j</artifactId> + <version>${project.version}</version> + <!-- !!! VERY IMPORTANT --> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-api</artifactId> + <version>${project.version}</version> + <!-- !!! VERY IMPORTANT --> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> diff --git a/demo/maven/pom.xml b/demo/maven/pom.xml new file mode 100644 index 0000000..36a0738 --- /dev/null +++ b/demo/maven/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <parent> + <groupId>org.pf4j</groupId> + <artifactId>pf4j-parent</artifactId> + <version>3.12.0-SNAPSHOT</version> + <relativePath>../..</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.pf4j.demo</groupId> + <artifactId>pf4j-demo-parent</artifactId> + <version>3.12.0-SNAPSHOT</version> + <packaging>pom</packaging> + <name>Demo Parent</name> + + <properties> + <javadoc.disabled>true</javadoc.disabled> + <deploy.disabled>true</deploy.disabled> + <source.disabled>true</source.disabled> + </properties> + + <build> + <resources> + <resource> + <filtering>false</filtering> + <directory>src/main/java</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + <resource> + <directory>src/main/resources</directory> + </resource> + </resources> + </build> + + <modules> + <module>app</module> + <module>api</module> + <module>plugins</module> + </modules> + +</project> |