You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2024/05/09 11:39:08 UTC

(logging-log4j-tools) branch feature/plugin-value created (now 2a0c257)

This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a change to branch feature/plugin-value
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git


      at 2a0c257  Add support for `@PluginValue` annotation

This branch includes the following new commits:

     new 2a0c257  Add support for `@PluginValue` annotation

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(logging-log4j-tools) 01/01: Add support for `@PluginValue` annotation

Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch feature/plugin-value
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git

commit 2a0c25786d9340f10f91f2e7b2fb39c317ee58c6
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Thu May 9 13:37:43 2024 +0200

    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.
---
 .../org/apache/logging/log4j/docgen/processor/Annotations.java     | 4 +++-
 .../test/resources/DescriptorGeneratorTest/expected-plugins.xml    | 6 ++++++
 .../DescriptorGeneratorTest/java-of-log4j2/MyAppender.java         | 6 ++++++
 .../DescriptorGeneratorTest/java-of-log4j2/MyOldLayout.java        | 5 ++++-
 .../DescriptorGeneratorTest/java-of-log4j3/MyAppender.java         | 6 ++++++
 .../DescriptorGeneratorTest/java-of-log4j3/MyOldLayout.java        | 5 ++++-
 src/changelog/0.9.0/add-plugin-value-annotation.xml                | 7 +++++++
 7 files changed, 36 insertions(+), 3 deletions(-)

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 cae6559..d51e6b2 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<String> 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<String> 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 39f6806..1289db0 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 @@
                     <description>A `String` attribute.</description>
                 </attribute>
                 <attribute name="undocumentedAttribute" type="double"/>
+                <attribute name="valueAttribute" type="int">
+                    <description>An attribute that can be also be inserted as content of the XML element.</description>
+                </attribute>
             </attributes>
             <elements>
                 <element type="example.AbstractAppender">
@@ -154,6 +157,9 @@ It also implements:
                 <attribute name="doubleAttr" type="double">
                     <description>A `double` attribute.</description>
                 </attribute>
+                <attribute name="elementValue" type="int">
+                    <description>An attribute that can be also be inserted as content of the XML element.</description>
+                </attribute>
                 <attribute name="enumAttr" type="example.MyEnum">
                     <description>An `enum` attribute.</description>
                 </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 37a47ef..47648ca 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.PluginBuilderFactory;
 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 class MyAppender extends AbstractAppender implements Appender {
 
         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 670b7fa..bbc7bba 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.PluginAttribute;
 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 final class MyOldLayout implements Layout {
             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 3024620..6c88741 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.PluginAttribute;
 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 class MyAppender extends AbstractAppender implements Appender {
 
         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 41b08c7..3f33594 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.Factory;
 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 final class MyOldLayout implements Layout {
             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 0000000..0e24a71
--- /dev/null
+++ b/src/changelog/0.9.0/add-plugin-value-annotation.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns="https://logging.apache.org/xml/ns"
+       xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
+       type="added">
+  <description format="asciidoc">Add support for the `@PluginValue` annotation.</description>
+</entry>