Skip to content

Commit

Permalink
Add support for @PluginValue annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ppkarwasz committed May 9, 2024
1 parent 9d822d3 commit a64f2fb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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(
Expand All @@ -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;
}
}
8 changes: 8 additions & 0 deletions src/changelog/0.9.0/add-plugin-value-annotation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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">
<issue id="123" link="https://github.com/apache/logging-log4j-tools/pull/123"/>
<description format="asciidoc">Add support for the `@PluginValue` annotation.</description>
</entry>

0 comments on commit a64f2fb

Please sign in to comment.