@ -17,10 +17,10 @@ PF4J is an open source (Apache license) lightweight (around 50KB) plugin framewo
Practically PF4J is a microframework and the aim is to keep the core simple but extensible. I try to create a little ecosystem (extensions) based on this core with the help of the comunity.
In above manifest I described a plugin with id `welcome-plugin`, with class `ro.fortsoft.pf4j.demo.welcome.WelcomePlugin`, with version `0.0.1` and with dependencies
to plugins `x, y, z`.
You can define an extension point in your application using **ExtensionPoint** interface marker.
public interface Greeting extends ExtensionPoint {
```java
public interface Greeting extends ExtensionPoint {
public String getGreeting();
public String getGreeting();
}
}
```
Another important internal component is **ExtensionFinder** that describes how the plugin manager discovers extensions for the extensions points.
**DefaultExtensionFinder** looks up extensions using **Extension** annotation.
DefaultExtensionFinder looks up extensions in all extensions index files `META-INF/extensions.idx`. PF4J uses Java Annotation Processing to process at compile time all classes annotated with @Extension and to produce the extensions index file.
public class WelcomePlugin extends Plugin {
```java
public class WelcomePlugin extends Plugin {
public WelcomePlugin(PluginWrapper wrapper) {
super(wrapper);
}
@Extension
public static class WelcomeGreeting implements Greeting {
public WelcomePlugin(PluginWrapper wrapper) {
super(wrapper);
}
public String getGreeting() {
return "Welcome";
}
@Extension
public static class WelcomeGreeting implements Greeting {
public String getGreeting() {
return "Welcome";
}
}
}
```
In above code I supply an extension for the `Greeting` extension point.
You can retrieve all extensions for an extension point with:
You can inject your custom component (for example PluginDescriptorFinder, ExtensionFinder, PluginClasspath, ...) in DefaultPluginManager just override `create...` methods (factory method pattern).