-
Notifications
You must be signed in to change notification settings - Fork 470
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
Refactor DefaultImapDecoderFactory
to Use POJO Style and Constructo…
#2410
base: master
Are you sure you want to change the base?
Conversation
…r Injection - Updated `DefaultImapDecoderFactory` to adhere to POJO design principles. - Replaced internal `ImapParserFactory` creation with constructor injection of `UnpooledStatusResponseFactory`. - Improved decoupling and maintainability by explicitly managing dependencies via the constructor. - Updated class and method documentation to reflect changes and clarify the role of the factory. This change enhances the clarity and testability of the `DefaultImapDecoderFactory` by removing direct dependency creation and enforcing a cleaner, more modular structure.
Hello, I am currently reviewing Apache James for developing a mail engine. While forking the source, I noticed a simple TO-DO comment and made a commit request. Starting from 2025, we plan to use Apache James extensively. If given the opportunity, I would like to contribute significantly to its improvements. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello. Thank you for the contribution, happy to see you so interested in using and contributing more to james in a near future. Welcome!
Comment below
* | ||
* @param unpooledStatusResponseFactory The factory for creating status responses. | ||
*/ | ||
public DefaultImapDecoderFactory(UnpooledStatusResponseFactory unpooledStatusResponseFactory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That code is very old... Aint very sure about this part but problems I can see:
- several test classes depend on DefaultImapDecoderFactory.buildImapDecoder() . This change without being adapted is definitely gonna break them
- have a look in
IMAPServerModule
. The DefaultImapDecoder is being provided by building directly it, not passing by the Factory. It would make sense maybe to do a refactoring there as well. - you might want to pass the ImapCommandParserFactory as an argument too (to use in IMAPServerModule)
- you could maybe have a static method that would return a default imap encoder (as of now) just for tests purposes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. I will check if it's possible to refactor based on what you mentioned.
Thank you for the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, don't hesitate to ask if you got issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, added a default constructor for DefaultImapDecoderFactory.
This addition enhances flexibility by allowing other classes to use the default constructor.
Additionally, added another constructor that accepts an implementation of StatusResponseFactory.
This change is to provide flexibility for the ResponseFactory in DefaultImapDecoderFactory in the future.
Also modified two other test classes to use the constructor-based approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The continuous-integration/jenkins/pr-merge failed. I will check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THis is great! Happy to further hear about your use cases and welcome onboard the community.
So as this very changeset I cannot say better than @Arsnael ;-)
…ility Updated DefaultImapDecoderFactory to use a generic type T for flexibility, allowing any implementation of StatusResponseFactory. Introduced a parameterized constructor that accepts an instance of StatusResponseFactory to facilitate various implementations. Retained the default constructor, which now initializes with UnpooledStatusResponseFactory as the default implementation. Enhanced modularity by enabling constructor injection, improving decoupling, and reducing hardcoded dependencies. Updated class and method documentation to reflect the use of generics and the new constructor design. Modified IMAPHealthCheckTest and IMAPServerTest to replace static function calls with instance creation using the new keyword, enhancing readability and flexibility in test code. This change improves the flexibility and reusability of the DefaultImapDecoderFactory by supporting multiple StatusResponseFactory implementations while maintaining a default behavior. Additionally, it improves test code clarity by using a more explicit object creation approach.
# Conflicts: # protocols/imap/src/main/java/org/apache/james/imap/main/DefaultImapDecoderFactory.java
@@ -0,0 +1,39 @@ | |||
package org.apache.james.imap.main; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THis file misses the compulsory ASF V2 license
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the ASF license notice to the source files. Please feel free to review and let me know if there are any concerns. Thank you! !
Add ASF license notice to source files
*/ | ||
public DefaultImapDecoderFactory(StatusResponseFactory statusResponseFactory) { | ||
this.statusResponseFactory = statusResponseFactory; | ||
this.imapCommandParserFactory = new ImapParserFactory(statusResponseFactory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary, you should pass that as an argument as well, and not building the default (that you can pass via your DefaultImapDecoderFactory()
constructor)
3 Checkstyle issues in the build. What IDE are you using btw? i personally use Intellij and it allows to navigate easily in the project. Also you can have a plugin to apply and check the checkstyle (to make sure it respects a certain number of coding rules within the project). Checkstyle file used by James is at the root f the project: https://github.com/apache/james-project/blob/master/checkstyle.xml Also I don't see a refactoring in IMAPServerModule to use the factory for building the DefaultImapDecoder? |
I also use IntelliJ. Thank you. If you have any references that I can refer to, I would appreciate it |
Applied DefaultImapDecoderFactory to IMAPServerModule and enforced code style
// Build an ImapDecoder using the factory and assert it's not null | ||
ImapDecoder decoder = factory.buildImapDecoder(); | ||
assertNotNull(decoder, "ImapDecoder instance should not be null"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a unit test for the constructor public DefaultImapDecoderFactory(ImapCommandParserFactory imapCommandParserFactory, StatusResponseFactory statusResponseFactory)
and I think it should be alright for me
06:36:13,438 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.3.0:check (check-style) on project protocols-imap: You have 1 Checkstyle violation. -> [Help 1] Still one checkstyle issue somewhere :) |
Why all the indents? Can you not change that please? Thanks |
DefaultImapDecoderFactoryTest code convention
After applying the Code Style in my IntelliJ, the code style was applied to the source I modified, and the indentation was updated. I will rollback if it causes any issues. The process of checking Code Style during the build was a refreshing experience for me. |
…r Injection
DefaultImapDecoderFactory
to adhere to POJO design principles.ImapParserFactory
creation with constructor injection ofUnpooledStatusResponseFactory
.This change enhances the clarity and testability of the
DefaultImapDecoderFactory
by removing direct dependency creation and enforcing a cleaner, more modular structure.