vy commented on code in PR #2887:
URL: https://github.com/apache/logging-log4j2/pull/2887#discussion_r1731690092
##########
src/site/antora/modules/ROOT/pages/manual/plugins.adoc:
##########
@@ -281,3 +281,48 @@ See `@PluginElement("EventTemplateAdditionalField")` usage
in {project-github-ur
link:../javadoc/log4j-core/org/apache/logging/log4j/core/config/plugins/util/PluginUtil.html[`PluginUtil`],
which is a convenient wrapper around <<#plugin-discovery,`PluginManager`>>, to
discover and load plugins.
See
{project-github-url}/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolverFactories.java[`TemplateResolverFactories.java`]
for example usages.
+
+[#plugin-merge]
+== Merging plugin descriptors
+
+The plugin descriptor is located in a JAR file at the following fixed location:
+----
+META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
+----
+
+Some deployment techniques like
+https://softwareengineering.stackexchange.com/questions/297276/what-is-a-shaded-java-dependency[shading]
+require multiple plugin descriptors to be merged into one.
+This can be done in multiple ways:
+
+* By using a resource transformer specialized in `Log4j2Plugins.dat` files.
+We are aware of the existence of the following resource transformers for
different Java build tools:
+
+https://maven.apache.org/plugins/maven-shade-plugin/[Maven Shade Plugin]:::
+You can use the
+https://logging.staged.apache.org/log4j/transform/log4j-transform-maven-shade-plugin-extensions.html#log4j-plugin-cache-transformer[Log4j
Plugin Descriptor Transformer].
+
+https://gradleup.com/shadow/[Gradle Shadow Plugin]:::
+You can use the
+https://github.com/GradleUp/shadow/blob/main/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/Log4j2PluginsCacheFileTransformer.groovy[`Log4j2PluginsCacheFileTransformer`].
+
+* Since version `2.24.0` you can any resource transformer capable of
concatenating files using `\n` as separator.
Review Comment:
```suggestion
* Since version `2.24.0`, you can employ any resource transformer capable of
concatenating files using `\n` as separator.
```
##########
src/site/antora/modules/ROOT/pages/manual/plugins.adoc:
##########
@@ -281,3 +281,48 @@ See `@PluginElement("EventTemplateAdditionalField")` usage
in {project-github-ur
link:../javadoc/log4j-core/org/apache/logging/log4j/core/config/plugins/util/PluginUtil.html[`PluginUtil`],
which is a convenient wrapper around <<#plugin-discovery,`PluginManager`>>, to
discover and load plugins.
See
{project-github-url}/log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TemplateResolverFactories.java[`TemplateResolverFactories.java`]
for example usages.
+
+[#plugin-merge]
+== Merging plugin descriptors
+
+The plugin descriptor is located in a JAR file at the following fixed location:
+----
Review Comment:
```suggestion
[source]
----
```
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginCacheTest.java:
##########
@@ -48,9 +42,51 @@ public void
testOutputIsReproducibleWhenInputOrderingChanges() throws IOExceptio
assertArrayEquals(cacheData(cacheA), cacheData(cacheB));
}
- private void createCategory(final PluginCache cache, final String
categoryName, final List<String> entryNames) {
+ @Test
+ void testDeserialize() throws IOException {
+ final PluginCache expected = createSampleCache();
+
+ final Map<String, Map<String, PluginEntry>> actual = new TreeMap<>();
+ PluginCache.loadInputStream(new
ByteArrayInputStream(cacheData(expected)), actual);
+
+ assertThat(actual).as("Deserialized plugin
cache").isEqualTo(expected.getAllCategories());
+ }
+
+ @Test
+ void testConcatenationOfCaches() throws IOException {
+ final ByteArrayOutputStream output = new ByteArrayOutputStream();
+ boolean first = true;
+ for (final String categoryName : Arrays.asList("one", "two")) {
+ final PluginCache cache = new PluginCache();
+ createCategory(cache, categoryName, Arrays.asList("alpha",
"bravo", "charlie"));
+ cache.writeCache(output);
+ if (first) {
+ output.write('\n');
+ first = false;
+ }
+ }
+
+ final Map<String, Map<String, PluginEntry>> actual = new TreeMap<>();
+ PluginCache.loadInputStream(new
ByteArrayInputStream(output.toByteArray()), actual);
+
+ assertThat(actual)
+ .as("Deserialized plugin cache")
+ .isEqualTo(createSampleCache().getAllCategories());
Review Comment:
_Nit:_ I'd prefer `createSampleCache()` accept categories and entries,
instead of assuming hardcoded values will be identical in multiple places.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]