Skip to content

Simplify name and alias annotation processing #3877

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jvz
Copy link
Member

@jvz jvz commented Aug 11, 2025

This fixes #3870

@jvz jvz added this to the 3.0.0-beta4 milestone Aug 11, 2025
@jvz jvz requested a review from ppkarwasz August 11, 2025 16:18
@jvz jvz added plugins Affects the plugin system minor API change labels Aug 11, 2025
@jvz jvz closed this Aug 11, 2025
@jvz jvz reopened this Aug 11, 2025
@jvz jvz closed this Aug 13, 2025
@jvz jvz reopened this Aug 13, 2025
@ppkarwasz
Copy link
Contributor

Hi @jvz,

Don't worry, I have seen your PR, but until the end of the week I don't really have the time to review it.

@jvz
Copy link
Member Author

jvz commented Aug 13, 2025

I'm trying to get the build to work 😆

@ppkarwasz
Copy link
Contributor

The MacOS failure is due to a problem in the Maven Wrapper script.
It was fixed in #3676 for 2.x, but never ported.

@jvz
Copy link
Member Author

jvz commented Aug 18, 2025

Now it seems there's a Windows-specific build issue related to TLS settings.

Copy link
Member

@vy vy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jvz, +93/-615 LoC is impressive! 💯 I've some questions that I will appreciate it if you can help with.

Comment on lines +25 to +29
/**
* Marks another annotation as one providing a name for an object. The name is obtained from
* the annotation element named {@code value}. This element can be a {@code String} or {@code String[]}.
* When specified as an array, the first element is used.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marks another annotation as one providing a name for an object.

Oookay... PluginElement, PluginValue, etc. are NameProviders. Got it.

The name is obtained from the annotation element named value.
This element can be a String or String[].
When specified as an array, the first element is used.

I am totally lost here. Would you mind elaborating on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try. The idea here is that an annotation like @Named(String[] value) can specify both the name (the first element of the array) and additional aliases (the rest of the array). However, some annotations like @PluginAliases(String[] value) use the whole array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! Got it!

Suggested change
/**
* Marks another annotation as one providing a name for an object. The name is obtained from
* the annotation element named {@code value}. This element can be a {@code String} or {@code String[]}.
* When specified as an array, the first element is used.
*/
/**
* Marks another annotation as one providing a name for an object.
* The name is obtained from the annotation element named {@code value}.
* This element can be a {@code String} or {@code String[]}.
* When specified as an array, the first element is used.
* <h2>Examples:</h2>
* <ul>
* <li>{@code @NameProvider @Named(String value)} - {@code value} will be used as the name
* <li>{@code @NameProvider @PluginAliases(String[] value)} - {@code value[0]} will be used as the name
* </ul>
*/

@NameProvider(NamedQualifierNameProvider.class)
@AliasesProvider(NamedQualifierNameProvider.class)
@NameProvider
@AliasesProvider(offset = 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by offset and its function. (Yes, I've read its Javadoc.) Would you mind explaining it a little bit more, please?

@@ -23,7 +23,7 @@
import java.lang.annotation.Target;

/**
* Annotations to separate {@link org.apache.logging.log4j.plugins.name.NameProvider} names into namespaces.
* Annotations to separate {@link NameProvider} names into namespaces.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "NameProvider names" mean? "Names provided by NameProviders"?

Comment on lines 27 to 28
* For example, the {@linkplain Configurable Core namespace} is used with the {@link Node} API, while the TypeConverter
* namespace is used with the {@link org.apache.logging.log4j.plugins.convert.TypeConverter} API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this example needs to be explained more.

@@ -53,7 +53,7 @@ Injection points are injectable fields or parameters where a dependency should b
_Injectable fields_ are fields annotated with `@Inject` or a qualifier annotation.
_Injectable methods_ are methods annotated with `@Inject` or are not annotated with a factory annotation and have at least one parameter annotated with a qualifier annotation.
_Injectable constructors_ are constructors annotated with `@Inject`; only one such constructor should exist per class.
When a field or parameter is annotated with a name-providing annotation (i.e., an annotation annotated with `@org.apache.logging.log4j.plugins.name.NameProvider`), then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point.
When a field or parameter is annotated with a name-providing annotation (i.e., an annotation annotated with `@org.apache.logging.log4j.plugins.NameProvider`), then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When a field or parameter is annotated with a name-providing annotation (i.e., an annotation annotated with `@org.apache.logging.log4j.plugins.NameProvider`), then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point.
When a field or parameter is annotated with `@NameProvider`, then the provided name or name of the field or parameter are included in the `Key<T>` for the injection point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... Lastly, no-arg methods annotated with @Inject are invoked which can be useful for post-injection initialization logic. Additional strategies for resolving factories for unbound keys may be registered which are consulted first before falling back to this @Inject reflection logic.

Do we have a use case for every single logic described above? For instance, I was not able to find a single usage of @Inject on a no-arg method. In a follow-up PR, can we remove and all other functionalities that do not (yet) serve a purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's there for a sort of @PostConstruct type of thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but without any usage. I am not keen on growing the public API, knowing that not even ourselves using it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't "grow" the public API; it has been in the plugin DI system for multiple 3.0.0 releases already. If you're suggesting we can review old code that's already in main, then I don't see the point of reviewing PRs since it could be reviewed directly from main as demonstrated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not suggesting to address this (or any other remark of mine applying to old text) in this PR. I will create a separate issue for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as bundles which are instances or injectable Class<T> instances that contain one or more annotated factory methods.

"Bundle" is a very convoluted term in the Java ecosystem. Above statement literally describes a "factory collection/set", which we can consider replacing bundle with as a more self-explanatory term.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I called it "module" before as the concept is borrowed from Guice, but that gets confusing with Java modules. They're similar to spring @Configuration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave the decision to you. You can resolve this conversation as you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor API change plugins Affects the plugin system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants