Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support any interface as an ExtensionPoint #350

Merged
merged 1 commit into from Nov 15, 2019
Merged

Support any interface as an ExtensionPoint #350

merged 1 commit into from Nov 15, 2019

Conversation

decebals
Copy link
Member

For more information about this feature, please read #289.

@decebals
Copy link
Member Author

  1. How it works

This feature is not enabled by default. To activate this feature you must use pf4j.ignoreExtensionPoint flag (option in ExtensionAnnotationProcessor).
If you use Maven, set this flag via compiler arguments

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <compilerArgs>
            <arg>-Apf4j.ignoreExtensionPoint</arg>
        </compilerArgs>
    </configuration>
</plugin>
  1. Show me the code

The Greeting interface from demo was modified

public interface Greeting /*extends ExtensionPoint*/ {

    String getGreeting();

}

NOTE Don't forget to activate this feature via pf4j.ignoreExtensionPoint option in ExtensionAnnotationProcessor.

  1. Constraints

If the class annotated with @Extension doesn't implement any interface

@Extension
public static class WelcomeGreeting /*implements Greeting*/ {

    /*@Override*/
    public String getGreeting() {
        return "Welcome";
    }

}

then ExtensionAnnotationProcessor will throw an error when the application is compiled

Error:(36, 19) java: com.mycompany.welcome.WelcomePlugin.WelcomeGreeting is not an extension (it doesn't implement any interface)

If the class annotated with @Extension implements multiple interface

@Extension
public static class WelcomeGreeting implements Greeting, AnInterface {

    @Override
    public String getGreeting() {
        return "Welcome";
    }

}

then ExtensionAnnotationProcessor will throw an error when the application is compiled

Error:(36, 19) java: com.mycompany.welcome.WelcomePlugin.WelcomeGreeting is not an extension (it implements multiple interfaces)

@decebals decebals merged commit 45eeec8 into master Nov 15, 2019
claymccoy added a commit to claymccoy/kork that referenced this pull request Dec 16, 2019
This is done in order to use the following pf4j feature with a configurable extension.
"Support any interface as an ExtensionPoint" pf4j/pf4j#350

This is nice because I can extend something that is not an extension point, and even do it in safe mode. The problem is that now my extension can only have one interface. So I can't use the ConfigurableExtension directly. I can only have one interface unless pf4j is modified to allow more.
Using my one super class slot for configuration is still not ideal, but it works. It might be nice to allow some other mechanism for config other than class hierarchy or modify pf4j to handle config natively.
mergify bot pushed a commit to spinnaker/kork that referenced this pull request Dec 18, 2019
This is done in order to use the following pf4j feature with a configurable extension.
"Support any interface as an ExtensionPoint" pf4j/pf4j#350

This is nice because I can extend something that is not an extension point, and even do it in safe mode. The problem is that now my extension can only have one interface. So I can't use the ConfigurableExtension directly. I can only have one interface unless pf4j is modified to allow more.
Using my one super class slot for configuration is still not ideal, but it works. It might be nice to allow some other mechanism for config other than class hierarchy or modify pf4j to handle config natively.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant