This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch feature/3.x/simplify-name-alias-processing
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 4fea2f1c798085816a42dc41a89f722f10c4a4a8
Author: Matt Sicker <msic...@apple.com>
AuthorDate: Fri Aug 8 17:23:15 2025 -0500
Simplify name and alias annotation processing
---
.../logging/log4j/core/test/junit/Named.java | 16 +----
.../log4j/core/config/plugins/PluginAliases.java | 5 +-
.../log4j/core/config/plugins/PluginAttribute.java | 5 +-
.../config/plugins/PluginBuilderAttribute.java | 5 +-
.../log4j/core/config/plugins/PluginElement.java | 5 +-
.../log4j/core/config/plugins/PluginValue.java | 5 +-
.../config/plugins/util/PluginAliasesProvider.java | 31 ----------
.../plugins/util/PluginAttributeNameProvider.java | 33 ----------
.../util/PluginBuilderAttributeNameProvider.java | 33 ----------
.../plugins/util/PluginElementNameProvider.java | 33 ----------
.../plugins/util/PluginValueNameProvider.java | 33 ----------
.../apache/logging/log4j/plugins/di/KeyTest.java | 13 +---
.../NameProvider.java => AliasesProvider.java} | 13 ++--
.../AliasesProvider.java => NameProvider.java} | 12 ++--
.../org/apache/logging/log4j/plugins/Named.java | 7 +--
.../apache/logging/log4j/plugins/Namespace.java | 2 +-
.../org/apache/logging/log4j/plugins/Plugin.java | 4 +-
.../logging/log4j/plugins/PluginAliases.java | 4 +-
.../logging/log4j/plugins/PluginAttribute.java | 4 +-
.../log4j/plugins/PluginBuilderAttribute.java | 4 +-
.../logging/log4j/plugins/PluginElement.java | 4 +-
.../apache/logging/log4j/plugins/PluginValue.java | 4 +-
.../org/apache/logging/log4j/plugins/di/Keys.java | 72 +++++++++++++---------
.../name/AnnotatedElementAliasesProvider.java | 24 --------
.../plugins/name/AnnotatedElementNameProvider.java | 36 -----------
.../log4j/plugins/name/CategoryNameProvider.java | 30 ---------
.../plugins/name/NamedQualifierNameProvider.java | 50 ---------------
.../log4j/plugins/name/PluginAliasesProvider.java | 28 ---------
.../plugins/name/PluginAttributeNameProvider.java | 30 ---------
.../name/PluginBuilderAttributeNameProvider.java | 30 ---------
.../plugins/name/PluginElementNameProvider.java | 30 ---------
.../log4j/plugins/name/PluginNameProvider.java | 30 ---------
.../plugins/name/PluginValueNameProvider.java | 30 ---------
.../logging/log4j/plugins/name/package-info.java | 26 --------
.../ROOT/pages/manual/dependencyinjection.adoc | 6 +-
35 files changed, 82 insertions(+), 615 deletions(-)
diff --git
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/Named.java
b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/Named.java
index 9fe8f7493a..293f54af46 100644
---
a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/Named.java
+++
b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/Named.java
@@ -16,17 +16,12 @@
*/
package org.apache.logging.log4j.core.test.junit;
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-import org.apache.logging.log4j.plugins.name.NameProvider;
+import org.apache.logging.log4j.plugins.NameProvider;
/**
* Specifies the name of an {@link org.apache.logging.log4j.core.Appender} to
inject into JUnit 5 tests from the specified
@@ -38,17 +33,10 @@ import org.apache.logging.log4j.plugins.name.NameProvider;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@Documented
-@NameProvider(Named.Provider.class)
+@NameProvider
public @interface Named {
/**
* Specifies the name of the configuration item to inject. If blank, uses
the name of the annotated parameter.
*/
String value() default "";
-
- class Provider implements AnnotatedElementNameProvider<Named> {
- @Override
- public Optional<String> getSpecifiedName(final Named annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
- }
}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
index cd0352821b..2f6e7f4bdf 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAliases.java
@@ -21,8 +21,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.logging.log4j.core.config.plugins.util.PluginAliasesProvider;
-import org.apache.logging.log4j.plugins.name.AliasesProvider;
+import org.apache.logging.log4j.plugins.AliasesProvider;
/**
* Identifies a list of aliases for a Plugin, PluginAttribute, or
PluginBuilderAttribute.
@@ -31,7 +30,7 @@ import org.apache.logging.log4j.plugins.name.AliasesProvider;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.TYPE, ElementType.FIELD})
-@AliasesProvider(PluginAliasesProvider.class)
+@AliasesProvider
@Deprecated(since = "3.0", forRemoval = true)
@SuppressWarnings("removal")
public @interface PluginAliases {
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttribute.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttribute.java
index bdd50b7a41..97eb9db19d 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttribute.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginAttribute.java
@@ -21,9 +21,8 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import
org.apache.logging.log4j.core.config.plugins.util.PluginAttributeNameProvider;
+import org.apache.logging.log4j.plugins.NameProvider;
import org.apache.logging.log4j.plugins.QualifierType;
-import org.apache.logging.log4j.plugins.name.NameProvider;
import org.apache.logging.log4j.util.Strings;
/**
@@ -37,7 +36,7 @@ import org.apache.logging.log4j.util.Strings;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD})
-@NameProvider(PluginAttributeNameProvider.class)
+@NameProvider
@QualifierType
@Deprecated(since = "3.0", forRemoval = true)
@SuppressWarnings("removal")
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginBuilderAttribute.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginBuilderAttribute.java
index 1255b01c1b..952f57a693 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginBuilderAttribute.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginBuilderAttribute.java
@@ -21,9 +21,8 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import
org.apache.logging.log4j.core.config.plugins.util.PluginBuilderAttributeNameProvider;
+import org.apache.logging.log4j.plugins.NameProvider;
import org.apache.logging.log4j.plugins.QualifierType;
-import org.apache.logging.log4j.plugins.name.NameProvider;
import org.apache.logging.log4j.util.Strings;
/**
@@ -33,7 +32,7 @@ import org.apache.logging.log4j.util.Strings;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD})
-@NameProvider(PluginBuilderAttributeNameProvider.class)
+@NameProvider
@QualifierType
@Deprecated(since = "3.0", forRemoval = true)
@SuppressWarnings("removal")
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java
index 112853c494..a09240e528 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginElement.java
@@ -21,9 +21,8 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import
org.apache.logging.log4j.core.config.plugins.util.PluginElementNameProvider;
+import org.apache.logging.log4j.plugins.NameProvider;
import org.apache.logging.log4j.plugins.QualifierType;
-import org.apache.logging.log4j.plugins.name.NameProvider;
/**
* Identifies a parameter as a Plugin and corresponds with an XML element (or
equivalent) in configuration files.
@@ -32,7 +31,7 @@ import org.apache.logging.log4j.plugins.name.NameProvider;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD})
-@NameProvider(PluginElementNameProvider.class)
+@NameProvider
@QualifierType
@Deprecated(since = "3.0", forRemoval = true)
@SuppressWarnings("removal")
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java
index d26b535113..b42e1bf20e 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/PluginValue.java
@@ -21,9 +21,8 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import
org.apache.logging.log4j.core.config.plugins.util.PluginValueNameProvider;
+import org.apache.logging.log4j.plugins.NameProvider;
import org.apache.logging.log4j.plugins.QualifierType;
-import org.apache.logging.log4j.plugins.name.NameProvider;
/**
* Identifies a parameter as a value. These correspond with property values
generally, but are meant as values to be
@@ -35,7 +34,7 @@ import org.apache.logging.log4j.plugins.name.NameProvider;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD})
-@NameProvider(PluginValueNameProvider.class)
+@NameProvider
@QualifierType
@Deprecated(since = "3.0", forRemoval = true)
@SuppressWarnings("removal")
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginAliasesProvider.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginAliasesProvider.java
deleted file mode 100644
index b83d62165f..0000000000
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginAliasesProvider.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.config.plugins.util;
-
-import java.util.Collection;
-import java.util.List;
-import org.apache.logging.log4j.core.config.plugins.PluginAliases;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementAliasesProvider;
-
-@Deprecated(since = "3.0", forRemoval = true)
-@SuppressWarnings("removal")
-public class PluginAliasesProvider implements
AnnotatedElementAliasesProvider<PluginAliases> {
- @Override
- public Collection<String> getAliases(final PluginAliases annotation) {
- return List.of(annotation.value());
- }
-}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginAttributeNameProvider.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginAttributeNameProvider.java
deleted file mode 100644
index 91b34613db..0000000000
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginAttributeNameProvider.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.config.plugins.util;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-
-@Deprecated(since = "3.0", forRemoval = true)
-@SuppressWarnings("removal")
-public class PluginAttributeNameProvider implements
AnnotatedElementNameProvider<PluginAttribute> {
- @Override
- public Optional<String> getSpecifiedName(final PluginAttribute annotation)
{
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilderAttributeNameProvider.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilderAttributeNameProvider.java
deleted file mode 100644
index e4a3747722..0000000000
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginBuilderAttributeNameProvider.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.config.plugins.util;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-
-@Deprecated(since = "3.0", forRemoval = true)
-@SuppressWarnings("removal")
-public class PluginBuilderAttributeNameProvider implements
AnnotatedElementNameProvider<PluginBuilderAttribute> {
- @Override
- public Optional<String> getSpecifiedName(final PluginBuilderAttribute
annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginElementNameProvider.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginElementNameProvider.java
deleted file mode 100644
index e4efb370c7..0000000000
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginElementNameProvider.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.config.plugins.util;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.core.config.plugins.PluginElement;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-
-@Deprecated(since = "3.0", forRemoval = true)
-@SuppressWarnings("removal")
-public class PluginElementNameProvider implements
AnnotatedElementNameProvider<PluginElement> {
- @Override
- public Optional<String> getSpecifiedName(final PluginElement annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginValueNameProvider.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginValueNameProvider.java
deleted file mode 100644
index 18d849066e..0000000000
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginValueNameProvider.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.core.config.plugins.util;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.core.config.plugins.PluginValue;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-
-@Deprecated(since = "3.0", forRemoval = true)
-@SuppressWarnings("removal")
-public class PluginValueNameProvider implements
AnnotatedElementNameProvider<PluginValue> {
- @Override
- public Optional<String> getSpecifiedName(final PluginValue annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java
b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java
index 0bdf724977..c50ddbc9f6 100644
---
a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java
+++
b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java
@@ -25,13 +25,11 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
-import java.util.Optional;
+import org.apache.logging.log4j.plugins.NameProvider;
import org.apache.logging.log4j.plugins.Named;
import org.apache.logging.log4j.plugins.Namespace;
import org.apache.logging.log4j.plugins.Ordered;
import org.apache.logging.log4j.plugins.QualifierType;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-import org.apache.logging.log4j.plugins.name.NameProvider;
import org.junit.jupiter.api.Test;
// TODO: add tests for more complex types with generics etc
@@ -107,18 +105,11 @@ class KeyTest {
@Retention(RetentionPolicy.RUNTIME)
@QualifierType
- @NameProvider(CustomQualifierNameProvider.class)
+ @NameProvider
@interface CustomQualifier {
String value();
}
- static class CustomQualifierNameProvider implements
AnnotatedElementNameProvider<CustomQualifier> {
- @Override
- public Optional<String> getSpecifiedName(final CustomQualifier
annotation) {
- return Optional.of(annotation.value());
- }
- }
-
@Retention(RetentionPolicy.RUNTIME)
@Namespace("logical")
@interface LogicalNamespace {}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/NameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/AliasesProvider.java
similarity index 72%
rename from
log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/NameProvider.java
rename to
log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/AliasesProvider.java
index 38ab42a232..02df1a67c0 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/NameProvider.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/AliasesProvider.java
@@ -14,9 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.plugins.name;
+package org.apache.logging.log4j.plugins;
-import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -24,14 +23,16 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * Meta annotation for specifying named annotations and how to get a specified
name from the named annotation.
+ * Marks another annotation as one providing aliases for an object. The
annotation must define an element
+ * named {@code value} of type {@code String[]} that contains the aliases. An
offset can define where to
+ * begin reading the aliases.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
-public @interface NameProvider {
+public @interface AliasesProvider {
/**
- * Strategy for extracting a specified name from an annotated element.
+ * Offset within the {@code value} array to read aliases from.
*/
- Class<? extends AnnotatedElementNameProvider<? extends Annotation>>
value();
+ int offset() default 0;
}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AliasesProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/NameProvider.java
similarity index 76%
rename from
log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AliasesProvider.java
rename to
log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/NameProvider.java
index d93b947a95..3073520a21 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AliasesProvider.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/NameProvider.java
@@ -14,18 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.plugins.name;
+package org.apache.logging.log4j.plugins;
-import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * 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.
+ */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
-public @interface AliasesProvider {
- Class<? extends AnnotatedElementAliasesProvider<? extends Annotation>>
value();
-}
+public @interface NameProvider {}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Named.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Named.java
index 6f284f9b4b..4df623283c 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Named.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Named.java
@@ -21,9 +21,6 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.logging.log4j.plugins.name.AliasesProvider;
-import org.apache.logging.log4j.plugins.name.NameProvider;
-import org.apache.logging.log4j.plugins.name.NamedQualifierNameProvider;
/**
* General naming qualifier for injectable objects. The first value given is
the primary name while subsequent values are
@@ -32,8 +29,8 @@ import
org.apache.logging.log4j.plugins.name.NamedQualifierNameProvider;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
ElementType.TYPE_USE})
@Documented
-@NameProvider(NamedQualifierNameProvider.class)
-@AliasesProvider(NamedQualifierNameProvider.class)
+@NameProvider
+@AliasesProvider(offset = 1)
@QualifierType
public @interface Named {
/**
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Namespace.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Namespace.java
index 4612cc1dfc..7980e1b6ac 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Namespace.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Namespace.java
@@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy;
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.
* 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.
* This can be annotated on another annotation to create an alias annotation
for a common namespace.
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Plugin.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Plugin.java
index 29ad60bee1..013ea7727e 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Plugin.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/Plugin.java
@@ -22,8 +22,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.apache.logging.log4j.plugins.model.PluginService;
-import org.apache.logging.log4j.plugins.name.NameProvider;
-import org.apache.logging.log4j.plugins.name.PluginNameProvider;
import org.apache.logging.log4j.util.Strings;
/**
@@ -44,7 +42,7 @@ import org.apache.logging.log4j.util.Strings;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
-@NameProvider(PluginNameProvider.class)
+@NameProvider
public @interface Plugin {
/**
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAliases.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAliases.java
index 0e9f22668b..9562d88b0f 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAliases.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAliases.java
@@ -21,8 +21,6 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.logging.log4j.plugins.name.AliasesProvider;
-import org.apache.logging.log4j.plugins.name.PluginAliasesProvider;
/**
* Identifies a list of aliases for an annotated plugin element. This is
supported by plugin classes and other element
@@ -31,7 +29,7 @@ import
org.apache.logging.log4j.plugins.name.PluginAliasesProvider;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.TYPE, ElementType.FIELD,
ElementType.METHOD})
-@AliasesProvider(PluginAliasesProvider.class)
+@AliasesProvider
public @interface PluginAliases {
/**
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAttribute.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAttribute.java
index 9ac1128a0a..e248e6aeb7 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAttribute.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginAttribute.java
@@ -24,8 +24,6 @@ import java.lang.annotation.Target;
import java.util.function.Supplier;
import org.apache.logging.log4j.plugins.convert.TypeConverter;
import
org.apache.logging.log4j.plugins.di.resolver.PluginAttributeFactoryResolver;
-import org.apache.logging.log4j.plugins.name.NameProvider;
-import org.apache.logging.log4j.plugins.name.PluginAttributeNameProvider;
import org.apache.logging.log4j.util.Strings;
/**
@@ -57,7 +55,7 @@ import org.apache.logging.log4j.util.Strings;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD,
ElementType.TYPE_USE})
-@NameProvider(PluginAttributeNameProvider.class)
+@NameProvider
@QualifierType
public @interface PluginAttribute {
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginBuilderAttribute.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginBuilderAttribute.java
index b539e59cfd..9d5fe39daf 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginBuilderAttribute.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginBuilderAttribute.java
@@ -21,8 +21,6 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.logging.log4j.plugins.name.NameProvider;
-import
org.apache.logging.log4j.plugins.name.PluginBuilderAttributeNameProvider;
import org.apache.logging.log4j.util.Strings;
/**
@@ -33,7 +31,7 @@ import org.apache.logging.log4j.util.Strings;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.TYPE,
ElementType.TYPE_USE})
-@NameProvider(PluginBuilderAttributeNameProvider.class)
+@NameProvider
@QualifierType
public @interface PluginBuilderAttribute {
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginElement.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginElement.java
index 1ddba1a415..c5d0dcd178 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginElement.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginElement.java
@@ -22,8 +22,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import
org.apache.logging.log4j.plugins.di.resolver.PluginElementFactoryResolver;
-import org.apache.logging.log4j.plugins.name.NameProvider;
-import org.apache.logging.log4j.plugins.name.PluginElementNameProvider;
import org.apache.logging.log4j.util.Strings;
/**
@@ -36,7 +34,7 @@ import org.apache.logging.log4j.util.Strings;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD,
ElementType.TYPE_USE})
-@NameProvider(PluginElementNameProvider.class)
+@NameProvider
@QualifierType
@Configurable
public @interface PluginElement {
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginValue.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginValue.java
index 8d4f98d575..e724a940fe 100644
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginValue.java
+++
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/PluginValue.java
@@ -21,8 +21,6 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.logging.log4j.plugins.name.NameProvider;
-import org.apache.logging.log4j.plugins.name.PluginValueNameProvider;
/**
* Identifies a Plugin Value and its corresponding attribute alias for
configuration formats that don't distinguish
@@ -37,7 +35,7 @@ import
org.apache.logging.log4j.plugins.name.PluginValueNameProvider;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD,
ElementType.TYPE_USE})
-@NameProvider(PluginValueNameProvider.class)
+@NameProvider
@QualifierType
public @interface PluginValue {
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Keys.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Keys.java
index d4f2ae7f8d..564448e51e 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Keys.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Keys.java
@@ -20,21 +20,19 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
+import org.apache.logging.log4j.plugins.AliasesProvider;
+import org.apache.logging.log4j.plugins.NameProvider;
import org.apache.logging.log4j.plugins.Namespace;
import org.apache.logging.log4j.plugins.internal.util.AnnotatedAnnotation;
import org.apache.logging.log4j.plugins.internal.util.AnnotationUtil;
import org.apache.logging.log4j.plugins.internal.util.BeanUtils;
-import org.apache.logging.log4j.plugins.name.AliasesProvider;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementAliasesProvider;
-import org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider;
-import org.apache.logging.log4j.plugins.name.NameProvider;
-import org.apache.logging.log4j.plugins.util.ReflectionUtil;
-import org.apache.logging.log4j.util.Cast;
import org.apache.logging.log4j.util.Strings;
public final class Keys {
@@ -66,9 +64,9 @@ public final class Keys {
}
/**
- * Gets the name of the annotated field using the corresponding {@link
AnnotatedElementNameProvider}
+ * Gets the name of the annotated field using the corresponding {@link
NameProvider}
* strategy for the named annotation on the field. If no named annotations
are present, then an empty string
- * is returned. If no {@linkplain
AnnotatedElementNameProvider#getSpecifiedName(Annotation) specified name} is
given
+ * is returned. If no specified name is given
* by the name provider, the {@linkplain Field#getName() field name} is
returned.
*
* @param field annotated field to find name for
@@ -79,9 +77,9 @@ public final class Keys {
}
/**
- * Gets the name of the given annotated parameter using the corresponding
{@link AnnotatedElementNameProvider}
+ * Gets the name of the given annotated parameter using the corresponding
{@link NameProvider}
* strategy for the named annotation on the parameter. If no named
annotations are present, then an empty string
- * is returned. If no {@linkplain
AnnotatedElementNameProvider#getSpecifiedName(Annotation) specified name} is
given
+ * is returned. If no specified name is given
* by the name provider, the {@linkplain Parameter#getName() parameter
name} is returned.
*
* @param parameter annotated parameter to find name for
@@ -92,9 +90,9 @@ public final class Keys {
}
/**
- * Gets the name of the given annotated method using the corresponding
{@link AnnotatedElementNameProvider}
+ * Gets the name of the given annotated method using the corresponding
{@link NameProvider}
* strategy for the named annotation on the method. If no named
annotations are present, then an empty string
- * is returned. If no {@linkplain
AnnotatedElementNameProvider#getSpecifiedName(Annotation) specified name} is
given by
+ * is returned. If no specified name is given by
* the name provider, the {@linkplain Method#getName() method name} is
used with {@code is}, {@code set}, {@code get},
* and {@code with} prefixes removed and the result being de-capitalized.
*
@@ -120,9 +118,9 @@ public final class Keys {
}
/**
- * Gets the name of the given annotated type using the corresponding
{@link AnnotatedElementNameProvider}
+ * Gets the name of the given annotated type using the corresponding
{@link NameProvider}
* strategy for the named annotation on the type. If no named annotations
are present or if no
- * {@linkplain AnnotatedElementNameProvider#getSpecifiedName(Annotation)
specified name} is given by the name provider,
+ * specified name is given by the name provider,
* then an empty string is returned.
*
* @param annotatedType annotated type to find name for
@@ -133,9 +131,9 @@ public final class Keys {
}
/**
- * Gets the name of the given annotated class using the corresponding
{@link AnnotatedElementNameProvider}
+ * Gets the name of the given annotated class using the corresponding
{@link NameProvider}
* strategy for the named annotation on the class. If no named annotations
are present, then an empty
- * string is returned. If no {@linkplain
AnnotatedElementNameProvider#getSpecifiedName(Annotation) specified name} is
given
+ * string is returned. If no specified name is given
* by the name provider, then the {@linkplain Class#getSimpleName() simple
name} of the annotated class is returned.
*
* @param type annotated class to find name for
@@ -145,19 +143,24 @@ public final class Keys {
return hasName(type) ?
getSpecifiedName(type).orElseGet(type::getSimpleName) : Strings.EMPTY;
}
- // TODO(ms): these name and alias providers should work via DI
private static Optional<String> getSpecifiedName(final AnnotatedElement
element) {
- return AnnotationUtil.findAnnotatedAnnotations(element,
NameProvider.class)
- .findFirst()
- .flatMap(Keys::getSpecifiedName);
+ var annotation =
AnnotationUtil.getElementAnnotationHavingMetaAnnotation(element,
NameProvider.class);
+ return Optional.ofNullable(annotation).flatMap(Keys::getSpecifiedName);
}
- private static <A extends Annotation> Optional<String> getSpecifiedName(
- final AnnotatedAnnotation<A, NameProvider> annotatedAnnotation) {
- final Class<? extends AnnotatedElementNameProvider<A>> providerType =
- Cast.cast(annotatedAnnotation.metaAnnotation().value());
- final AnnotatedElementNameProvider<A> provider =
ReflectionUtil.instantiate(providerType);
- return provider.getSpecifiedName(annotatedAnnotation.annotation());
+ private static Optional<String> getSpecifiedName(final Annotation
annotation) {
+ try {
+ final Method nameProvidingElement =
annotation.annotationType().getDeclaredMethod("value");
+ final Object value = nameProvidingElement.invoke(annotation);
+ if (value instanceof final String string) {
+ return Optional.ofNullable(Strings.trimToNull(string));
+ }
+ if (value instanceof final String[] array && array.length > 0) {
+ return Optional.ofNullable(Strings.trimToNull(array[0]));
+ }
+ } catch (final NoSuchMethodException | IllegalAccessException |
InvocationTargetException ignored) {
+ }
+ return Optional.empty();
}
public static Collection<String> getAliases(final AnnotatedElement
element) {
@@ -169,9 +172,18 @@ public final class Keys {
private static <A extends Annotation> Collection<String> getAliases(
final AnnotatedAnnotation<A, AliasesProvider> annotatedAnnotation)
{
- final Class<? extends AnnotatedElementAliasesProvider<A>> providerType
=
- Cast.cast(annotatedAnnotation.metaAnnotation().value());
- final AnnotatedElementAliasesProvider<A> provider =
ReflectionUtil.instantiate(providerType);
- return provider.getAliases(annotatedAnnotation.annotation());
+ final A annotation = annotatedAnnotation.annotation();
+ try {
+ final Method valueMethod =
annotation.annotationType().getDeclaredMethod("value");
+ final String[] value = (String[]) valueMethod.invoke(annotation);
+ final List<String> list = Arrays.asList(value);
+ if (!list.isEmpty()) {
+ final AliasesProvider aliasesProvider =
annotatedAnnotation.metaAnnotation();
+ final int offset = aliasesProvider.offset();
+ return offset > 0 ? list.subList(offset, list.size()) : list;
+ }
+ } catch (NoSuchMethodException | IllegalAccessException |
InvocationTargetException ignored) {
+ }
+ return List.of();
}
}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AnnotatedElementAliasesProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AnnotatedElementAliasesProvider.java
deleted file mode 100644
index 36695b0fae..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AnnotatedElementAliasesProvider.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import java.lang.annotation.Annotation;
-import java.util.Collection;
-
-public interface AnnotatedElementAliasesProvider<A extends Annotation> {
- Collection<String> getAliases(final A annotation);
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AnnotatedElementNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AnnotatedElementNameProvider.java
deleted file mode 100644
index 78bacb8692..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/AnnotatedElementNameProvider.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import java.lang.annotation.Annotation;
-import java.util.Optional;
-
-/**
- * Extracts a specified name for some configurable annotated element. A
specified name is one given in a non-empty
- * string in an annotation as opposed to relying on the default name taken
from the annotated element itself.
- *
- * @param <A> plugin configuration annotation
- */
-public interface AnnotatedElementNameProvider<A extends Annotation> {
- /**
- * Returns the specified name from this annotation if given or {@code
Optional.empty()} if none given.
- *
- * @param annotation annotation value of configuration element
- * @return specified name of configuration element or empty if none
specified
- */
- Optional<String> getSpecifiedName(final A annotation);
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/CategoryNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/CategoryNameProvider.java
deleted file mode 100644
index 8772f7d217..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/CategoryNameProvider.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.Namespace;
-
-public class CategoryNameProvider implements
AnnotatedElementNameProvider<Namespace> {
- @Override
- public Optional<String> getSpecifiedName(final Namespace annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/NamedQualifierNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/NamedQualifierNameProvider.java
deleted file mode 100644
index edeb7a6d93..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/NamedQualifierNameProvider.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.Named;
-
-public class NamedQualifierNameProvider
- implements AnnotatedElementNameProvider<Named>,
AnnotatedElementAliasesProvider<Named> {
- @Override
- public Optional<String> getSpecifiedName(final Named annotation) {
- final String[] names = annotation.value();
- if (names == null || names.length == 0) {
- return Optional.empty();
- }
- return ofNullable(trimToNull(names[0]));
- }
-
- @Override
- public Collection<String> getAliases(final Named annotation) {
- final String[] names = annotation.value();
- if (names == null || names.length <= 1) {
- return List.of();
- }
- final String[] aliases = new String[names.length - 1];
- for (int i = 0; i < aliases.length; i++) {
- aliases[i] = names[i + 1].trim();
- }
- return List.of(aliases);
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginAliasesProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginAliasesProvider.java
deleted file mode 100644
index 79dcdf2dcd..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginAliasesProvider.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import java.util.Collection;
-import java.util.List;
-import org.apache.logging.log4j.plugins.PluginAliases;
-
-public class PluginAliasesProvider implements
AnnotatedElementAliasesProvider<PluginAliases> {
- @Override
- public Collection<String> getAliases(final PluginAliases annotation) {
- return List.of(annotation.value());
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginAttributeNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginAttributeNameProvider.java
deleted file mode 100644
index 37f8a1544b..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginAttributeNameProvider.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.PluginAttribute;
-
-public class PluginAttributeNameProvider implements
AnnotatedElementNameProvider<PluginAttribute> {
- @Override
- public Optional<String> getSpecifiedName(final PluginAttribute annotation)
{
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginBuilderAttributeNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginBuilderAttributeNameProvider.java
deleted file mode 100644
index c61cb4dd4c..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginBuilderAttributeNameProvider.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
-
-public class PluginBuilderAttributeNameProvider implements
AnnotatedElementNameProvider<PluginBuilderAttribute> {
- @Override
- public Optional<String> getSpecifiedName(final PluginBuilderAttribute
annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginElementNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginElementNameProvider.java
deleted file mode 100644
index ec3c3dd10d..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginElementNameProvider.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.PluginElement;
-
-public class PluginElementNameProvider implements
AnnotatedElementNameProvider<PluginElement> {
- @Override
- public Optional<String> getSpecifiedName(final PluginElement annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginNameProvider.java
deleted file mode 100644
index 5072ed6347..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginNameProvider.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.Plugin;
-
-public class PluginNameProvider implements
AnnotatedElementNameProvider<Plugin> {
- @Override
- public Optional<String> getSpecifiedName(final Plugin annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginValueNameProvider.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginValueNameProvider.java
deleted file mode 100644
index 2bcaa27d07..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/PluginValueNameProvider.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.plugins.name;
-
-import static java.util.Optional.ofNullable;
-import static org.apache.logging.log4j.util.Strings.trimToNull;
-
-import java.util.Optional;
-import org.apache.logging.log4j.plugins.PluginValue;
-
-public class PluginValueNameProvider implements
AnnotatedElementNameProvider<PluginValue> {
- @Override
- public Optional<String> getSpecifiedName(final PluginValue annotation) {
- return ofNullable(trimToNull(annotation.value()));
- }
-}
diff --git
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/package-info.java
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/package-info.java
deleted file mode 100644
index 6458d1520f..0000000000
---
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/name/package-info.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-/**
- * Strategies for extracting names and aliases from annotations.
- */
-@Export
-@Version("1.0.0")
-package org.apache.logging.log4j.plugins.name;
-
-import org.osgi.annotation.bundle.Export;
-import org.osgi.annotation.versioning.Version;
diff --git a/src/site/antora/modules/ROOT/pages/manual/dependencyinjection.adoc
b/src/site/antora/modules/ROOT/pages/manual/dependencyinjection.adoc
index e6686c541a..e2b8619fea 100644
--- a/src/site/antora/modules/ROOT/pages/manual/dependencyinjection.adoc
+++ b/src/site/antora/modules/ROOT/pages/manual/dependencyinjection.adoc
@@ -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.
When these elements are annotated with a `@Namespace` annotation or
meta-annotation, then that namespace name is included in the `Key<T>` for the
injection point.
Similarly, when a field or parameter is annotated with a qualifier annotation,
then that qualifier annotation type is included in the `Key<T>` for the
injection point.
@@ -114,8 +114,8 @@ Qualifiers provide a way to match dependencies and
factories based on more than
For example, the `@org.apache.logging.log4j.plugins.Named` qualifier allows
for creating different bindings of the same type with different names (along
with support for aliases).
Qualifiers on an injection point request a binding with that qualifier type
and name.
Qualifiers on a factory method register a binding with that qualifier type and
name.
-The name for a qualifier is provided via an
`org.apache.logging.log4j.plugins.name.AnnotatedElementNameProvider` strategy
class given in the `@NameProvider` annotation declared on the qualifier
annotation.
-Aliases are likewise provided via an
`org.apache.logging.log4j.plugins.name.AnnotatedElementAliasesProvider`
strategy class given in the `@AliasesProvider` annotated declared on the
qualifier annotation.
+The name for a qualifier is provided via a `@NameProvider` annotation declared
on the qualifier annotation.
+Aliases are likewise provided via a `@AliasesProvider` annotated declared on
the qualifier annotation.
=== Scopes