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

annotation processor creates wrong files under certain conditions #264

Closed
pinhead84 opened this Issue Dec 27, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@pinhead84
Copy link
Contributor

pinhead84 commented Dec 27, 2018

I'm currently migrating my application from JPF to pf4j and discovered a problem in the ExtensionAnnotationProcessor in combination with the ServiceProviderExtensionStorage.

I'm using the following pattern to define extension points and extensions:

pf4j-extensions

In contrast to your examples there are abstract classes (MainMenuAdapter, BootAdapter) for each available extension point. The extensions are derived from these abstract classes instead of the extension point interfaces (MainMenuExtensionPoint, BootExtensionPoint). This gives a bit more flexibility, because later added methods in an extension point can be implemented in the abstract classes without the need of modifying the extension points in all plugins. From my experience in certain projects this is a quite common pattern - similar to the java.awt.event.WindowListener / java.awt.event.WindowAdapter approach in the Java classpath.

Basically this approach also works with pf4j. But the ExtensionAnnotationProcessor in combination with the ServiceProviderExtensionStorage doesn't behave as expected in this scenario. For the above scenario the following files are generated:

META-INF/services/com.example.api.BootAdapter
META-INF/services/com.example.api.MainMenuAdapter

Instead the ExtensionAnnotationProcessor should create these files:

META-INF/services/com.example.api.BootExtensionPoint
META-INF/services/com.example.api.MainMenuExtensionPoint

Because of this problem the PluginManager is not able to load the extensions by its interface via pluginManager.getExtensions(BootExtensionPoint.class). Instead I would have to call pluginManager.getExtensions(BootAdapter.class).

I'm going to propose a pull request with a possible workaround for this problem.

pinhead84 added a commit to pinhead84/pf4j that referenced this issue Dec 27, 2018

explicitly configure extension points for an extension
This is a workaround for issue pf4j#264. An extension may provide its implemented extension points explicitly through its annotation. In this case the annotation processor does not try to detect the extension points for an extension automatically (which fails under certain conditions).
@decebals

This comment has been minimized.

Copy link
Member

decebals commented Dec 28, 2018

Thanks again for detailed explanation. Now, the case with adapters doesn't work. The adapters are see as extensions by PF4J.
Your approach proposed in #265 is good. The same approach I use in Pippo to declare extensions.
So, after some reviews and comments, #265 will be merged and the issue will be resolved.

@pinhead84

This comment has been minimized.

Copy link
Contributor Author

pinhead84 commented Jan 4, 2019

Thanks for merging my pull request. I will close this issue accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment