Skip to content

Commit 2a0c257

Browse files
committed
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.
1 parent 9d822d3 commit 2a0c257

File tree

7 files changed

+36
-3
lines changed

7 files changed

+36
-3
lines changed

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/Annotations.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ final class Annotations {
5353
private static final Collection<String> PLUGIN_ATTRIBUTE_ANNOTATION_NAMES = Arrays.asList(
5454
"org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute",
5555
"org.apache.logging.log4j.core.config.plugins.PluginAttribute",
56+
"org.apache.logging.log4j.core.config.plugins.PluginValue",
5657
"org.apache.logging.log4j.plugins.PluginAttribute",
57-
"org.apache.logging.log4j.plugins.PluginBuilderAttribute");
58+
"org.apache.logging.log4j.plugins.PluginBuilderAttribute",
59+
"org.apache.logging.log4j.plugins.PluginValue");
5860
private static final Collection<String> PLUGIN_ELEMENT_ANNOTATION_NAMES = Arrays.asList(
5961
"org.apache.logging.log4j.core.config.plugins.PluginElement",
6062
"org.apache.logging.log4j.plugins.PluginElement");

log4j-docgen/src/test/resources/DescriptorGeneratorTest/expected-plugins.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
<description>A `String` attribute.</description>
8787
</attribute>
8888
<attribute name="undocumentedAttribute" type="double"/>
89+
<attribute name="valueAttribute" type="int">
90+
<description>An attribute that can be also be inserted as content of the XML element.</description>
91+
</attribute>
8992
</attributes>
9093
<elements>
9194
<element type="example.AbstractAppender">
@@ -154,6 +157,9 @@ It also implements:
154157
<attribute name="doubleAttr" type="double">
155158
<description>A `double` attribute.</description>
156159
</attribute>
160+
<attribute name="elementValue" type="int">
161+
<description>An attribute that can be also be inserted as content of the XML element.</description>
162+
</attribute>
157163
<attribute name="enumAttr" type="example.MyEnum">
158164
<description>An `enum` attribute.</description>
159165
</attribute>

log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyAppender.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.logging.log4j.core.config.plugins.PluginElement;
2727
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
2828
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
29+
import org.apache.logging.log4j.plugins.PluginValue;
2930

3031
/**
3132
* Example plugin
@@ -115,6 +116,11 @@ public static final class Builder extends ParentBuilder
115116

116117
private @PluginBuilderAttribute double undocumentedAttribute;
117118

119+
/**
120+
* An attribute that can be also be inserted as content of the XML element.
121+
*/
122+
private @PluginValue int valueAttribute;
123+
118124
private Object notAnAttribute;
119125

120126
/**

log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j2/MyOldLayout.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.logging.log4j.core.config.plugins.PluginElement;
2222
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
2323
import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
24+
import org.apache.logging.log4j.plugins.PluginValue;
2425

2526
/**
2627
* Example plugin without a builder.
@@ -42,6 +43,7 @@ public final class MyOldLayout implements Layout {
4243
* @param enumAttr An {@code enum} attribute.
4344
* @param nestedLayout An element with multiplicity {@code 1}.
4445
* @param filters An element with multiplicity {@code n}.
46+
* @param valueAttribute An attribute that can be also be inserted as content of the XML element.
4547
*/
4648
@PluginFactory
4749
public static MyOldLayout newLayout(
@@ -57,7 +59,8 @@ public static MyOldLayout newLayout(
5759
final @PluginAttribute("otherName") String origName,
5860
final @PluginAttribute("enumAttr") MyEnum enumAttr,
5961
final @PluginElement("nestedLayout") Layout nestedLayout,
60-
final @PluginElement("filters") Filter[] filters) {
62+
final @PluginElement("filters") Filter[] filters,
63+
final @PluginValue("elementValue") int valueAttribute) {
6164
return null;
6265
}
6366
}

log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyAppender.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.logging.log4j.plugins.PluginBuilderAttribute;
2828
import org.apache.logging.log4j.plugins.PluginElement;
2929
import org.apache.logging.log4j.plugins.PluginFactory;
30+
import org.apache.logging.log4j.plugins.PluginValue;
3031
import org.apache.logging.log4j.plugins.validation.constraints.Required;
3132

3233
/**
@@ -118,6 +119,11 @@ public static final class Builder extends ParentBuilder
118119

119120
private @PluginBuilderAttribute double undocumentedAttribute;
120121

122+
/**
123+
* An attribute that can be also be inserted as content of the XML element.
124+
*/
125+
private @PluginValue int valueAttribute;
126+
121127
private Object notAnAttribute;
122128

123129
/**

log4j-docgen/src/test/resources/DescriptorGeneratorTest/java-of-log4j3/MyOldLayout.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.logging.log4j.plugins.Plugin;
2121
import org.apache.logging.log4j.plugins.PluginAttribute;
2222
import org.apache.logging.log4j.plugins.PluginElement;
23+
import org.apache.logging.log4j.plugins.PluginValue;
2324
import org.apache.logging.log4j.plugins.validation.constraints.Required;
2425

2526
/**
@@ -42,6 +43,7 @@ public final class MyOldLayout implements Layout {
4243
* @param enumAttr An {@code enum} attribute.
4344
* @param nestedLayout An element with multiplicity {@code 1}.
4445
* @param filters An element with multiplicity {@code n}.
46+
* @param valueAttribute An attribute that can be also be inserted as content of the XML element.
4547
*/
4648
@Factory
4749
public static MyOldLayout newLayout(
@@ -57,7 +59,8 @@ public static MyOldLayout newLayout(
5759
final @PluginAttribute("otherName") String origName,
5860
final @PluginAttribute MyEnum enumAttr,
5961
final @PluginElement Layout nestedLayout,
60-
final @PluginElement Filter[] filters) {
62+
final @PluginElement Filter[] filters,
63+
final @PluginValue("elementValue") int valueAttribute) {
6164
return null;
6265
}
6366
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="added">
6+
<description format="asciidoc">Add support for the `@PluginValue` annotation.</description>
7+
</entry>

0 commit comments

Comments
 (0)