From a64f2fba15202dc3de747250afaa4f5e3df58140 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 9 May 2024 13:37:43 +0200 Subject: [PATCH] Add support for `@PluginValue` annotation We add support for the [@PluginValue](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/config/plugins/PluginValue.html) annotation. --- .../logging/log4j/docgen/processor/Annotations.java | 4 +++- .../DescriptorGeneratorTest/expected-plugins.xml | 6 ++++++ .../java-of-log4j2/MyAppender.java | 6 ++++++ .../java-of-log4j2/MyOldLayout.java | 5 ++++- .../java-of-log4j3/MyAppender.java | 6 ++++++ .../java-of-log4j3/MyOldLayout.java | 5 ++++- src/changelog/0.9.0/add-plugin-value-annotation.xml | 8 ++++++++ 7 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/changelog/0.9.0/add-plugin-value-annotation.xml diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/Annotations.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/Annotations.java index cae6559f..d51e6b24 100644 --- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/Annotations.java +++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/Annotations.java @@ -53,8 +53,10 @@ final class Annotations { private static final Collection PLUGIN_ATTRIBUTE_ANNOTATION_NAMES = Arrays.asList( "org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute", "org.apache.logging.log4j.core.config.plugins.PluginAttribute", + "org.apache.logging.log4j.core.config.plugins.PluginValue", "org.apache.logging.log4j.plugins.PluginAttribute", - "org.apache.logging.log4j.plugins.PluginBuilderAttribute"); + "org.apache.logging.log4j.plugins.PluginBuilderAttribute", + "org.apache.logging.log4j.plugins.PluginValue"); private static final Collection PLUGIN_ELEMENT_ANNOTATION_NAMES = Arrays.asList( "org.apache.logging.log4j.core.config.plugins.PluginElement", "org.apache.logging.log4j.plugins.PluginElement"); diff --git a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/expected-plugins.xml b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/expected-plugins.xml index 39f6806c..1289db03 100644 --- a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/expected-plugins.xml +++ b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/expected-plugins.xml @@ -86,6 +86,9 @@ A `String` attribute. + + An attribute that can be also be inserted as content of the XML element. + @@ -154,6 +157,9 @@ It also implements: A `double` attribute. + + An attribute that can be also be inserted as content of the XML element. + An `enum` attribute. diff --git a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyAppender.java b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyAppender.java index 37a47ef7..47648ca5 100644 --- a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyAppender.java +++ b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyAppender.java @@ -26,6 +26,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; +import org.apache.logging.log4j.plugins.PluginValue; /** * Example plugin @@ -115,6 +116,11 @@ public static final class Builder extends ParentBuilder private @PluginBuilderAttribute double undocumentedAttribute; + /** + * An attribute that can be also be inserted as content of the XML element. + */ + private @PluginValue int valueAttribute; + private Object notAnAttribute; /** diff --git a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyOldLayout.java b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyOldLayout.java index 670b7faa..bbc7bbaf 100644 --- a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyOldLayout.java +++ b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyOldLayout.java @@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required; +import org.apache.logging.log4j.plugins.PluginValue; /** * Example plugin without a builder. @@ -42,6 +43,7 @@ public final class MyOldLayout implements Layout { * @param enumAttr An {@code enum} attribute. * @param nestedLayout An element with multiplicity {@code 1}. * @param filters An element with multiplicity {@code n}. + * @param valueAttribute An attribute that can be also be inserted as content of the XML element. */ @PluginFactory public static MyOldLayout newLayout( @@ -57,7 +59,8 @@ public static MyOldLayout newLayout( final @PluginAttribute("otherName") String origName, final @PluginAttribute("enumAttr") MyEnum enumAttr, final @PluginElement("nestedLayout") Layout nestedLayout, - final @PluginElement("filters") Filter[] filters) { + final @PluginElement("filters") Filter[] filters, + final @PluginValue("elementValue") int valueAttribute) { return null; } } diff --git a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyAppender.java b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyAppender.java index 30246206..6c88741c 100644 --- a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyAppender.java +++ b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyAppender.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.plugins.PluginBuilderAttribute; import org.apache.logging.log4j.plugins.PluginElement; import org.apache.logging.log4j.plugins.PluginFactory; +import org.apache.logging.log4j.plugins.PluginValue; import org.apache.logging.log4j.plugins.validation.constraints.Required; /** @@ -118,6 +119,11 @@ public static final class Builder extends ParentBuilder private @PluginBuilderAttribute double undocumentedAttribute; + /** + * An attribute that can be also be inserted as content of the XML element. + */ + private @PluginValue int valueAttribute; + private Object notAnAttribute; /** diff --git a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyOldLayout.java b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyOldLayout.java index 41b08c73..3f335941 100644 --- a/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyOldLayout.java +++ b/log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyOldLayout.java @@ -20,6 +20,7 @@ import org.apache.logging.log4j.plugins.Plugin; import org.apache.logging.log4j.plugins.PluginAttribute; import org.apache.logging.log4j.plugins.PluginElement; +import org.apache.logging.log4j.plugins.PluginValue; import org.apache.logging.log4j.plugins.validation.constraints.Required; /** @@ -42,6 +43,7 @@ public final class MyOldLayout implements Layout { * @param enumAttr An {@code enum} attribute. * @param nestedLayout An element with multiplicity {@code 1}. * @param filters An element with multiplicity {@code n}. + * @param valueAttribute An attribute that can be also be inserted as content of the XML element. */ @Factory public static MyOldLayout newLayout( @@ -57,7 +59,8 @@ public static MyOldLayout newLayout( final @PluginAttribute("otherName") String origName, final @PluginAttribute MyEnum enumAttr, final @PluginElement Layout nestedLayout, - final @PluginElement Filter[] filters) { + final @PluginElement Filter[] filters, + final @PluginValue("elementValue") int valueAttribute) { return null; } } diff --git a/src/changelog/0.9.0/add-plugin-value-annotation.xml b/src/changelog/0.9.0/add-plugin-value-annotation.xml new file mode 100644 index 00000000..3a56de32 --- /dev/null +++ b/src/changelog/0.9.0/add-plugin-value-annotation.xml @@ -0,0 +1,8 @@ + + + + Add support for the `@PluginValue` annotation. +