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

Refactor DefaultImapDecoderFactory to Use POJO Style and Constructo… #2410

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

superbAura
Copy link

…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.

…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.
@superbAura
Copy link
Author

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!

Copy link
Contributor

@Arsnael Arsnael left a 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) {
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Author

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

Copy link
Author

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.

Copy link
Contributor

@chibenwa chibenwa left a 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 ;-)

superbAura and others added 8 commits September 19, 2024 15:21
…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;
Copy link
Contributor

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

Copy link
Author

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! !

*/
public DefaultImapDecoderFactory(StatusResponseFactory statusResponseFactory) {
this.statusResponseFactory = statusResponseFactory;
this.imapCommandParserFactory = new ImapParserFactory(statusResponseFactory);
Copy link
Contributor

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)

@Arsnael
Copy link
Contributor

Arsnael commented Sep 20, 2024

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?

@superbAura
Copy link
Author

I also use IntelliJ.
@Arsnael
I will improve the factory and builder pattern in the IMAPServerModule module.

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");
}
Copy link
Contributor

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

@Arsnael
Copy link
Contributor

Arsnael commented Sep 20, 2024

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 :)

@Arsnael
Copy link
Contributor

Arsnael commented Sep 20, 2024

Why all the indents? Can you not change that please? Thanks

@superbAura
Copy link
Author

@Arsnael

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.
I fixed the build errors caused by the Code Style. may be .. build runtime is so long

The process of checking Code Style during the build was a refreshing experience for me.
I learned a lot today as well.

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.

3 participants