You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2024/02/21 14:21:20 UTC
(logging-log4j-tools) branch main updated (8272aea -> d153adb)
This is an automated email from the ASF dual-hosted git repository.
vy pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
from 8272aea Update `org.codehaus.modello:modello-maven-plugin` to version `2.3.0` (#105)
new c6d465c Syntactic `pom.xml` improvements
new 7a31856 Clean-up `configuration.xml`
new ecab88c Move test resource loading to `TestUtils`
new 6e04662 Simplify test resource access
new a2cde8b Refactor `AsciidocConverterTest`
new 45b991f Rename occurrences of `[Aa]sciidoc` to `[Aa]sciiDoc`
new b6016b3 Improve test resource naming
new 3794610 Refactor `DocGenProcessorTest`
new 660ebc7 Refactor `SchemaGeneratorTest`
new c2b0d29 Close `OutputStream` in `DefaultSchemaGenerator`
new b52747a Refactor `FreeMarkerGeneratorTest`
new 1085e6c Fix typos in `plugins-model.xml`
new 9c9f552 Relocate `log4j-changelog-maven-plugin` to an individual package
new f679d21 Rename `DocGenProcessor` to `DescriptorGenerator`
new 1a7aa68 Removed unnecessary `synchronized` keyword from changelog plugin MOJOs (#80)
new debb643 Add `SchemaGeneratorMojo`
new 15321d7 Add `DocumentationGeneratorMojo`
new b19fc0a Improve package visibility
new 5239946 Rename template files
new 424b431 Improve `scalars.adoc.ftl`
new 4531832 Avoid hardcoded file names in `DocumentationGenerator`
new 23e055c Enhance `DocumentationGenerator` to provide source artifact information
new 757d118 Report the source on `DescriptorGenerator` failures
new 5c183e7 Add `log4j.docgen.descriptorFilePath` argument to `DescriptorGenerator`
new e8b009e Improve empty description handling
new fa8708a Accept path pattern in the `log4j-docgen-maven-plugin`
new f88e7d5 Add group ID, artifact ID, version, and description options to `DescriptorGenerator`
new 6c61b31 Fix `PathMatcherMojo#pathPatterns` javadoc
new d153adb Merge `Documented` into `Type` type in plugin model
The 29 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.
Summary of changes:
.../log4j/{ => changelog/maven}/ExportMojo.java | 4 +-
.../log4j/{ => changelog/maven}/ImportMojo.java | 4 +-
.../log4j/{ => changelog/maven}/ReleaseMojo.java | 4 +-
.../log4j/{ => changelog/maven}/TemplateMojo.java | 2 +-
.../log4j/{ => changelog/maven}/package-info.java | 2 +-
log4j-changelog/pom.xml | 10 +-
.../changelog/exporter/ChangelogExporter.java | 1 +
.../logging/log4j/changelog/util/XmlWriter.java | 10 +-
.../log4j/changelog/ChangelogExporterTest.java | 2 +-
.../log4j/changelog/ChangelogReleaserTest.java | 2 +-
.../log4j/changelog/MavenChangesImporterTest.java | 2 +-
.../pom.xml | 50 ++---
.../docgen/maven/DocumentationGeneratorMojo.java | 99 ++++++++++
.../docgen/maven/DocumentationTemplateMojo.java | 57 ++++++
.../log4j/docgen/maven/PathMatcherMojo.java | 103 +++++++++++
.../logging/log4j/docgen/maven/PluginSets.java | 61 ++++++
.../log4j/docgen/maven/SchemaGeneratorMojo.java | 78 ++++++++
.../logging/log4j/docgen/maven}/package-info.java | 6 +-
log4j-docgen/pom.xml | 32 +++-
.../docgen/generator/ArtifactSourcedType.java | 69 +++++++
.../logging/log4j/docgen/generator/BaseTypes.java | 44 +++++
.../docgen/generator/DocumentationGenerator.java | 97 ++++++++++
.../generator/DocumentationGeneratorArgs.java | 49 +++++
.../docgen/generator/DocumentationTemplate.java | 16 +-
.../SchemaGenerator.java} | 80 ++++----
.../SchemaGeneratorArgs.java} | 23 ++-
.../logging/log4j/docgen/generator/TypeLookup.java | 127 +++++++++++++
.../docgen/{util => generator}/package-info.java | 4 +-
.../internal/DefaultFreeMarkerGenerator.java | 164 ----------------
...sitor.java => AbstractAsciiDocTreeVisitor.java} | 22 +--
...ciidocConverter.java => AsciiDocConverter.java} | 20 +-
.../{AsciidocData.java => AsciiDocData.java} | 8 +-
...cGenProcessor.java => DescriptorGenerator.java} | 206 ++++++++++++++-------
.../logging/log4j/docgen/util/TypeLookup.java | 62 -------
log4j-docgen/src/main/mdo/plugins-model.xml | 148 +--------------
.../log4j/docgen/generator/base-java-types.xml | 66 +++++++
.../log4j/docgen/generator/base-log4j-types.xml | 139 ++++++++++++++
.../log4j/docgen/internal/configuration.xml | 165 -----------------
.../generator/DocumentationGeneratorTest.java | 56 ++++++
.../SchemaGeneratorTest.java | 42 ++---
.../docgen/internal/FreeMarkerGeneratorTest.java | 67 -------
...nverterTest.java => AsciiDocConverterTest.java} | 83 +++++----
.../docgen/processor/DescriptorGeneratorTest.java | 120 ++++++++++++
.../docgen/processor/DocGenProcessorTest.java | 105 -----------
.../plugins-sample.xml => example-plugins.xml} | 0
.../resources/expected/freemarker/scalars.adoc | 87 ---------
.../log4j/plugins.xml => generated-plugins.xml} | 6 +
.../xsd/log4j-config.xsd => generated-plugins.xsd} | 76 +++-----
.../example/JavadocExample.java | 0
.../example/JavadocExample.java} | 9 +-
.../JavadocExample.adoc | 0
.../org.apache.logging.log4j.core.Appender.adoc | 5 +
.../org.apache.logging.log4j.core.Filter.adoc | 5 +
.../org.apache.logging.log4j.core.Layout.adoc | 5 +
...ogging.log4j.core.appender.ConsoleAppender.adoc | 25 ++-
...ache.logging.log4j.core.config.AppenderRef.adoc | 15 +-
....logging.log4j.core.config.AppendersPlugin.adoc | 8 +-
...he.logging.log4j.core.config.Configuration.adoc | 84 ++++-----
...ogging.log4j.core.config.CustomLevelConfig.adoc | 10 +-
...che.logging.log4j.core.config.CustomLevels.adoc | 8 +-
....log4j.core.config.LoggerConfig.RootLogger.adoc | 15 +-
...che.logging.log4j.core.config.LoggerConfig.adoc | 18 +-
...he.logging.log4j.core.config.LoggersPlugin.adoc | 8 +-
...logging.log4j.core.config.PropertiesPlugin.adoc | 8 +-
....apache.logging.log4j.core.config.Property.adoc | 10 +-
...ache.logging.log4j.core.filter.BurstFilter.adoc | 16 +-
...he.logging.log4j.core.layout.PatternLayout.adoc | 8 +-
.../plugins-to-freemarker-output/scalars.adoc | 122 ++++++++++++
.../example/AbstractAppender.java | 0
.../example/Appender.java | 0
.../example/BaseAppender.java | 0
.../example/Filter.java | 0
.../example/Layout.java | 0
.../example/MyAppender.java | 2 +
.../example/MyEnum.java | 3 +-
.../example/MyOldLayout.java | 0
.../example/AbstractAppender.java | 0
.../example/Appender.java | 0
.../example/BaseAppender.java | 0
.../example/Filter.java | 0
.../example/Layout.java | 0
.../example/MyAppender.java | 2 +
.../example/MyEnum.java | 3 +-
.../example/MyOldLayout.java | 0
.../{interface.ftl => interface.adoc.ftl} | 20 +-
.../templates/{license.ftl => license.adoc.ftl} | 0
.../templates/{plugin.ftl => plugin.adoc.ftl} | 39 ++--
.../templates/{scalars.ftl => scalars.adoc.ftl} | 27 +--
.../pom.xml | 46 +----
.../internal/freemarker/util}/FreeMarkerUtils.java | 20 +-
.../pom.xml | 47 +----
.../tools/internal/test/util}/FileTestUtils.java | 6 +-
log4j-tools-parent/pom.xml | 17 ++
pom.xml | 1 +
.../0.5.0/make-maven-plugin-thread-safe.xml | 3 +-
95 files changed, 1975 insertions(+), 1320 deletions(-)
rename log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/{ => changelog/maven}/ExportMojo.java (98%)
rename log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/{ => changelog/maven}/ImportMojo.java (97%)
rename log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/{ => changelog/maven}/ReleaseMojo.java (97%)
rename log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/{ => changelog/maven}/TemplateMojo.java (97%)
copy log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/{ => changelog/maven}/package-info.java (94%)
copy {log4j-changelog-maven-plugin => log4j-docgen-maven-plugin}/pom.xml (66%)
create mode 100644 log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
create mode 100644 log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
create mode 100644 log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java
create mode 100644 log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java
create mode 100644 log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
rename {log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j => log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven}/package-info.java (88%)
create mode 100644 log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ArtifactSourcedType.java
create mode 100644 log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/BaseTypes.java
create mode 100644 log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
create mode 100644 log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
rename log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/CharsetUtils.java => log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationTemplate.java (67%)
rename log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/{internal/DefaultSchemaGenerator.java => generator/SchemaGenerator.java} (85%)
copy log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/{processor/internal/RowImpl.java => generator/SchemaGeneratorArgs.java} (60%)
create mode 100644 log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java
rename log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/{util => generator}/package-info.java (89%)
delete mode 100644 log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultFreeMarkerGenerator.java
rename log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/{AbstractAsciidocTreeVisitor.java => AbstractAsciiDocTreeVisitor.java} (95%)
rename log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/{AsciidocConverter.java => AsciiDocConverter.java} (87%)
rename log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/{AsciidocData.java => AsciiDocData.java} (97%)
rename log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/{DocGenProcessor.java => DescriptorGenerator.java} (81%)
delete mode 100644 log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/TypeLookup.java
create mode 100644 log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml
create mode 100644 log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-log4j-types.xml
delete mode 100644 log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/internal/configuration.xml
create mode 100644 log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
rename log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/{internal => generator}/SchemaGeneratorTest.java (55%)
delete mode 100644 log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
rename log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/{AsciidocConverterTest.java => AsciiDocConverterTest.java} (57%)
create mode 100644 log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
delete mode 100644 log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
rename log4j-docgen/src/test/resources/{META-INF/log4j/plugins-sample.xml => example-plugins.xml} (100%)
delete mode 100644 log4j-docgen/src/test/resources/expected/freemarker/scalars.adoc
rename log4j-docgen/src/test/resources/{expected/processor/META-INF/log4j/plugins.xml => generated-plugins.xml} (96%)
rename log4j-docgen/src/test/resources/{expected/xsd/log4j-config.xsd => generated-plugins.xsd} (89%)
rename log4j-docgen/src/test/resources/{processor/asciidoc => javadoc-input}/example/JavadocExample.java (100%)
copy log4j-docgen/src/test/resources/{processor/v2/example/AbstractAppender.java => javadoc-invalid-input/example/JavadocExample.java} (79%)
rename log4j-docgen/src/test/resources/{expected/processor => javadoc-to-asciidoc-output}/JavadocExample.adoc (100%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.Appender.adoc (90%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.Filter.adoc (87%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.Layout.adoc (83%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc (73%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.AppenderRef.adoc (71%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.AppendersPlugin.adoc (76%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.Configuration.adoc (51%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc (74%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.CustomLevels.adoc (78%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc (74%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.LoggerConfig.adoc (74%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.LoggersPlugin.adoc (77%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc (76%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.config.Property.adoc (74%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.filter.BurstFilter.adoc (74%)
rename log4j-docgen/src/test/resources/{expected/freemarker/Core => plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core}/org.apache.logging.log4j.core.layout.PatternLayout.adoc (81%)
create mode 100644 log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/AbstractAppender.java (100%)
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/Appender.java (100%)
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/BaseAppender.java (100%)
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/Filter.java (100%)
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/Layout.java (100%)
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/MyAppender.java (98%)
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/MyEnum.java (97%)
rename log4j-docgen/src/test/resources/{processor/v2 => plugins-using-log4j2}/example/MyOldLayout.java (100%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/AbstractAppender.java (100%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/Appender.java (100%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/BaseAppender.java (100%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/Filter.java (100%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/Layout.java (100%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/MyAppender.java (98%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/MyEnum.java (97%)
rename log4j-docgen/src/test/resources/{processor/v3 => plugins-using-log4j3}/example/MyOldLayout.java (100%)
rename log4j-docgen/src/test/resources/templates/{interface.ftl => interface.adoc.ftl} (68%)
rename log4j-docgen/src/test/resources/templates/{license.ftl => license.adoc.ftl} (100%)
rename log4j-docgen/src/test/resources/templates/{plugin.ftl => plugin.adoc.ftl} (66%)
rename log4j-docgen/src/test/resources/templates/{scalars.ftl => scalars.adoc.ftl} (60%)
copy {log4j-changelog => log4j-tools-internal-freemarker-util}/pom.xml (58%)
rename {log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter => log4j-tools-internal-freemarker-util/src/main/java/org/apache/logging/log4j/tools/internal/freemarker/util}/FreeMarkerUtils.java (87%)
copy {log4j-changelog => log4j-tools-internal-test-util}/pom.xml (58%)
rename {log4j-changelog/src/test/java/org/apache/logging/log4j/changelog => log4j-tools-internal-test-util/src/main/java/org/apache/logging/log4j/tools/internal/test/util}/FileTestUtils.java (93%)
(logging-log4j-tools) 22/29: Enhance `DocumentationGenerator` to provide source artifact information
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 23e055c0a08f557a7f54f6170dff48829534b3a2
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Mon Feb 19 10:26:27 2024 +0100
Enhance `DocumentationGenerator` to provide source artifact information
---
.../docgen/maven/DocumentationTemplateMojo.java | 24 ++++-
.../docgen/generator/ArtifactSourcedType.java | 69 ++++++++++++
.../docgen/generator/DocumentationGenerator.java | 45 +++++---
.../log4j/docgen/generator/SchemaGenerator.java | 9 +-
.../logging/log4j/docgen/generator/TypeLookup.java | 115 +++++++++++++++-----
.../log4j/docgen/generator/base-java-types.xml | 2 +-
.../generator/DocumentationGeneratorTest.java | 4 +-
.../org.apache.logging.log4j.core.Appender.adoc | 5 +
.../org.apache.logging.log4j.core.Filter.adoc | 5 +
.../org.apache.logging.log4j.core.Layout.adoc | 5 +
...ogging.log4j.core.appender.ConsoleAppender.adoc | 25 +++--
...ache.logging.log4j.core.config.AppenderRef.adoc | 15 ++-
....logging.log4j.core.config.AppendersPlugin.adoc | 8 +-
...he.logging.log4j.core.config.Configuration.adoc | 25 +++--
...ogging.log4j.core.config.CustomLevelConfig.adoc | 10 +-
...che.logging.log4j.core.config.CustomLevels.adoc | 8 +-
....log4j.core.config.LoggerConfig.RootLogger.adoc | 15 ++-
...che.logging.log4j.core.config.LoggerConfig.adoc | 18 +++-
...he.logging.log4j.core.config.LoggersPlugin.adoc | 8 +-
...logging.log4j.core.config.PropertiesPlugin.adoc | 8 +-
....apache.logging.log4j.core.config.Property.adoc | 10 +-
...ache.logging.log4j.core.filter.BurstFilter.adoc | 16 ++-
...he.logging.log4j.core.layout.PatternLayout.adoc | 8 +-
.../plugins-to-freemarker-output/scalars.adoc | 116 +++++++++++++--------
.../test/resources/templates/interface.adoc.ftl | 16 ++-
.../src/test/resources/templates/plugin.adoc.ftl | 35 ++++---
.../src/test/resources/templates/scalars.adoc.ftl | 23 ++--
27 files changed, 484 insertions(+), 163 deletions(-)
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
index f93be5c..1459d8b 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
@@ -21,13 +21,33 @@ import org.apache.maven.plugins.annotations.Parameter;
public final class DocumentationTemplateMojo {
/**
- * The name of the template (e.g., {@code plugin.adoc.ftl}, {@code scalars.adoc.ftl})
+ * The name of the FreeMarker template.
+ * <p>
+ * This corresponds to the file path (relative to {@link DocumentationGeneratorMojo#templateDirectory the template directory}) of the FreeMarker template.
+ * For instance, {@code scalars.adoc.ftl}, {@code plugin.adoc.ftl}, and {@code interface.adoc.ftl} for scalar values, plugins, and interfaces, respectively.
+ * </p>
*/
@Parameter(required = true)
String name;
/**
- * The target file path rendered content will be written to (e.g., {@code %g/%a/%c.adoc})
+ * The target file path rendered content will be written to.
+ * <p>
+ * Certain directives are subject to substitution:
+ * </p>
+ * <ul>
+ * <li>%a – artifact ID, if the type is provided with an artifact origin; {@code unknown-artifactId}, otherwise</li>
+ * <li>%c – class name</li>
+ * <li>%g – group ID, if the type is provided with an artifact origin; {@code unknown-groupId}, otherwise</li>
+ * <li>%v – version, if the type is provided with an artifact origin; {@code unknown-version}, otherwise</li>
+ * </ul>
+ * <p>
+ * For instance,
+ * </p>
+ * <ul>
+ * <li>{@code scalars.adoc} for scalar values</li>
+ * <li>{@code %g/%a/%c.adoc} for interfaces and plugins</li>
+ * </ul>
*/
@Parameter(required = true)
String targetPath;
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ArtifactSourcedType.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ArtifactSourcedType.java
new file mode 100644
index 0000000..e35f233
--- /dev/null
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ArtifactSourcedType.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.generator;
+
+import static java.util.Objects.requireNonNull;
+
+import java.util.Comparator;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.Type;
+import org.jspecify.annotations.Nullable;
+
+public final class ArtifactSourcedType implements Comparable<ArtifactSourcedType> {
+
+ private static final Comparator<ArtifactSourcedType> COMPARATOR = Comparator.<ArtifactSourcedType, String>comparing(
+ sourcedType -> sourcedType.type.getClassName())
+ .thenComparing(sourcedType -> na(sourcedType.groupId))
+ .thenComparing(sourcedType -> na(sourcedType.artifactId))
+ .thenComparing(sourcedType -> na(sourcedType.version));
+
+ private static String na(@Nullable final String value) {
+ return value != null ? value : "N/A";
+ }
+
+ @Nullable
+ public final String groupId;
+
+ @Nullable
+ public final String artifactId;
+
+ @Nullable
+ public final String version;
+
+ public final Type type;
+
+ private ArtifactSourcedType(
+ @Nullable final String groupId,
+ @Nullable final String artifactId,
+ @Nullable final String version,
+ final Type type) {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ this.type = requireNonNull(type, "type");
+ }
+
+ static ArtifactSourcedType ofPluginSet(final PluginSet pluginSet, final Type type) {
+ return new ArtifactSourcedType(pluginSet.getGroupId(), pluginSet.getArtifactId(), pluginSet.getVersion(), type);
+ }
+
+ @Override
+ @SuppressWarnings("NullableProblems")
+ public int compareTo(final ArtifactSourcedType sourcedType) {
+ return COMPARATOR.compare(this, sourcedType);
+ }
+}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
index 38a1237..c2a6871 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
@@ -21,7 +21,6 @@ import static org.apache.logging.log4j.tools.internal.freemarker.util.FreeMarker
import java.nio.file.Path;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
@@ -31,6 +30,8 @@ import org.apache.logging.log4j.docgen.AbstractType;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.ScalarType;
+import org.apache.logging.log4j.docgen.Type;
+import org.jspecify.annotations.Nullable;
public final class DocumentationGenerator {
@@ -41,14 +42,15 @@ public final class DocumentationGenerator {
final List<PluginSet> extendedSets = Stream.concat(BaseTypes.PLUGIN_SETS.stream(), args.pluginSets.stream())
.collect(Collectors.toList());
final TypeLookup lookup = TypeLookup.of(extendedSets);
- final Collection<ScalarType> scalarTypes = new TreeSet<>();
- lookup.forEach((typeKey, type) -> {
+ final Collection<ArtifactSourcedType> scalarTypes = new TreeSet<>();
+ lookup.forEach((className, sourcedType) -> {
+ final Type type = sourcedType.type;
if (type instanceof PluginType) {
- documentAbstractType((AbstractType) type, lookup, args.templateDirectory, args.pluginTemplate);
+ documentAbstractType(sourcedType, lookup, args.templateDirectory, args.pluginTemplate);
} else if (type instanceof AbstractType) {
- documentAbstractType((AbstractType) type, lookup, args.templateDirectory, args.interfaceTemplate);
+ documentAbstractType(sourcedType, lookup, args.templateDirectory, args.interfaceTemplate);
} else if (type instanceof ScalarType) {
- scalarTypes.add((ScalarType) type);
+ scalarTypes.add(sourcedType);
} else {
throw new RuntimeException("unknown type: `" + type + "`");
}
@@ -57,28 +59,39 @@ public final class DocumentationGenerator {
}
private static void documentAbstractType(
- final AbstractType abstractType,
+ final ArtifactSourcedType sourcedType,
final TypeLookup lookup,
final Path templateDirectory,
final DocumentationTemplate template) {
- final Map<String, Object> templateData = new HashMap<>();
- templateData.put("type", abstractType);
- templateData.put("lookup", lookup);
- final Path targetPath = createAbstractTypeTargetPath(abstractType, template.targetPath);
+ final Map<String, Object> templateData = Map.of(
+ "sourcedType", sourcedType,
+ "lookup", lookup);
+ final Path targetPath = createAbstractTypeTargetPath(sourcedType, template.targetPath);
render(templateDirectory, template.name, templateData, targetPath);
}
- private static Path createAbstractTypeTargetPath(final AbstractType abstractType, final String targetPathPattern) {
- final String targetPath = targetPathPattern.replaceAll("%c", abstractType.getClassName());
+ private static Path createAbstractTypeTargetPath(
+ final ArtifactSourcedType sourcedType, final String targetPathPattern) {
+ final String groupId = or(sourcedType.groupId, "unknown-groupId");
+ final String artifactId = or(sourcedType.artifactId, "unknown-artifactId");
+ final String version = or(sourcedType.version, "unknown-version");
+ final String targetPath = targetPathPattern
+ .replaceAll("%g", groupId)
+ .replaceAll("%a", artifactId)
+ .replaceAll("%v", version)
+ .replaceAll("%c", sourcedType.type.getClassName());
return Path.of(targetPath);
}
+ private static String or(@Nullable final String value, final String fallback) {
+ return value != null ? value : fallback;
+ }
+
private static void documentScalarTypes(
- final Collection<ScalarType> scalarTypes,
+ final Collection<ArtifactSourcedType> scalarTypes,
final Path templateDirectory,
final DocumentationTemplate template) {
- final Map<String, Object> templateData = new HashMap<>();
- templateData.put("scalars", scalarTypes);
+ final Map<String, Object> templateData = Map.of("sourcedTypes", scalarTypes);
render(templateDirectory, template.name, templateData, Path.of(template.targetPath));
}
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
index 652086c..ab13a87 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
@@ -101,7 +101,8 @@ public final class SchemaGenerator {
}
private static void writeTypes(final TypeLookup lookup, final XMLStreamWriter writer) throws XMLStreamException {
- for (final Type type : lookup.values()) {
+ for (final ArtifactSourcedType sourcedType : lookup.values()) {
+ final Type type = sourcedType.type;
if (isBuiltinXmlType(type.getClassName())) {
continue;
}
@@ -199,7 +200,7 @@ public final class SchemaGenerator {
implementations.add(abstractType.getClassName());
}
for (final String implementation : implementations) {
- final PluginType pluginType = (PluginType) lookup.get(implementation);
+ final PluginType pluginType = (PluginType) lookup.get(implementation).type;
for (final String key : getKeyAndAliases(pluginType)) {
writer.writeEmptyElement(XSD_NAMESPACE, "element");
writer.writeAttribute("name", key);
@@ -235,7 +236,7 @@ public final class SchemaGenerator {
throws XMLStreamException {
final String type = element.getType();
final String xmlType = getXmlType(lookup, type);
- final AbstractType abstractType = (AbstractType) lookup.get(type);
+ final AbstractType abstractType = (AbstractType) lookup.get(type).type;
final PluginType pluginType = abstractType instanceof PluginType ? (PluginType) abstractType : null;
/*
* If a plugin extends another plugin or has multiple aliases
@@ -287,7 +288,7 @@ public final class SchemaGenerator {
case "java.lang.String":
return "string";
}
- final Type type = lookup.get(className);
+ final ArtifactSourcedType type = lookup.get(className);
if (type != null) {
return LOG4J_PREFIX + ":" + className;
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java
index bde06ff..7aceacd 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java
@@ -16,16 +16,19 @@
*/
package org.apache.logging.log4j.docgen.generator;
-import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.TreeMap;
-import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import org.apache.logging.log4j.docgen.AbstractType;
+import org.apache.logging.log4j.docgen.PluginElement;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.Type;
+import org.jspecify.annotations.Nullable;
-final class TypeLookup extends TreeMap<String, Type> {
+final class TypeLookup extends TreeMap<String, ArtifactSourcedType> {
private static final long serialVersionUID = 1L;
@@ -33,30 +36,92 @@ final class TypeLookup extends TreeMap<String, Type> {
return new TypeLookup(pluginSets);
}
- private TypeLookup(final Iterable<? extends PluginSet> sets) {
- final Predicate<PluginType> hasCoreNamespace = p -> "Core".equals(p.getNamespace());
- // Round 1: Merge all the information from the sets
- sets.forEach(set -> {
- set.getScalars().forEach(scalar -> put(scalar.getClassName(), scalar));
- set.getAbstractTypes().forEach(abstractType -> put(abstractType.getClassName(), abstractType));
- set.getPlugins().stream().filter(hasCoreNamespace).forEach(plugin -> put(plugin.getClassName(), plugin));
+ private TypeLookup(final Iterable<? extends PluginSet> pluginSets) {
+ mergeDescriptors(pluginSets);
+ populateTypeHierarchy(pluginSets);
+ removeUnusedTypes(pluginSets);
+ }
+
+ private void mergeDescriptors(Iterable<? extends PluginSet> pluginSets) {
+ pluginSets.forEach(pluginSet -> {
+ pluginSet.getScalars().forEach(scalar -> {
+ final ArtifactSourcedType sourcedType = ArtifactSourcedType.ofPluginSet(pluginSet, scalar);
+ put(scalar.getClassName(), sourcedType);
+ });
+ pluginSet.getAbstractTypes().forEach(abstractType -> {
+ final ArtifactSourcedType sourcedType = ArtifactSourcedType.ofPluginSet(pluginSet, abstractType);
+ put(abstractType.getClassName(), sourcedType);
+ });
+ pluginSet.getPlugins().forEach(pluginType -> {
+ final ArtifactSourcedType sourcedType = ArtifactSourcedType.ofPluginSet(pluginSet, pluginType);
+ put(pluginType.getClassName(), sourcedType);
+ });
+ });
+ }
+
+ private void populateTypeHierarchy(Iterable<? extends PluginSet> pluginSets) {
+ pluginSets.forEach(pluginSet -> {
+ final Set<PluginType> pluginTypes = pluginSet.getPlugins();
+ pluginTypes.forEach(plugin -> {
+ final Set<String> superTypeClassNames = plugin.getSupertypes();
+ superTypeClassNames.forEach(superTypeClassName -> {
+ final AbstractType sourcedSuperType = getOrPutAbstractType(superTypeClassName, pluginSet);
+ sourcedSuperType.addImplementation(plugin.getClassName());
+ });
+ });
});
- // Round 2: fill in the set of abstract types used in elements and the list of their possible implementations
- final Set<String> requiredAbstractTypes = new HashSet<>();
- sets.forEach(set -> set.getPlugins().stream().filter(hasCoreNamespace).forEach(plugin -> {
- plugin.getSupertypes()
- .forEach(supertype -> ((AbstractType) computeIfAbsent(supertype, TypeLookup::createAbstractType))
- .addImplementation(plugin.getClassName()));
- plugin.getElements().forEach(element -> requiredAbstractTypes.add(element.getType()));
- }));
- // Round 3: remove the types that are not required and do not have a description
- values().removeIf(
- type -> !requiredAbstractTypes.contains(type.getClassName()) && type.getDescription() == null);
}
- private static AbstractType createAbstractType(final String className) {
- final AbstractType abstractType = new AbstractType();
- abstractType.setClassName(className);
- return abstractType;
+ /**
+ * Gets the {@link AbstractType} associated with the provided class name, otherwise puts a new one sourced using the provided {@link PluginSet}.
+ * <h1>Invocation order matters!</h1>
+ * <p>
+ * Consider we are processing {@code plugins.xml}s from following artifacts:
+ * </p>
+ * <ol>
+ * <li>{@code log4j-core} providing {@code Layout}</li>
+ * <li>{@code log4j-layout-template-json} providing {@code JsonTemplateLayout} extending from {@code Layout}
+ * </ol>
+ * <p>
+ * If {@code plugins.xml} of {@code log4j-layout-template-json} gets processed first, {@code Layout} type will be <strong>incorrectly</strong> associated with {@code log4j-layout-template-json}.
+ * Hence, {@code log4j-core} processing needs to happen before the {@code log4j-layout-template-json} processing.
+ * </p>
+ *
+ * @param className a class name
+ * @param pluginSet the descriptor sourcing the type
+ * @return either the existing {@link AbstractType} associated with the provided class name, or a new one created
+ */
+ @Nullable
+ private AbstractType getOrPutAbstractType(final String className, final PluginSet pluginSet) {
+
+ // If there is already an entry with the same class name, return that
+ @Nullable final ArtifactSourcedType foundSourcedType = get(className);
+ if (foundSourcedType != null) {
+ return (AbstractType) foundSourcedType.type;
+ }
+
+ // Otherwise, create a new one, and return that
+ else {
+ final AbstractType type = new AbstractType();
+ type.setClassName(className);
+ final ArtifactSourcedType sourcedType = ArtifactSourcedType.ofPluginSet(pluginSet, type);
+ put(className, sourcedType);
+ return type;
+ }
+ }
+
+ private void removeUnusedTypes(Iterable<? extends PluginSet> pluginSets) {
+ final Set<String> requiredAbstractTypes = StreamSupport.stream(pluginSets.spliterator(), false)
+ .map(PluginSet::getPlugins)
+ .flatMap(Set::stream)
+ .map(PluginType::getElements)
+ .flatMap(List::stream)
+ .map(PluginElement::getType)
+ .collect(Collectors.toSet());
+ values().removeIf(sourcedType -> {
+ final Type type = sourcedType.type;
+ final boolean typeRequired = !requiredAbstractTypes.contains(type.getClassName());
+ return typeRequired && type.getDescription() == null;
+ });
}
}
diff --git a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml
index bc2a8f1..0dd93bc 100644
--- a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml
+++ b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml
@@ -22,7 +22,7 @@
<scalars>
<scalar className="boolean">
- <description>A boolean value.</description>
+ <description>A boolean value</description>
<values>
<value name="false">
<description>false</description>
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
index 8c068ec..6b89139 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
@@ -44,9 +44,9 @@ public class DocumentationGeneratorTest {
new DocumentationTemplate(
"scalars.adoc.ftl", outputDir.resolve("scalars.adoc").toString()),
new DocumentationTemplate(
- "plugin.adoc.ftl", outputDir.resolve("Core/%c.adoc").toString()),
+ "plugin.adoc.ftl", outputDir.resolve("%g/%a/%c.adoc").toString()),
new DocumentationTemplate(
- "interface.adoc.ftl", outputDir.resolve("Core/%c.adoc").toString()));
+ "interface.adoc.ftl", outputDir.resolve("%g/%a/%c.adoc").toString()));
DocumentationGenerator.generateDocumentation(generatorArgs);
// Verify the output
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Appender.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Appender.adoc
similarity index 90%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Appender.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Appender.adoc
index 28c148a..a44c188 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Appender.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Appender.adoc
@@ -14,8 +14,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_Appender]
= Appender
+Class:: `org.apache.logging.log4j.core.Appender`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Appends log events.
An Appender can contain a `Layout` if applicable as well as an `ErrorHandler`.
Typical Appender implementations coordinate with an implementation of `AbstractManager` to handle external resources such as streams, connections, and other shared state.
@@ -27,6 +31,7 @@ For instance, many Appenders can take advantage of the `@OutputStreamManager` cl
It is recommended that Appenders don't do any heavy lifting since there can be many instances of the class being used at any given time.
When resources require locking (e.g., through `@FileLock`), it is important to isolate synchronized code to prevent concurrency issues.
+[#org_apache_logging_log4j_core_Appender-implementations]
== Known implementations
* xref:org.apache.logging.log4j.core.appender.ConsoleAppender.adoc[ConsoleAppender]
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Filter.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Filter.adoc
similarity index 87%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Filter.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Filter.adoc
index 0c852c0..8fb358a 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Filter.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Filter.adoc
@@ -14,14 +14,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_Filter]
= Filter
+Class:: `org.apache.logging.log4j.core.Filter`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Interface that must be implemented to allow custom event filtering.
It is highly recommended that applications make use of the filters provided with this Log4j Core before creating their own.
This interface supports "global" filters (i.e. - all events must pass through them first), attached to specific loggers and associated with Appenders.
It is recommended that, where possible, `Filter` implementations create a generic filtering method that can be called from any of the filter methods.
+[#org_apache_logging_log4j_core_Filter-implementations]
== Known implementations
* xref:org.apache.logging.log4j.core.filter.BurstFilter.adoc[BurstFilter]
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Layout.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Layout.adoc
similarity index 83%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Layout.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Layout.adoc
index 78a1f6c..fcab5e5 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Layout.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.Layout.adoc
@@ -14,10 +14,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_Layout]
= Layout
+Class:: `org.apache.logging.log4j.core.Layout`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
A layout is responsible for formatting a `LogEvent` as a string.
+[#org_apache_logging_log4j_core_Layout-implementations]
== Known implementations
* xref:org.apache.logging.log4j.core.layout.PatternLayout.adoc[PatternLayout]
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
similarity index 73%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
index 59cd3ec..ac5bed4 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
@@ -14,10 +14,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_appender_ConsoleAppender]
= Console
+Class:: `org.apache.logging.log4j.core.appender.ConsoleAppender`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Write log events to the console.
+[#org_apache_logging_log4j_core_appender_ConsoleAppender-XML-snippet]
== XML snippet
[source, xml]
----
@@ -27,11 +32,12 @@ Write log events to the console.
immediateFlush="true"
name=""
target="SYSTEM_OUT">
- ... one Filter element ...
- ... one Layout element ...
+ <a-Filter-implementation/>
+ <a-Layout-implementation/>
</Console>
----
+[#org_apache_logging_log4j_core_appender_ConsoleAppender-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -41,41 +47,42 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|bufferedIo
-|xref:../scalars.adoc#boolean[boolean]
+|xref:../../scalars.adoc#boolean[boolean]
|true
a|If set to `true` (default) the appender will buffer messages before sending them.
This attribute is ignored if `immediateFlush` is set to `true`.
|bufferSize
-|xref:../scalars.adoc#int[int]
+|xref:../../scalars.adoc#int[int]
|
a|Size in bytes of the appender's buffer.
|ignoreExceptions
-|xref:../scalars.adoc#boolean[boolean]
+|xref:../../scalars.adoc#boolean[boolean]
|true
a|If set to `false` logging exceptions will be forwarded to the caller.
|immediateFlush
-|xref:../scalars.adoc#boolean[boolean]
+|xref:../../scalars.adoc#boolean[boolean]
|true
a|If set to `true`, the appender flushes the output stream at each message and
buffering is disabled regardless of the value of `bufferedIo`.
|**name**
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|The name of the appender used in appender references.
Must be unique.
|target
-|xref:../scalars.adoc#org.apache.logging.log4j.core.appender.ConsoleAppender.Target[Target]
+|xref:../../scalars.adoc#org_apache_logging_log4j_core_appender_ConsoleAppender_Target[Target]
|SYSTEM_OUT
a|Specifies the target of the appender.
|===
-== Nested Components
+[#org_apache_logging_log4j_core_appender_ConsoleAppender-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppenderRef.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.AppenderRef.adoc
similarity index 71%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppenderRef.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.AppenderRef.adoc
index 652be60..2aa1f96 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppenderRef.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.AppenderRef.adoc
@@ -14,19 +14,25 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_AppenderRef]
= AppenderRef
+Class:: `org.apache.logging.log4j.core.config.AppenderRef`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Reference to an appender defined in the `Appenders` section.
+[#org_apache_logging_log4j_core_config_AppenderRef-XML-snippet]
== XML snippet
[source, xml]
----
<AppenderRef level=""
ref="">
- ... one Filter element ...
+ <a-Filter-implementation/>
</AppenderRef>
----
+[#org_apache_logging_log4j_core_config_AppenderRef-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -36,18 +42,19 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|level
-|xref:../scalars.adoc#org.apache.logging.log4j.Level[Level]
+|xref:../../scalars.adoc#org_apache_logging_log4j_Level[Level]
|
a|The level to filter against.
|**ref**
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|The name of an appender.
|===
-== Nested Components
+[#org_apache_logging_log4j_core_config_AppenderRef-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
similarity index 76%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
index c8f6334..b4e1e33 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
@@ -14,17 +14,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_AppendersPlugin]
= Appenders
+Class:: `org.apache.logging.log4j.core.config.AppendersPlugin`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
A wrapper for a list of appenders.
+[#org_apache_logging_log4j_core_config_AppendersPlugin-XML-snippet]
== XML snippet
[source, xml]
----
<Appenders/>
----
-== Nested Components
+[#org_apache_logging_log4j_core_config_AppendersPlugin-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Configuration.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.Configuration.adoc
similarity index 80%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Configuration.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.Configuration.adoc
index f7a675e..48742fd 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Configuration.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.Configuration.adoc
@@ -14,10 +14,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_Configuration]
= Configuration
+Class:: `org.apache.logging.log4j.core.config.Configuration`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
A Log4j configuration contains many components of which two are required: `Appenders` and `Loggers`.
+[#org_apache_logging_log4j_core_config_Configuration-XML-snippet]
== XML snippet
[source, xml]
----
@@ -36,6 +41,7 @@ A Log4j configuration contains many components of which two are required: `Appen
</Configuration>
----
+[#org_apache_logging_log4j_core_config_Configuration-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -45,7 +51,7 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|dest
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|err
a|Specifies the destination for status logger events.
The possible values are:
@@ -57,45 +63,46 @@ The possible values are:
If the provided value is invalid, then the default destination of standard out will be used.
|monitorInterval
-|xref:../scalars.adoc#int[int]
+|xref:../../scalars.adoc#int[int]
|0
a|Number of seconds between polls for configuration changes
|**name**
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|Name of the configuration
|schema
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|The name of a classpath resource to use to validate the configuration
|shutdownHook
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|Indicates if Log4j should automatically shut down when the JVM shuts down.
Possible values are `enable` and `disable`.
The shutdown hook is enabled by default, unless Log4j detects the presence of the Servlet API.
|shutdownTimeout
-|xref:../scalars.adoc#int[int]
+|xref:../../scalars.adoc#int[int]
|
a|Timeout in milliseconds of the logger context shut down
|status
-|xref:../scalars.adoc#org.apache.logging.log4j.Level[Level]
+|xref:../../scalars.adoc#org_apache_logging_log4j_Level[Level]
|ERROR
a|Sets the level of the status logger
|strict
-|xref:../scalars.adoc#boolean[boolean]
+|xref:../../scalars.adoc#boolean[boolean]
|false
a|If set to `true` the configuration file will be validated using an XML schema.
|===
-== Nested Components
+[#org_apache_logging_log4j_core_config_Configuration-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
similarity index 74%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
index 411f5ab..eac1689 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
@@ -14,10 +14,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_CustomLevelConfig]
= CustomLevel
+Class:: `org.apache.logging.log4j.core.config.CustomLevelConfig`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Configures a custom level.
+[#org_apache_logging_log4j_core_config_CustomLevelConfig-XML-snippet]
== XML snippet
[source, xml]
----
@@ -25,6 +30,7 @@ Configures a custom level.
name=""/>
----
+[#org_apache_logging_log4j_core_config_CustomLevelConfig-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -34,12 +40,12 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|**intLevel**
-|xref:../scalars.adoc#int[int]
+|xref:../../scalars.adoc#int[int]
|
a|An integer determines the strength of the custom level relative to the built-in levels.
|**name**
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|The name of the level.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevels.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.CustomLevels.adoc
similarity index 78%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevels.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.CustomLevels.adoc
index afc46e5..c10c19b 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevels.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.CustomLevels.adoc
@@ -14,17 +14,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_CustomLevels]
= CustomLevels
+Class:: `org.apache.logging.log4j.core.config.CustomLevels`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
A wrapper for a list of custom level configurations.
+[#org_apache_logging_log4j_core_config_CustomLevels-XML-snippet]
== XML snippet
[source, xml]
----
<CustomLevels/>
----
-== Nested Components
+[#org_apache_logging_log4j_core_config_CustomLevels-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
similarity index 74%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
index cdee35f..0f5ea48 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
@@ -14,20 +14,26 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_LoggerConfig_RootLogger]
= Root
+Class:: `org.apache.logging.log4j.core.config.LoggerConfig.RootLogger`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Configures the root logger
+[#org_apache_logging_log4j_core_config_LoggerConfig_RootLogger-XML-snippet]
== XML snippet
[source, xml]
----
<Root includeLocation=""
level="ERROR">
<AppenderRef/>
- ... one Filter element ...
+ <a-Filter-implementation/>
</Root>
----
+[#org_apache_logging_log4j_core_config_LoggerConfig_RootLogger-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -37,20 +43,21 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|includeLocation
-|xref:../scalars.adoc#boolean[boolean]
+|xref:../../scalars.adoc#boolean[boolean]
|
a|When set to `false` location information will **not** be computed.
The default value depends on the logger context implementation: it is `false` for `AsyncLoggerContext` and `true` for `LoggerContext`.
|level
-|xref:../scalars.adoc#org.apache.logging.log4j.Level[Level]
+|xref:../../scalars.adoc#org_apache_logging_log4j_Level[Level]
|ERROR
a|The level of the logger.
|===
-== Nested Components
+[#org_apache_logging_log4j_core_config_LoggerConfig_RootLogger-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
similarity index 74%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
index 60af05b..b427d1e 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
@@ -14,10 +14,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_LoggerConfig]
= Logger
+Class:: `org.apache.logging.log4j.core.config.LoggerConfig`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Configures a particular logger
+[#org_apache_logging_log4j_core_config_LoggerConfig-XML-snippet]
== XML snippet
[source, xml]
----
@@ -25,10 +30,11 @@ Configures a particular logger
level=""
name="">
<AppenderRef/>
- ... one Filter element ...
+ <a-Filter-implementation/>
</Logger>
----
+[#org_apache_logging_log4j_core_config_LoggerConfig-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -38,25 +44,26 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|includeLocation
-|xref:../scalars.adoc#boolean[boolean]
+|xref:../../scalars.adoc#boolean[boolean]
|
a|When set to `false` location information will **not** be computed.
The default value depends on the logger context implementation: it is `false` for `AsyncLoggerContext` and `true` for `LoggerContext`.
|level
-|xref:../scalars.adoc#org.apache.logging.log4j.Level[Level]
+|xref:../../scalars.adoc#org_apache_logging_log4j_Level[Level]
|
a|The level of the logger.
|**name**
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|The name of the logger.
|===
-== Nested Components
+[#org_apache_logging_log4j_core_config_LoggerConfig-components]
+== Nested components
Required components are in **bold face**.
@@ -74,6 +81,7 @@ a|A filter to filter events, before calling the appenders.
|===
+[#org_apache_logging_log4j_core_config_LoggerConfig-implementations]
== Known implementations
* xref:org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc[RootLogger]
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
similarity index 77%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
index 46063f1..e5aeecf 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
@@ -14,17 +14,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_LoggersPlugin]
= Loggers
+Class:: `org.apache.logging.log4j.core.config.LoggersPlugin`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
A wrapper for a list of logger configurations.
+[#org_apache_logging_log4j_core_config_LoggersPlugin-XML-snippet]
== XML snippet
[source, xml]
----
<Loggers/>
----
-== Nested Components
+[#org_apache_logging_log4j_core_config_LoggersPlugin-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
similarity index 76%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
index ff5613c..4e79408 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
@@ -14,17 +14,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_PropertiesPlugin]
= Properties
+Class:: `org.apache.logging.log4j.core.config.PropertiesPlugin`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
A wrapper for a list of properties.
+[#org_apache_logging_log4j_core_config_PropertiesPlugin-XML-snippet]
== XML snippet
[source, xml]
----
<Properties/>
----
-== Nested Components
+[#org_apache_logging_log4j_core_config_PropertiesPlugin-components]
+== Nested components
Required components are in **bold face**.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Property.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.Property.adoc
similarity index 74%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Property.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.Property.adoc
index d7c55ac..1b01968 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Property.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.config.Property.adoc
@@ -14,10 +14,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_config_Property]
= Property
+Class:: `org.apache.logging.log4j.core.config.Property`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
Represents a key/value pair in the configuration.
+[#org_apache_logging_log4j_core_config_Property-XML-snippet]
== XML snippet
[source, xml]
----
@@ -25,6 +30,7 @@ Represents a key/value pair in the configuration.
value=""/>
----
+[#org_apache_logging_log4j_core_config_Property-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -34,12 +40,12 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|**name**
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|Name of the property.
|value
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|
a|Value of the property.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.filter.BurstFilter.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
similarity index 74%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
index 21d1ab3..a2ba2ad 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
@@ -14,11 +14,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_filter_BurstFilter]
= BurstFilter
+Class:: `org.apache.logging.log4j.core.filter.BurstFilter`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
The BurstFilter is a logging filter that regulates logging traffic.
Use this filter when you want to control the mean rate and maximum burst of log statements that can be sent to an appender.
+[#org_apache_logging_log4j_core_filter_BurstFilter-XML-snippet]
== XML snippet
[source, xml]
----
@@ -29,6 +34,7 @@ Use this filter when you want to control the mean rate and maximum burst of log
rate="10"/>
----
+[#org_apache_logging_log4j_core_filter_BurstFilter-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -38,27 +44,27 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|level
-|xref:../scalars.adoc#org.apache.logging.log4j.Level[Level]
+|xref:../../scalars.adoc#org_apache_logging_log4j_Level[Level]
|WARN
a|Log events less specific than this level are filtered, while events with level equal or more specific always match.
|maxBurst
-|xref:../scalars.adoc#long[long]
+|xref:../../scalars.adoc#long[long]
|
a|Sets the maximum number of events that can occur before events are filtered for exceeding the average rate.
|onMatch
-|xref:../scalars.adoc#org.apache.logging.log4j.core.Filter.Result[Result]
+|xref:../../scalars.adoc#org_apache_logging_log4j_core_Filter_Result[Result]
|NEUTRAL
a|Action to perform if the filter matches.
|onMismatch
-|xref:../scalars.adoc#org.apache.logging.log4j.core.Filter.Result[Result]
+|xref:../../scalars.adoc#org_apache_logging_log4j_core_Filter_Result[Result]
|DENY
a|Action to perform if the filter does not match.
|rate
-|xref:../scalars.adoc#float[float]
+|xref:../../scalars.adoc#float[float]
|10
a|Sets the average number of events per second to allow.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.layout.PatternLayout.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
similarity index 81%
rename from log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
index 23e2180..a567c45 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/org.apache.logging.log4j/log4j-core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
@@ -14,8 +14,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#org_apache_logging_log4j_core_layout_PatternLayout]
= PatternLayout
+Class:: `org.apache.logging.log4j.core.layout.PatternLayout`
+Provider:: `org.apache.logging.log4j:log4j-core`
+
A flexible layout configurable with pattern string.
The goal of this class is to {@link org.apache.logging.log4j.core.Layout#toByteArray format} a {@link LogEvent} and return the results.
@@ -24,12 +28,14 @@ The format of the result depends on the _conversion pattern_.
The conversion pattern is closely related to the conversion pattern of the printf function in C.
A conversion pattern is composed of literal text and format control expressions called _conversion specifiers_.
+[#org_apache_logging_log4j_core_layout_PatternLayout-XML-snippet]
== XML snippet
[source, xml]
----
<PatternLayout pattern="%m%n"/>
----
+[#org_apache_logging_log4j_core_layout_PatternLayout-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -39,7 +45,7 @@ Required attributes are in **bold face**.
|Name|Type|Default|Description
|pattern
-|xref:../scalars.adoc#java.lang.String[String]
+|xref:../../scalars.adoc#java_lang_String[String]
|%m%n
a|The pattern to use to format log events.
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
index 3562590..d147a94 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
@@ -14,48 +14,69 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
////
+[#type-converters]
= Type converters
Type converter plugins are used to convert simple `String` values into other types.
-== Available converters
+[#boolean]
+== `boolean`
-[cols="1m,2"]
-|===
-|Type|Description
-|[[boolean]]
-boolean
-a|A boolean value.
+A boolean value
-Possible values:
+[#boolean-values]
+=== Possible values
`false`:: false
`true`:: true
-|[[byte]]
-byte
-a|An 8-bit signed integer from `-128` to `127`
-|[[double]]
-double
-a|A double precision floating number from `4.94065645841246544e-324` to `1.79769313486231570e+308`
-|[[float]]
-float
-a|A single precision floating number from `1.40239846e-45` to `3.40282347e+38`
-|[[int]]
-int
-a|A 32-bit signed integer from `-2147483648` to `2147483647`
-|[[java.lang.String]]
-java.lang.String
-a|A string of characters
-|[[long]]
-long
-a|A 64-bit signed integer from `-9223372036854775808` to `9223372036854775807`
-|[[org.apache.logging.log4j.Level]]
-o.a.l.l.Level
-a|Represents a logging level.
+
+[#byte]
+== `byte`
+
+
+An 8-bit signed integer from `-128` to `127`
+
+[#double]
+== `double`
+
+
+A double precision floating number from `4.94065645841246544e-324` to `1.79769313486231570e+308`
+
+[#float]
+== `float`
+
+
+A single precision floating number from `1.40239846e-45` to `3.40282347e+38`
+
+[#int]
+== `int`
+
+
+A 32-bit signed integer from `-2147483648` to `2147483647`
+
+[#java_lang_String]
+== `java.lang.String`
+
+
+A string of characters
+
+[#long]
+== `long`
+
+
+A 64-bit signed integer from `-9223372036854775808` to `9223372036854775807`
+
+[#org_apache_logging_log4j_Level]
+== `org.apache.logging.log4j.Level`
+
+Provider:: `org.apache.logging.log4j:log4j-core`
+
+Represents a logging level.
NOTE: The Log4j API supports custom levels, the following list contains only the standard ones.
-Possible values:
+[#org_apache_logging_log4j_Level-values]
+=== Possible values
`OFF`:: Special level that disables logging.
No events should be logged at this level.
@@ -66,23 +87,36 @@ No events should be logged at this level.
`DEBUG`:: A general debugging event
`TRACE`:: A fine-grained debug message, typically capturing the flow through the application
`ALL`:: Special level indicating all events should be logged
-|[[org.apache.logging.log4j.core.Filter.Result]]
-o.a.l.l.core.Filter.Result
-a|The result that can returned from a filter method call.
-Possible values:
+[#org_apache_logging_log4j_core_Filter_Result]
+== `org.apache.logging.log4j.core.Filter.Result`
+
+Provider:: `org.apache.logging.log4j:log4j-core`
+
+The result that can returned from a filter method call.
+
+[#org_apache_logging_log4j_core_Filter_Result-values]
+=== Possible values
`ACCEPT`:: The event will be processed without further filtering based on the log Level.
`NEUTRAL`:: No decision could be made, further filtering should occur.
`DENY`:: The event should not be processed.
-|[[org.apache.logging.log4j.core.appender.ConsoleAppender.Target]]
-o.a.l.l.core.appender.ConsoleAppender.Target
-a|Specifies the target of a console appender.
-Possible values:
+[#org_apache_logging_log4j_core_appender_ConsoleAppender_Target]
+== `org.apache.logging.log4j.core.appender.ConsoleAppender.Target`
+
+Provider:: `org.apache.logging.log4j:log4j-core`
+
+Specifies the target of a console appender.
+
+[#org_apache_logging_log4j_core_appender_ConsoleAppender_Target-values]
+=== Possible values
`SYSTEM_OUT`:: Logs to the standard output.
`SYSTEM_ERR`:: Logs to the standard error.
-|[[short]]
-short
-a|A 16-bit signed integer from `-32768` to `32767`
+
+[#short]
+== `short`
+
+
+A 16-bit signed integer from `-32768` to `32767`
diff --git a/log4j-docgen/src/test/resources/templates/interface.adoc.ftl b/log4j-docgen/src/test/resources/templates/interface.adoc.ftl
index 415107c..5302097 100644
--- a/log4j-docgen/src/test/resources/templates/interface.adoc.ftl
+++ b/log4j-docgen/src/test/resources/templates/interface.adoc.ftl
@@ -15,19 +15,25 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
+<#-- @ftlvariable name="sourcedType" type="org.apache.logging.log4j.docgen.model.ArtifactSourcedType" -->
+<#assign type = sourcedType.type/>
<#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.model.AbstractType" -->
<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
<#include "license.adoc.ftl">
+[#${type.className?replace('.', '_')}]
= ${type.className?keep_after_last('.')}
-<#if type.description??>
+Class:: `${type.className}`
+<#if sourcedType.groupId?has_content && sourcedType.artifactId?has_content>
+Provider:: `${sourcedType.groupId}:${sourcedType.artifactId}`
+
+</#if><#if type.description??>
${type.description.text}
</#if>
+[#${type.className?replace('.', '_')}-implementations]
== Known implementations
-<#if type.implementations??>
- <#list type.implementations as impl>
+<#list type.implementations as impl>
* xref:${impl}.adoc[${impl?contains('.')?then(impl?keep_after_last('.'), impl)}]
- </#list>
-</#if>
+</#list>
diff --git a/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl b/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
index ab4b72b..f219996 100644
--- a/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
+++ b/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
@@ -15,20 +15,28 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
+<#-- @ftlvariable name="sourcedType" type="org.apache.logging.log4j.docgen.model.ArtifactSourcedType" -->
+<#assign type = sourcedType.type/>
<#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.PluginType" -->
<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
<#include "license.adoc.ftl">
+[#${type.className?replace('.', '_')}]
= ${type.name}
-${type.description.text}
+Class:: `${type.className}`
+<#if sourcedType.groupId?has_content && sourcedType.artifactId?has_content>
+Provider:: `${sourcedType.groupId}:${sourcedType.artifactId}`
+</#if>${type.description.text}
+
+[#${type.className?replace('.', '_')}-XML-snippet]
== XML snippet
[source, xml]
----
<#assign tag><${type.name} </#assign>
<#assign indent = tag?replace('.', ' ', 'r')/>
<#assign has_elements = type.elements?size != 0/>
-<#if type.attributes?size == 0>
+<#if !type.attributes?has_content>
<${type.name}/>
<#else>
<#list type.attributes?sort_by('name') as attr>
@@ -40,21 +48,22 @@ ${indent}${attr.name}="${attr.defaultValue!}"${attr?is_last?then(has_elements?th
</#list>
<#if has_elements>
<#list type.elements as element>
- <#assign element_type = lookup[element.type]/>
+ <#assign element_type = lookup[element.type].type/>
<#-- @ftlvariable name="element_type" type="org.apache.logging.log4j.docgen.model.AbstractType" -->
- <#if element_type.name?? && element_type.implementations?size == 0>
+ <#if element_type.name?? && !element_type.implementations?has_content>
<#-- @ftlvariable name="element_type" type="org.apache.logging.log4j.docgen.model.PluginType" -->
<${element_type.name}/>
- <#else>
- ... ${(element.multiplicity == '*')?then('multiple ' + element.type?keep_after_last('.') + ' elements', 'one ' + element.type?keep_after_last('.') + ' element')} ...
+ <#else>
+ <a-${element.type?keep_after_last('.')}-implementation/><#if element.multiplicity == '*'><!-- multiple occurrences allowed --></#if>
</#if>
</#list>
</${type.name}>
</#if>
</#if>
----
-<#if type.attributes?size != 0>
+<#if type.attributes?has_content>
+[#${type.className?replace('.', '_')}-attributes]
== Attributes
Required attributes are in **bold face**.
@@ -65,16 +74,17 @@ Required attributes are in **bold face**.
<#list type.attributes?sort_by('name') as attr>
|${attr.required?then('**', '')}${attr.name}${attr.required?then('**', '')}
-|xref:../scalars.adoc#${attr.type}[${attr.type?contains('.')?then(attr.type?keep_after_last('.'), attr.type)}]
+|xref:../../scalars.adoc#${attr.type?replace('.', '_')}[${attr.type?contains('.')?then(attr.type?keep_after_last('.'), attr.type)}]
|${attr.defaultValue!}
a|${attr.description.text}
</#list>
|===
</#if>
-<#if type.elements?size != 0>
+<#if has_elements>
-== Nested Components
+[#${type.className?replace('.', '_')}-components]
+== Nested components
Required components are in **bold face**.
@@ -83,15 +93,16 @@ Required components are in **bold face**.
|Tag|Type|Description
<#list type.elements?sort_by('type') as element>
-|${element.required?then('**', '') + (lookup[element.type].name!'N/A') + element.required?then('**', '')}
+|${element.required?then('**', '') + (lookup[element.type].type.name!'N/A') + element.required?then('**', '')}
|xref:${element.type}.adoc[${element.type?contains('.')?then(element.type?keep_after_last('.'), element.type)}]
a|${element.description.text}
</#list>
|===
</#if>
-<#if type.implementations?size != 0>
+<#if type.implementations?has_content>
+[#${type.className?replace('.', '_')}-implementations]
== Known implementations
<#list type.implementations as impl>
diff --git a/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
index 6e646c6..5dde191 100644
--- a/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
+++ b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
@@ -15,25 +15,28 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
-<#-- @ftlvariable name="scalars" type="org.apache.logging.log4j.docgen.model.ScalarType[]" -->
+<#-- @ftlvariable name="sourcedTypes" type="org.apache.logging.log4j.docgen.generator.ArtifactSourcedType[]" -->
<#include "license.adoc.ftl">
+[#type-converters]
= Type converters
Type converter plugins are used to convert simple `String` values into other types.
+<#list sourcedTypes as sourcedType>
+<#assign scalar = sourcedType.type/>
+<#-- @ftlvariable name="scalar" type="org.apache.logging.log4j.docgen.model.ScalarType" -->
-== Available converters
+[#${scalar.className?replace('.', '_')}]
+== `${scalar.className}`
-[cols="1m,2"]
-|===
-|Type|Description
+ <#if sourcedType.groupId?has_content && sourcedType.artifactId?has_content>
+Provider:: `${sourcedType.groupId}:${sourcedType.artifactId}`
+ </#if>
-<#list scalars as scalar>
-|[[${scalar.className}]]
-${scalar.className?replace('org.apache.logging.log4j', 'o.a.l.l')}
-a|${scalar.description.text}
+${scalar.description.text}
<#if scalar.values?size != 0>
-Possible values:
+[#${scalar.className?replace('.', '_')}-values]
+=== Possible values
<#list scalar.values as value>
`${value.name}`:: ${value.description.text}
(logging-log4j-tools) 09/29: Refactor `SchemaGeneratorTest`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 660ebc74c15b6a8850a19cf3a1f2083b257c78ea
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 21:00:35 2024 +0100
Refactor `SchemaGeneratorTest`
---
.../docgen/internal/FreeMarkerGeneratorTest.java | 2 +-
.../log4j/docgen/internal/SchemaGeneratorTest.java | 34 +++++++++++-----------
.../plugins-sample.xml => example-plugins.xml} | 0
.../xsd/log4j-config.xsd => generated-plugins.xsd} | 0
4 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
index 1648607..debcdde 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
@@ -34,7 +34,7 @@ public class FreeMarkerGeneratorTest {
@Test
void generatePluginDocumentation() throws Exception {
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- final PluginSet set = reader.read("src/test/resources/META-INF/log4j/plugins-sample.xml");
+ final PluginSet set = reader.read("src/test/resources/example-plugins.xml");
final Path templateDir = Paths.get("src/test/resources/templates");
final Path expectedDirectory = Paths.get("src/test/resources/expected/freemarker");
final Path outputDirectory = Paths.get("target/test-site/freemarker");
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
index 149e0a7..adee706 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
@@ -16,30 +16,27 @@
*/
package org.apache.logging.log4j.docgen.internal;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-
-import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import javax.xml.stream.XMLStreamException;
import javax.xml.transform.Source;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
import org.apache.logging.log4j.docgen.xsd.SchemaGenerator;
import org.apache.logging.log4j.docgen.xsd.SchemaGeneratorRequest;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.CleanupMode;
+import org.junit.jupiter.api.io.TempDir;
import org.xmlunit.assertj3.XmlAssert;
import org.xmlunit.builder.Input;
public class SchemaGeneratorTest {
@Test
- void schemaGeneration() {
+ void schemaGeneration(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir) throws Exception {
final Source xmlSchema =
Input.fromURI("https://www.w3.org/2001/XMLSchema.xsd").build();
- final Path expectedSchema = Paths.get("src/test/resources/expected/xsd/log4j-config.xsd");
- final Path actualSchema = assertDoesNotThrow(SchemaGeneratorTest::generateSchema);
+ final Path expectedSchema = Paths.get("src/test/resources/generated-plugins.xsd");
+ final Path actualSchema = generateSchema(outputDir);
XmlAssert.assertThat(actualSchema)
.isValidAgainst(xmlSchema)
.and(expectedSchema)
@@ -48,17 +45,20 @@ public class SchemaGeneratorTest {
.areIdentical();
}
- private static Path generateSchema() throws XMLStreamException, IOException {
+ private static Path generateSchema(final Path outputDir) throws Exception {
+
+ // Read sample plugins
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- final PluginSet set = reader.read("src/test/resources/META-INF/log4j/plugins-sample.xml");
- final SchemaGenerator generator = new DefaultSchemaGenerator();
- final SchemaGeneratorRequest request = new SchemaGeneratorRequest();
- final Path outputDirectory = Paths.get("target/test-site/xsd");
- Files.createDirectories(outputDirectory);
- request.addPluginSet(set);
- request.setOutputDirectory(outputDirectory);
+ final PluginSet pluginSet = reader.read("src/test/resources/example-plugins.xml");
+ // Generate the schema
+ final SchemaGeneratorRequest request = new SchemaGeneratorRequest();
+ request.addPluginSet(pluginSet);
+ request.setOutputDirectory(outputDir);
+ final SchemaGenerator generator = new DefaultSchemaGenerator();
generator.generateSchema(request);
- return outputDirectory.resolve(request.getFileName());
+
+ // Return the generated XSD file path
+ return outputDir.resolve(request.getFileName());
}
}
diff --git a/log4j-docgen/src/test/resources/META-INF/log4j/plugins-sample.xml b/log4j-docgen/src/test/resources/example-plugins.xml
similarity index 100%
rename from log4j-docgen/src/test/resources/META-INF/log4j/plugins-sample.xml
rename to log4j-docgen/src/test/resources/example-plugins.xml
diff --git a/log4j-docgen/src/test/resources/expected/xsd/log4j-config.xsd b/log4j-docgen/src/test/resources/generated-plugins.xsd
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/xsd/log4j-config.xsd
rename to log4j-docgen/src/test/resources/generated-plugins.xsd
(logging-log4j-tools) 02/29: Clean-up `configuration.xml`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 7a31856f0d78105893c47cf474281b216a0c7257
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 09:24:21 2024 +0100
Clean-up `configuration.xml`
- Fix AsciiDoc typos
- Remove deprecated components
- Remove optional elements (e.g., `<version>`)
---
.../log4j/docgen/internal/configuration.xml | 300 +++++++++++----------
...he.logging.log4j.core.config.Configuration.adoc | 59 ++--
.../resources/expected/freemarker/scalars.adoc | 33 +--
.../test/resources/expected/xsd/log4j-config.xsd | 72 ++---
4 files changed, 223 insertions(+), 241 deletions(-)
diff --git a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/internal/configuration.xml b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/internal/configuration.xml
index e2b8d3f..7e2ad71 100644
--- a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/internal/configuration.xml
+++ b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/internal/configuration.xml
@@ -15,151 +15,167 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<pluginSet xmlns="https://logging.apache.org/xml/ns/plugins"
- version="0.1.0">
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <version>2.22.0</version>
- <description>Reference implementation of the Log4j API.</description>
-
-
- <scalars>
- <!-- Some default scalar types -->
- <scalar className="boolean">
- <description>A boolean value.</description>
- <values>
- <value name="false">
- <description>false</description>
- </value>
- <value name="true">
- <description>true</description>
- </value>
- </values>
- </scalar>
- <scalar className="byte">
- <description>An 8-bit signed integer from -128 to 127.</description>
- </scalar>
- <scalar className="short">
- <description>A 16-bit signed integer from -32768 to 32767.</description>
- </scalar>
- <scalar className="int">
- <description>A 32-bit signed integer from -2147483648 to 2147483647.</description>
- </scalar>
- <scalar className="long">
- <description>A 64-bit signed integer from -9223372036854775808 to 9223372036854775807.</description>
- </scalar>
- <scalar className="float">
- <description>A single precision floating number from 1.40239846e-45 to 3.40282347e+38.</description>
- </scalar>
- <scalar className="double">
- <description>A double precision floating number from 4.94065645841246544e-324 to 1.79769313486231570e+308.</description>
- </scalar>
- <scalar className="java.lang.String">
- <description>A string of characters.</description>
- </scalar>
- <!--
- ~ Level is not a scalar, but for the purpose of the XSD we can limit its values to the standard ones.
- -->
- <scalar className="org.apache.logging.log4j.Level">
- <description>Represents a logging level.
-**Note**: the Log4j API supports custom levels, the following list contains only the standard ones.</description>
- <values>
- <value name="OFF">
- <description>Special level that disables logging. No events should be logged at this level.</description>
- </value>
- <value name="FATAL">
- <description>A fatal event that will prevent the application from continuing.</description>
- </value>
- <value name="ERROR">
- <description>An error in the application, possibly recoverable.</description>
- </value>
- <value name="WARN">
- <description>An event that might possible lead to an error.</description>
- </value>
- <value name="INFO">
- <description>An event for informational purposes.</description>
- </value>
- <value name="DEBUG">
- <description>A general debugging event.</description>
- </value>
- <value name="TRACE">
- <description>A fine-grained debug message, typically capturing the flow through the application.</description>
- </value>
- <value name="ALL">
- <description>All events should be logged.</description>
- </value>
- </values>
- </scalar>
- </scalars>
+<pluginSet xmlns="https://logging.apache.org/xml/ns/plugins" version="0.1.0">
+
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <description>Basic definitions untraceable from the plugin hierarchy.</description>
+
+ <scalars>
+
+ <!-- Primitive type definitions -->
+
+ <scalar className="boolean">
+ <description>A boolean value.</description>
+ <values>
+ <value name="false">
+ <description>false</description>
+ </value>
+ <value name="true">
+ <description>true</description>
+ </value>
+ </values>
+ </scalar>
+
+ <scalar className="byte">
+ <description>An 8-bit signed integer from `-128` to `127`</description>
+ </scalar>
+
+ <scalar className="short">
+ <description>A 16-bit signed integer from `-32768` to `32767`</description>
+ </scalar>
+
+ <scalar className="int">
+ <description>A 32-bit signed integer from `-2147483648` to `2147483647`</description>
+ </scalar>
+
+ <scalar className="long">
+ <description>A 64-bit signed integer from `-9223372036854775808` to `9223372036854775807`</description>
+ </scalar>
+
+ <scalar className="float">
+ <description>A single precision floating number from `1.40239846e-45` to `3.40282347e+38`</description>
+ </scalar>
+
+ <scalar className="double">
+ <description>A double precision floating number from `4.94065645841246544e-324` to `1.79769313486231570e+308`</description>
+ </scalar>
+
+ <scalar className="java.lang.String">
+ <description>A string of characters</description>
+ </scalar>
+
+ <!-- `Level` is not a scalar, but for the purpose of the XSD we can limit its values to the standard ones. -->
+ <scalar className="org.apache.logging.log4j.Level">
+ <description><![CDATA[Represents a logging level.
+NOTE: The Log4j API supports custom levels, the following list contains only the standard ones.]]></description>
+ <values>
+ <value name="OFF">
+ <description><![CDATA[Special level that disables logging.
+No events should be logged at this level.]]></description>
+ </value>
+ <value name="FATAL">
+ <description>A fatal event that will prevent the application from continuing</description>
+ </value>
+ <value name="ERROR">
+ <description>An error in the application, possibly recoverable</description>
+ </value>
+ <value name="WARN">
+ <description>An event that might possible lead to an error</description>
+ </value>
+ <value name="INFO">
+ <description>An event for informational purposes</description>
+ </value>
+ <value name="DEBUG">
+ <description>A general debugging event</description>
+ </value>
+ <value name="TRACE">
+ <description>A fine-grained debug message, typically capturing the flow through the application</description>
+ </value>
+ <value name="ALL">
+ <description>Special level indicating all events should be logged</description>
+ </value>
+ </values>
+ </scalar>
+
+ </scalars>
+
+ <plugins>
<!--
~ The main `Configuration` element is not a plugin, so we add a fake entry for it.
-->
- <plugins>
- <plugin name="Configuration" namespace="Core" className="org.apache.logging.log4j.core.config.Configuration">
- <description>A Log4j 2.x configuration contains many components, two of them `Appenders` and `Loggers` are required.</description>
- <attributes>
- <attribute name="advertiser">
- <description>If set it should contain the name of an `Advertiser` plugin
-(cf. https://logging.apache.org/log4j/2.x/manual/configuration.html#chainsaw-can-automatically-process-your-log-files-advertising-ap[documentation] ).
-Log4j Core provides a single implementation based on JmDNS called `MulticastDns`.</description>
- </attribute>
- <attribute name="dest" defaultValue="err">
- <description>Specifies the destination for StatusLogger events.
+ <plugin name="Configuration" namespace="Core" className="org.apache.logging.log4j.core.config.Configuration">
+
+ <description>A Log4j configuration contains many components of which two are required: `Appenders` and `Loggers`.</description>
+
+ <attributes>
+
+ <attribute name="dest" defaultValue="err">
+ <description><![CDATA[Specifies the destination for status logger events.
The possible values are:
-* `out` for using standard out (default),
-* `err` for using standard error,
-* a string that is interpreted in order as URI, URL or the path to a local file.
-
-If the provided value is invalid, then the default destination of standard out will be used.</description>
- </attribute>
- <attribute name="name" required="true">
- <description>Name of the configuration.</description>
- </attribute>
- <attribute name="monitorInterval" type="int" defaultValue="0">
- <description>Number of seconds between polls for configuration changes.</description>
- </attribute>
- <attribute name="schema">
- <description>The name of a classpath resource to use to validate the configuration.</description>
- </attribute>
- <attribute name="shutdownHook">
- <description>Specifies whether Log4j should automatically shut down when the JVM shuts down.
-Possible values:
-* `enable`: to enable unconditionally the hook,
-* `disable`: to disable unconditionally the hook.
-
-The shutdown hook is enabled by default, unless Log4j Core detects the presence of the Servlet API.</description>
- </attribute>
- <attribute name="shutdownTimeout" type="int">
- <description>Timeout in milliseconds of the logger context shut down.</description>
- </attribute>
- <attribute name="status" type="org.apache.logging.log4j.Level" defaultValue="ERROR">
- <description>Sets the level of the status logger.</description>
- </attribute>
- <attribute name="strict" type="boolean" defaultValue="false">
- <description>If set to `true` the configuration file will be validated using an XML schema.</description>
- </attribute>
- <attribute name="verbose">
- <description>Specifies the verbosity level for the status logger.
-This only applies to classes configured by `StatusConfiguration#setVerboseClasses`.</description>
- </attribute>
- </attributes>
- <elements>
- <element type="org.apache.logging.log4j.core.config.PropertiesPlugin">
- <description>Wrapper element for a list of properties.
-
-If present, this element must be the **first** child of the configuration.</description>
- </element>
- <element type="org.apache.logging.log4j.core.config.AppendersPlugin" required="true">
- <description>Wrapper element for a list of appenders.</description>
- </element>
- <element type="org.apache.logging.log4j.core.config.CustomLevels">
- <description>Wrapper element for a list of custom levels.</description>
- </element>
- <element type="org.apache.logging.log4j.core.config.LoggersPlugin">
- <description>Wrapper element for a list of logger configurations.</description>
- </element>
- </elements>
- </plugin>
- </plugins>
+
+* `out` for using standard out (default)
+* `err` for using standard error
+* a string that is interpreted in order as URI, URL or the path to a local file
+
+If the provided value is invalid, then the default destination of standard out will be used.]]></description>
+ </attribute>
+
+ <attribute name="name" required="true">
+ <description>Name of the configuration</description>
+ </attribute>
+
+ <attribute name="monitorInterval" type="int" defaultValue="0">
+ <description>Number of seconds between polls for configuration changes</description>
+ </attribute>
+
+ <attribute name="schema">
+ <description>The name of a classpath resource to use to validate the configuration</description>
+ </attribute>
+
+ <attribute name="shutdownHook">
+ <description><![CDATA[Indicates if Log4j should automatically shut down when the JVM shuts down.
+Possible values are `enable` and `disable`.
+The shutdown hook is enabled by default, unless Log4j detects the presence of the Servlet API.]]></description>
+ </attribute>
+
+ <attribute name="shutdownTimeout" type="int">
+ <description>Timeout in milliseconds of the logger context shut down</description>
+ </attribute>
+
+ <attribute name="status" type="org.apache.logging.log4j.Level" defaultValue="ERROR">
+ <description>Sets the level of the status logger</description>
+ </attribute>
+
+ <attribute name="strict" type="boolean" defaultValue="false">
+ <description>If set to `true` the configuration file will be validated using an XML schema.</description>
+ </attribute>
+
+ </attributes>
+
+ <elements>
+
+ <element type="org.apache.logging.log4j.core.config.PropertiesPlugin">
+ <description>Wrapper element for a list of properties</description>
+ </element>
+
+ <element type="org.apache.logging.log4j.core.config.AppendersPlugin" required="true">
+ <description>Wrapper element for a list of appenders</description>
+ </element>
+
+ <element type="org.apache.logging.log4j.core.config.CustomLevels">
+ <description>Wrapper element for a list of custom levels</description>
+ </element>
+
+ <element type="org.apache.logging.log4j.core.config.LoggersPlugin">
+ <description>Wrapper element for a list of logger configurations</description>
+ </element>
+
+ </elements>
+
+ </plugin>
+
+ </plugins>
+
</pluginSet>
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Configuration.adoc b/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Configuration.adoc
index 53c5a50..f7a675e 100644
--- a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Configuration.adoc
+++ b/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Configuration.adoc
@@ -16,21 +16,19 @@ limitations under the License.
////
= Configuration
-A Log4j 2.x configuration contains many components, two of them `Appenders` and `Loggers` are required.
+A Log4j configuration contains many components of which two are required: `Appenders` and `Loggers`.
== XML snippet
[source, xml]
----
-<Configuration advertiser=""
- dest="err"
+<Configuration dest="err"
monitorInterval="0"
name=""
schema=""
shutdownHook=""
shutdownTimeout=""
status="ERROR"
- strict="false"
- verbose="">
+ strict="false">
<Properties/>
<Appenders/>
<CustomLevels/>
@@ -46,70 +44,55 @@ Required attributes are in **bold face**.
|===
|Name|Type|Default|Description
-|advertiser
-|xref:../scalars.adoc#java.lang.String[String]
-|
-a|If set it should contain the name of an `Advertiser` plugin
-(cf. https://logging.apache.org/log4j/2.x/manual/configuration.html#chainsaw-can-automatically-process-your-log-files-advertising-ap[documentation] ).
-Log4j Core provides a single implementation based on JmDNS called `MulticastDns`.
-
|dest
|xref:../scalars.adoc#java.lang.String[String]
|err
-a|Specifies the destination for StatusLogger events.
+a|Specifies the destination for status logger events.
The possible values are:
-* `out` for using standard out (default),
-* `err` for using standard error,
-* a string that is interpreted in order as URI, URL or the path to a local file.
+
+* `out` for using standard out (default)
+* `err` for using standard error
+* a string that is interpreted in order as URI, URL or the path to a local file
If the provided value is invalid, then the default destination of standard out will be used.
|monitorInterval
|xref:../scalars.adoc#int[int]
|0
-a|Number of seconds between polls for configuration changes.
+a|Number of seconds between polls for configuration changes
|**name**
|xref:../scalars.adoc#java.lang.String[String]
|
-a|Name of the configuration.
+a|Name of the configuration
|schema
|xref:../scalars.adoc#java.lang.String[String]
|
-a|The name of a classpath resource to use to validate the configuration.
+a|The name of a classpath resource to use to validate the configuration
|shutdownHook
|xref:../scalars.adoc#java.lang.String[String]
|
-a|Specifies whether Log4j should automatically shut down when the JVM shuts down.
-Possible values:
-* `enable`: to enable unconditionally the hook,
-* `disable`: to disable unconditionally the hook.
-
-The shutdown hook is enabled by default, unless Log4j Core detects the presence of the Servlet API.
+a|Indicates if Log4j should automatically shut down when the JVM shuts down.
+Possible values are `enable` and `disable`.
+The shutdown hook is enabled by default, unless Log4j detects the presence of the Servlet API.
|shutdownTimeout
|xref:../scalars.adoc#int[int]
|
-a|Timeout in milliseconds of the logger context shut down.
+a|Timeout in milliseconds of the logger context shut down
|status
|xref:../scalars.adoc#org.apache.logging.log4j.Level[Level]
|ERROR
-a|Sets the level of the status logger.
+a|Sets the level of the status logger
|strict
|xref:../scalars.adoc#boolean[boolean]
|false
a|If set to `true` the configuration file will be validated using an XML schema.
-|verbose
-|xref:../scalars.adoc#java.lang.String[String]
-|
-a|Specifies the verbosity level for the status logger.
-This only applies to classes configured by `StatusConfiguration#setVerboseClasses`.
-
|===
== Nested Components
@@ -122,20 +105,18 @@ Required components are in **bold face**.
|**Appenders**
|xref:org.apache.logging.log4j.core.config.AppendersPlugin.adoc[AppendersPlugin]
-a|Wrapper element for a list of appenders.
+a|Wrapper element for a list of appenders
|CustomLevels
|xref:org.apache.logging.log4j.core.config.CustomLevels.adoc[CustomLevels]
-a|Wrapper element for a list of custom levels.
+a|Wrapper element for a list of custom levels
|Loggers
|xref:org.apache.logging.log4j.core.config.LoggersPlugin.adoc[LoggersPlugin]
-a|Wrapper element for a list of logger configurations.
+a|Wrapper element for a list of logger configurations
|Properties
|xref:org.apache.logging.log4j.core.config.PropertiesPlugin.adoc[PropertiesPlugin]
-a|Wrapper element for a list of properties.
-
-If present, this element must be the **first** child of the configuration.
+a|Wrapper element for a list of properties
|===
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/scalars.adoc b/log4j-docgen/src/test/resources/expected/freemarker/scalars.adoc
index 4ba953c..8393e5c 100644
--- a/log4j-docgen/src/test/resources/expected/freemarker/scalars.adoc
+++ b/log4j-docgen/src/test/resources/expected/freemarker/scalars.adoc
@@ -34,37 +34,38 @@ Possible values:
* `true`: true
|[[byte]]
byte
-a|An 8-bit signed integer from -128 to 127.
+a|An 8-bit signed integer from `-128` to `127`
|[[double]]
double
-a|A double precision floating number from 4.94065645841246544e-324 to 1.79769313486231570e+308.
+a|A double precision floating number from `4.94065645841246544e-324` to `1.79769313486231570e+308`
|[[float]]
float
-a|A single precision floating number from 1.40239846e-45 to 3.40282347e+38.
+a|A single precision floating number from `1.40239846e-45` to `3.40282347e+38`
|[[int]]
int
-a|A 32-bit signed integer from -2147483648 to 2147483647.
+a|A 32-bit signed integer from `-2147483648` to `2147483647`
|[[java.lang.String]]
java.lang.String
-a|A string of characters.
+a|A string of characters
|[[long]]
long
-a|A 64-bit signed integer from -9223372036854775808 to 9223372036854775807.
+a|A 64-bit signed integer from `-9223372036854775808` to `9223372036854775807`
|[[org.apache.logging.log4j.Level]]
o.a.l.l.Level
a|Represents a logging level.
-**Note**: the Log4j API supports custom levels, the following list contains only the standard ones.
+NOTE: The Log4j API supports custom levels, the following list contains only the standard ones.
Possible values:
-* `OFF`: Special level that disables logging. No events should be logged at this level.
-* `FATAL`: A fatal event that will prevent the application from continuing.
-* `ERROR`: An error in the application, possibly recoverable.
-* `WARN`: An event that might possible lead to an error.
-* `INFO`: An event for informational purposes.
-* `DEBUG`: A general debugging event.
-* `TRACE`: A fine-grained debug message, typically capturing the flow through the application.
-* `ALL`: All events should be logged.
+* `OFF`: Special level that disables logging.
+No events should be logged at this level.
+* `FATAL`: A fatal event that will prevent the application from continuing
+* `ERROR`: An error in the application, possibly recoverable
+* `WARN`: An event that might possible lead to an error
+* `INFO`: An event for informational purposes
+* `DEBUG`: A general debugging event
+* `TRACE`: A fine-grained debug message, typically capturing the flow through the application
+* `ALL`: Special level indicating all events should be logged
|[[org.apache.logging.log4j.core.Filter.Result]]
o.a.l.l.core.Filter.Result
a|The result that can returned from a filter method call.
@@ -84,4 +85,4 @@ Possible values:
* `SYSTEM_ERR`: Logs to the standard error.
|[[short]]
short
-a|A 16-bit signed integer from -32768 to 32767.
+a|A 16-bit signed integer from `-32768` to `32767`
diff --git a/log4j-docgen/src/test/resources/expected/xsd/log4j-config.xsd b/log4j-docgen/src/test/resources/expected/xsd/log4j-config.xsd
index 8be9a11..643cda9 100644
--- a/log4j-docgen/src/test/resources/expected/xsd/log4j-config.xsd
+++ b/log4j-docgen/src/test/resources/expected/xsd/log4j-config.xsd
@@ -24,47 +24,48 @@
<simpleType name="org.apache.logging.log4j.Level">
<annotation>
<documentation>Represents a logging level.
-**Note**: the Log4j API supports custom levels, the following list contains only the standard ones.</documentation>
+NOTE: The Log4j API supports custom levels, the following list contains only the standard ones.</documentation>
</annotation>
<restriction base="string">
<enumeration value="OFF">
<annotation>
- <documentation>Special level that disables logging. No events should be logged at this level.</documentation>
+ <documentation>Special level that disables logging.
+No events should be logged at this level.</documentation>
</annotation>
</enumeration>
<enumeration value="FATAL">
<annotation>
- <documentation>A fatal event that will prevent the application from continuing.</documentation>
+ <documentation>A fatal event that will prevent the application from continuing</documentation>
</annotation>
</enumeration>
<enumeration value="ERROR">
<annotation>
- <documentation>An error in the application, possibly recoverable.</documentation>
+ <documentation>An error in the application, possibly recoverable</documentation>
</annotation>
</enumeration>
<enumeration value="WARN">
<annotation>
- <documentation>An event that might possible lead to an error.</documentation>
+ <documentation>An event that might possible lead to an error</documentation>
</annotation>
</enumeration>
<enumeration value="INFO">
<annotation>
- <documentation>An event for informational purposes.</documentation>
+ <documentation>An event for informational purposes</documentation>
</annotation>
</enumeration>
<enumeration value="DEBUG">
<annotation>
- <documentation>A general debugging event.</documentation>
+ <documentation>A general debugging event</documentation>
</annotation>
</enumeration>
<enumeration value="TRACE">
<annotation>
- <documentation>A fine-grained debug message, typically capturing the flow through the application.</documentation>
+ <documentation>A fine-grained debug message, typically capturing the flow through the application</documentation>
</annotation>
</enumeration>
<enumeration value="ALL">
<annotation>
- <documentation>All events should be logged.</documentation>
+ <documentation>Special level indicating all events should be logged</documentation>
</annotation>
</enumeration>
</restriction>
@@ -240,83 +241,72 @@ buffering is disabled regardless of the value of `bufferedIo`.</documentation>
</complexType>
<complexType name="org.apache.logging.log4j.core.config.Configuration">
<annotation>
- <documentation>A Log4j 2.x configuration contains many components, two of them `Appenders` and `Loggers` are required.</documentation>
+ <documentation>A Log4j configuration contains many components of which two are required: `Appenders` and `Loggers`.</documentation>
</annotation>
<sequence>
<element name="Properties" type="log4j:org.apache.logging.log4j.core.config.PropertiesPlugin" minOccurs="0">
<annotation>
- <documentation>Wrapper element for a list of properties.
-
-If present, this element must be the **first** child of the configuration.</documentation>
+ <documentation>Wrapper element for a list of properties</documentation>
</annotation>
</element>
<element name="Appenders" type="log4j:org.apache.logging.log4j.core.config.AppendersPlugin">
<annotation>
- <documentation>Wrapper element for a list of appenders.</documentation>
+ <documentation>Wrapper element for a list of appenders</documentation>
</annotation>
</element>
<element name="CustomLevels" type="log4j:org.apache.logging.log4j.core.config.CustomLevels" minOccurs="0">
<annotation>
- <documentation>Wrapper element for a list of custom levels.</documentation>
+ <documentation>Wrapper element for a list of custom levels</documentation>
</annotation>
</element>
<element name="Loggers" type="log4j:org.apache.logging.log4j.core.config.LoggersPlugin" minOccurs="0">
<annotation>
- <documentation>Wrapper element for a list of logger configurations.</documentation>
+ <documentation>Wrapper element for a list of logger configurations</documentation>
</annotation>
</element>
</sequence>
- <attribute name="advertiser" type="string">
- <annotation>
- <documentation>If set it should contain the name of an `Advertiser` plugin
-(cf. https://logging.apache.org/log4j/2.x/manual/configuration.html#chainsaw-can-automatically-process-your-log-files-advertising-ap[documentation] ).
-Log4j Core provides a single implementation based on JmDNS called `MulticastDns`.</documentation>
- </annotation>
- </attribute>
<attribute name="dest" type="string">
<annotation>
- <documentation>Specifies the destination for StatusLogger events.
+ <documentation>Specifies the destination for status logger events.
The possible values are:
-* `out` for using standard out (default),
-* `err` for using standard error,
-* a string that is interpreted in order as URI, URL or the path to a local file.
+
+* `out` for using standard out (default)
+* `err` for using standard error
+* a string that is interpreted in order as URI, URL or the path to a local file
If the provided value is invalid, then the default destination of standard out will be used.</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
- <documentation>Name of the configuration.</documentation>
+ <documentation>Name of the configuration</documentation>
</annotation>
</attribute>
<attribute name="monitorInterval" type="int">
<annotation>
- <documentation>Number of seconds between polls for configuration changes.</documentation>
+ <documentation>Number of seconds between polls for configuration changes</documentation>
</annotation>
</attribute>
<attribute name="schema" type="string">
<annotation>
- <documentation>The name of a classpath resource to use to validate the configuration.</documentation>
+ <documentation>The name of a classpath resource to use to validate the configuration</documentation>
</annotation>
</attribute>
<attribute name="shutdownHook" type="string">
<annotation>
- <documentation>Specifies whether Log4j should automatically shut down when the JVM shuts down.
-Possible values:
-* `enable`: to enable unconditionally the hook,
-* `disable`: to disable unconditionally the hook.
-
-The shutdown hook is enabled by default, unless Log4j Core detects the presence of the Servlet API.</documentation>
+ <documentation>Indicates if Log4j should automatically shut down when the JVM shuts down.
+Possible values are `enable` and `disable`.
+The shutdown hook is enabled by default, unless Log4j detects the presence of the Servlet API.</documentation>
</annotation>
</attribute>
<attribute name="shutdownTimeout" type="int">
<annotation>
- <documentation>Timeout in milliseconds of the logger context shut down.</documentation>
+ <documentation>Timeout in milliseconds of the logger context shut down</documentation>
</annotation>
</attribute>
<attribute name="status" type="log4j:org.apache.logging.log4j.Level">
<annotation>
- <documentation>Sets the level of the status logger.</documentation>
+ <documentation>Sets the level of the status logger</documentation>
</annotation>
</attribute>
<attribute name="strict" type="boolean">
@@ -324,12 +314,6 @@ The shutdown hook is enabled by default, unless Log4j Core detects the presence
<documentation>If set to `true` the configuration file will be validated using an XML schema.</documentation>
</annotation>
</attribute>
- <attribute name="verbose" type="string">
- <annotation>
- <documentation>Specifies the verbosity level for the status logger.
-This only applies to classes configured by `StatusConfiguration#setVerboseClasses`.</documentation>
- </annotation>
- </attribute>
</complexType>
<complexType name="org.apache.logging.log4j.core.config.CustomLevelConfig">
<annotation>
(logging-log4j-tools) 23/29: Report the source on `DescriptorGenerator` failures
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 757d118571dd71183daa33ebc1c4d2d9c5108521
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Mon Feb 19 14:19:24 2024 +0100
Report the source on `DescriptorGenerator` failures
---
.../docgen/processor/DescriptorGenerator.java | 50 ++++++++++++++--------
.../docgen/processor/AsciiDocConverterTest.java | 2 +-
.../docgen/processor/DescriptorGeneratorTest.java | 10 ++++-
.../example/JavadocExample.java | 26 +++++++++++
4 files changed, 69 insertions(+), 19 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
index 03d0e04..1ae19e3 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
@@ -182,31 +182,47 @@ public class DescriptorGenerator extends AbstractProcessor {
}
private void addPluginDocumentation(final Element element) {
- if (element instanceof TypeElement) {
- final PluginType pluginType = new PluginType();
- pluginType.setName(annotations.getPluginSpecifiedName(element).orElseGet(() -> element.getSimpleName()
- .toString()));
- pluginType.setNamespace(
- annotations.getPluginSpecifiedNamespace(element).orElse("Core"));
- populatePlugin((TypeElement) element, pluginType);
- pluginSet.addPlugin(pluginType);
- } else {
- messager.printMessage(Diagnostic.Kind.WARNING, "Found @Plugin annotation on unexpected element.", element);
+ try {
+ if (element instanceof TypeElement) {
+ final PluginType pluginType = new PluginType();
+ pluginType.setName(annotations.getPluginSpecifiedName(element).orElseGet(() -> element.getSimpleName()
+ .toString()));
+ pluginType.setNamespace(
+ annotations.getPluginSpecifiedNamespace(element).orElse("Core"));
+ populatePlugin((TypeElement) element, pluginType);
+ pluginSet.addPlugin(pluginType);
+ } else {
+ messager.printMessage(
+ Diagnostic.Kind.WARNING, "Found @Plugin annotation on unexpected element.", element);
+ }
+ } catch (final Exception error) {
+ final String message = String.format("failed to process element `%s`", element);
+ throw new RuntimeException(message, error);
}
}
private void addAbstractTypeDocumentation(final QualifiedNameable element) {
- final AbstractType abstractType = new AbstractType();
- populateAbstractType(element, abstractType);
- if (!abstractType.getDescription().getText().isEmpty()) {
- pluginSet.addAbstractType(abstractType);
+ try {
+ final AbstractType abstractType = new AbstractType();
+ populateAbstractType(element, abstractType);
+ if (!abstractType.getDescription().getText().isEmpty()) {
+ pluginSet.addAbstractType(abstractType);
+ }
+ } catch (final Exception error) {
+ final String message = String.format("failed to process element `%s`", element);
+ throw new RuntimeException(message, error);
}
}
private void addScalarTypeDocumentation(final TypeElement element) {
- final ScalarType scalarType = new ScalarType();
- populateScalarType(element, scalarType);
- pluginSet.addScalar(scalarType);
+ try {
+ final ScalarType scalarType = new ScalarType();
+ populateScalarType(element, scalarType);
+ pluginSet.addScalar(scalarType);
+ } catch (final Exception error) {
+ final String message = String.format("failed to process element `%s`", element);
+ throw new RuntimeException(message, error);
+ }
}
private void writePluginDescriptor() {
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
index a1e9233..b650aaf 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
@@ -120,7 +120,7 @@ public class AsciiDocConverterTest {
if (ElementKind.CLASS.equals(element.getKind())
&& TEST_CLASS_NAME.equals(element.getSimpleName().toString())) {
final FileObject output = fileManager.getFileForOutput(
- StandardLocation.CLASS_OUTPUT, "", "JavadocExample.adoc", null);
+ StandardLocation.CLASS_OUTPUT, "", TEST_CLASS_NAME + ".adoc", null);
final String asciiDoc = converter.toAsciiDoc(element);
assertThat(asciiDoc).isNotNull();
try (final OutputStream os = output.openOutputStream()) {
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
index 180041a..201d68c 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.docgen.processor;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -54,6 +55,13 @@ public class DescriptorGeneratorTest {
test(outputDir, Paths.get("src/test/resources/plugins-using-log4j3"));
}
+ @Test
+ void failure_source_should_be_reported(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir) {
+ assertThatThrownBy(() -> test(outputDir, Paths.get("src/test/resources/javadoc-invalid-input")))
+ .hasMessageContaining("failed to process element `example.JavadocExample`")
+ .hasRootCauseMessage("A <li> tag must be a child of a <ol> or <ul> tag.");
+ }
+
private static void test(final Path outputDir, final Path sourceDir) throws Exception {
final Path modelloGeneratedSchema = Paths.get("target/generated-site/resources/xsd/plugins-0.1.0.xsd");
final Path expectedDescriptor = Paths.get("src/test/resources/generated-plugins.xml");
@@ -79,7 +87,7 @@ public class DescriptorGeneratorTest {
sources = fileManager.getJavaFileObjects(sourceFiles);
}
- // Set the target path used by `DocGenProcessor` to dump the generated files
+ // Set the target path used by `DescriptorGenerator` to dump the generated files
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(outputDir));
// Compile the sources
diff --git a/log4j-docgen/src/test/resources/javadoc-invalid-input/example/JavadocExample.java b/log4j-docgen/src/test/resources/javadoc-invalid-input/example/JavadocExample.java
new file mode 100644
index 0000000..3d6f0b2
--- /dev/null
+++ b/log4j-docgen/src/test/resources/javadoc-invalid-input/example/JavadocExample.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package example;
+
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+
+/**
+ * Example class containing invalid JavaDoc
+ * <li>This should not be allowed
+ */
+@Plugin(name = "Foo", category = "Bar")
+public class JavadocExample {}
(logging-log4j-tools) 14/29: Rename `DocGenProcessor` to `DescriptorGenerator`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit f679d2190d5e1b95f20dc785f290251ea13d4f25
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 14 11:56:11 2024 +0100
Rename `DocGenProcessor` to `DescriptorGenerator`
---
.../processor/{DocGenProcessor.java => DescriptorGenerator.java} | 6 +++---
.../{DocGenProcessorTest.java => DescriptorGeneratorTest.java} | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
similarity index 99%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
index 96cbd25..03d0e04 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
@@ -84,7 +84,7 @@ import org.jspecify.annotations.Nullable;
@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
@SupportedAnnotationTypes({"org.apache.logging.log4j.core.config.plugins.*", "org.apache.logging.log4j.plugins.*"})
@NullMarked
-public class DocGenProcessor extends AbstractProcessor {
+public class DescriptorGenerator extends AbstractProcessor {
/**
* The file path generated descriptor will be written to.
@@ -127,11 +127,11 @@ public class DocGenProcessor extends AbstractProcessor {
// Used by reflection
@SuppressWarnings("unused")
- public DocGenProcessor() {
+ public DescriptorGenerator() {
this(new PluginSet());
}
- public DocGenProcessor(final PluginSet pluginSet) {
+ public DescriptorGenerator(final PluginSet pluginSet) {
this.pluginSet = pluginSet;
// Will be initialized later
annotations = null;
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
similarity index 95%
rename from log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
rename to log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
index 9cd1faa..180041a 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
@@ -40,7 +40,7 @@ import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
import org.xmlunit.assertj3.XmlAssert;
-public class DocGenProcessorTest {
+public class DescriptorGeneratorTest {
@Test
void log4j2_plugins_should_be_extracted(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir)
@@ -88,7 +88,7 @@ public class DocGenProcessorTest {
null,
fileManager,
diagnosticCollector,
- asList("-proc:only", "-processor", DocGenProcessor.class.getName()),
+ asList("-proc:only", "-processor", DescriptorGenerator.class.getName()),
null,
sources);
task.call();
@@ -98,7 +98,7 @@ public class DocGenProcessorTest {
assertThat(diagnostics).noneMatch(diagnostic -> diagnostic.getKind() != Diagnostic.Kind.NOTE);
// Resolve the descriptor file
- final Path descriptor = outputDir.resolve(DocGenProcessor.DESCRIPTOR_FILE_PATH);
+ final Path descriptor = outputDir.resolve(DescriptorGenerator.DESCRIPTOR_FILE_PATH);
assertThat(descriptor).isNotEmptyFile();
return descriptor;
}
(logging-log4j-tools) 18/29: Improve package visibility
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit b19fc0a78a3d16c60a006bc28578f26b161a8e51
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Thu Feb 15 15:03:33 2024 +0100
Improve package visibility
---
.../docgen/maven/DocumentationGeneratorMojo.java | 6 ++-
.../log4j/docgen/maven/SchemaGeneratorMojo.java | 8 ++--
.../{internal => generator}/ConfigurationXml.java | 2 +-
.../DocumentationGenerator.java | 25 +++++-----
.../generator/DocumentationGeneratorArgs.java | 53 ++++++++++++++++++++++
.../{internal => generator}/SchemaGenerator.java | 14 +++---
.../SchemaGeneratorArgs.java} | 23 ++++++++--
.../docgen/{util => generator}/TypeLookup.java | 8 ++--
.../docgen/{util => generator}/package-info.java | 4 +-
.../{internal => generator}/configuration.xml | 0
.../DocumentationGeneratorTest.java | 5 +-
.../SchemaGeneratorTest.java | 5 +-
.../src/test/resources/templates/interface.ftl | 2 +-
.../src/test/resources/templates/plugin.ftl | 2 +-
14 files changed, 114 insertions(+), 43 deletions(-)
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
index db7b406..79b0f55 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
@@ -19,7 +19,8 @@ package org.apache.logging.log4j.docgen.maven;
import java.io.File;
import java.util.Set;
import org.apache.logging.log4j.docgen.PluginSet;
-import org.apache.logging.log4j.docgen.internal.DocumentationGenerator;
+import org.apache.logging.log4j.docgen.generator.DocumentationGenerator;
+import org.apache.logging.log4j.docgen.generator.DocumentationGeneratorArgs;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -72,12 +73,13 @@ public class DocumentationGeneratorMojo extends AbstractMojo {
@Override
public void execute() {
final Set<PluginSet> pluginSets = PluginSets.ofDescriptorFiles(descriptorFiles);
- DocumentationGenerator.generateDocumentation(
+ final DocumentationGeneratorArgs generatorArgs = new DocumentationGeneratorArgs(
pluginSets,
templateDirectory.toPath(),
scalarsTemplateName,
pluginTemplateName,
interfaceTemplateName,
outputDirectory.toPath());
+ DocumentationGenerator.generateDocumentation(generatorArgs);
}
}
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
index 3773bd9..a53da90 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
@@ -20,7 +20,8 @@ import java.io.File;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.apache.logging.log4j.docgen.PluginSet;
-import org.apache.logging.log4j.docgen.internal.SchemaGenerator;
+import org.apache.logging.log4j.docgen.generator.SchemaGenerator;
+import org.apache.logging.log4j.docgen.generator.SchemaGeneratorArgs;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -30,7 +31,7 @@ import org.apache.maven.plugins.annotations.Parameter;
/**
* Goal generating an XSD from a given plugin descriptor, e.g., {@code plugins.xml}.
*
- * @see org.apache.logging.log4j.docgen.internal.SchemaGenerator
+ * @see SchemaGenerator
*/
@Mojo(name = "generate-schema", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public class SchemaGeneratorMojo extends AbstractMojo {
@@ -51,7 +52,8 @@ public class SchemaGeneratorMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
final Set<PluginSet> pluginSets = PluginSets.ofDescriptorFiles(descriptorFiles);
try {
- SchemaGenerator.generateSchema(pluginSets, schemaFile.toPath());
+ final SchemaGeneratorArgs generatorArgs = new SchemaGeneratorArgs(pluginSets, schemaFile.toPath());
+ SchemaGenerator.generateSchema(generatorArgs);
} catch (final XMLStreamException error) {
final String message = String.format("failed generating the schema file `%s`", schemaFile);
throw new MojoExecutionException(message, error);
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/ConfigurationXml.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ConfigurationXml.java
similarity index 96%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/ConfigurationXml.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ConfigurationXml.java
index 0dde0f2..40da480 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/ConfigurationXml.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ConfigurationXml.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.docgen.internal;
+package org.apache.logging.log4j.docgen.generator;
import java.io.InputStream;
import org.apache.logging.log4j.docgen.PluginSet;
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DocumentationGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
similarity index 79%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DocumentationGenerator.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
index 2956e34..bf5882a 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DocumentationGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
@@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.docgen.internal;
+package org.apache.logging.log4j.docgen.generator;
+import static java.util.Objects.requireNonNull;
import static org.apache.logging.log4j.tools.internal.freemarker.util.FreeMarkerUtils.render;
import java.nio.file.Path;
@@ -24,7 +25,6 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -33,33 +33,30 @@ import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.ScalarType;
import org.apache.logging.log4j.docgen.Type;
-import org.apache.logging.log4j.docgen.util.TypeLookup;
public final class DocumentationGenerator {
private DocumentationGenerator() {}
- public static void generateDocumentation(
- final Set<PluginSet> pluginSets,
- final Path templateDirectory,
- final String scalarsTemplateName,
- final String pluginTemplateName,
- final String interfaceTemplateName,
- final Path outputDirectory) {
- final List<PluginSet> extendedSets = Stream.concat(Stream.of(ConfigurationXml.PLUGIN_SET), pluginSets.stream())
+ public static void generateDocumentation(final DocumentationGeneratorArgs args) {
+ requireNonNull(args, "args");
+ final List<PluginSet> extendedSets = Stream.concat(
+ Stream.of(ConfigurationXml.PLUGIN_SET), args.pluginSets.stream())
.collect(Collectors.toList());
final TypeLookup lookup = TypeLookup.of(extendedSets);
final Collection<ScalarType> scalarTypes = new TreeSet<>(Comparator.comparing(ScalarType::getClassName));
for (final Type type : lookup.values()) {
if (type instanceof AbstractType) {
- final String template = type instanceof PluginType ? pluginTemplateName : interfaceTemplateName;
- documentAbstractType((AbstractType) type, lookup, templateDirectory, template, outputDirectory);
+ final String template =
+ type instanceof PluginType ? args.pluginTemplateName : args.interfaceTemplateName;
+ documentAbstractType(
+ (AbstractType) type, lookup, args.templateDirectory, template, args.outputDirectory);
}
if (type instanceof ScalarType) {
scalarTypes.add((ScalarType) type);
}
}
- documentScalarTypes(scalarTypes, templateDirectory, scalarsTemplateName, outputDirectory);
+ documentScalarTypes(scalarTypes, args.templateDirectory, args.scalarsTemplateName, args.outputDirectory);
}
private static void documentAbstractType(
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
new file mode 100644
index 0000000..789e317
--- /dev/null
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.generator;
+
+import static java.util.Objects.requireNonNull;
+
+import java.nio.file.Path;
+import java.util.Set;
+import org.apache.logging.log4j.docgen.PluginSet;
+
+public final class DocumentationGeneratorArgs {
+
+ final Set<PluginSet> pluginSets;
+
+ final Path templateDirectory;
+
+ final String scalarsTemplateName;
+
+ final String pluginTemplateName;
+
+ final String interfaceTemplateName;
+
+ final Path outputDirectory;
+
+ public DocumentationGeneratorArgs(
+ final Set<PluginSet> pluginSets,
+ final Path templateDirectory,
+ final String scalarsTemplateName,
+ final String pluginTemplateName,
+ final String interfaceTemplateName,
+ final Path outputDirectory) {
+ this.pluginSets = requireNonNull(pluginSets, "pluginSets");
+ this.templateDirectory = requireNonNull(templateDirectory, "templateDirectory");
+ this.scalarsTemplateName = requireNonNull(scalarsTemplateName, "scalarsTemplateName");
+ this.pluginTemplateName = requireNonNull(pluginTemplateName, "pluginTemplateName");
+ this.interfaceTemplateName = requireNonNull(interfaceTemplateName, "interfaceTemplateName");
+ this.outputDirectory = requireNonNull(outputDirectory, "outputDirectory");
+ }
+}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/SchemaGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
similarity index 97%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/SchemaGenerator.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
index 2d1c862..310fcbd 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/SchemaGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
@@ -14,12 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.docgen.internal;
+package org.apache.logging.log4j.docgen.generator;
+
+import static java.util.Objects.requireNonNull;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -41,7 +42,6 @@ import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.ScalarType;
import org.apache.logging.log4j.docgen.ScalarValue;
import org.apache.logging.log4j.docgen.Type;
-import org.apache.logging.log4j.docgen.util.TypeLookup;
@Singleton
@Named("default")
@@ -59,15 +59,15 @@ public final class SchemaGenerator {
private SchemaGenerator() {}
- public static void generateSchema(final Set<PluginSet> pluginSets, final Path schemaFile)
- throws XMLStreamException {
+ public static void generateSchema(final SchemaGeneratorArgs args) throws XMLStreamException {
+ requireNonNull(args, "args");
try {
final List<PluginSet> extendedSets = Stream.concat(
- Stream.of(ConfigurationXml.PLUGIN_SET), pluginSets.stream())
+ Stream.of(ConfigurationXml.PLUGIN_SET), args.pluginSets.stream())
.collect(Collectors.toList());
final TypeLookup lookup = TypeLookup.of(extendedSets);
final XMLOutputFactory factory = XMLOutputFactory.newFactory();
- try (final OutputStream schemaPathOutputStream = Files.newOutputStream(schemaFile)) {
+ try (final OutputStream schemaPathOutputStream = Files.newOutputStream(args.schemaFile)) {
final XMLStreamWriter writer = factory.createXMLStreamWriter(schemaPathOutputStream, CHARSET_NAME);
try {
writeSchema(lookup, writer);
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/package-info.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGeneratorArgs.java
similarity index 59%
copy from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/package-info.java
copy to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGeneratorArgs.java
index 507fa20..bfb7336 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/package-info.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGeneratorArgs.java
@@ -14,9 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-@Export
-@Version("0.8.0")
-package org.apache.logging.log4j.docgen.util;
+package org.apache.logging.log4j.docgen.generator;
-import org.osgi.annotation.bundle.Export;
-import org.osgi.annotation.versioning.Version;
+import static java.util.Objects.requireNonNull;
+
+import java.nio.file.Path;
+import java.util.Set;
+import org.apache.logging.log4j.docgen.PluginSet;
+
+public final class SchemaGeneratorArgs {
+
+ final Set<PluginSet> pluginSets;
+
+ final Path schemaFile;
+
+ public SchemaGeneratorArgs(final Set<PluginSet> pluginSets, final Path schemaFile) {
+ this.pluginSets = requireNonNull(pluginSets, "pluginSets");
+ this.schemaFile = requireNonNull(schemaFile, "schemaFile");
+ }
+}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/TypeLookup.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java
similarity index 92%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/TypeLookup.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java
index 10986a4..bde06ff 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/TypeLookup.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/TypeLookup.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.docgen.util;
+package org.apache.logging.log4j.docgen.generator;
import java.util.HashSet;
import java.util.Set;
@@ -25,12 +25,12 @@ import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.Type;
-public final class TypeLookup extends TreeMap<String, Type> {
+final class TypeLookup extends TreeMap<String, Type> {
private static final long serialVersionUID = 1L;
- public static TypeLookup of(final Iterable<? extends PluginSet> sets) {
- return new TypeLookup(sets);
+ static TypeLookup of(final Iterable<? extends PluginSet> pluginSets) {
+ return new TypeLookup(pluginSets);
}
private TypeLookup(final Iterable<? extends PluginSet> sets) {
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/package-info.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/package-info.java
similarity index 89%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/package-info.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/package-info.java
index 507fa20..fa97190 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/util/package-info.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/package-info.java
@@ -16,7 +16,9 @@
*/
@Export
@Version("0.8.0")
-package org.apache.logging.log4j.docgen.util;
+@NullMarked
+package org.apache.logging.log4j.docgen.generator;
+import org.jspecify.annotations.NullMarked;
import org.osgi.annotation.bundle.Export;
import org.osgi.annotation.versioning.Version;
diff --git a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/internal/configuration.xml b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/configuration.xml
similarity index 100%
rename from log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/internal/configuration.xml
rename to log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/configuration.xml
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/DocumentationGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
similarity index 90%
rename from log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/DocumentationGeneratorTest.java
rename to log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
index ab4b987..7701c4f 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/DocumentationGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.docgen.internal;
+package org.apache.logging.log4j.docgen.generator;
import static org.apache.logging.log4j.tools.internal.test.util.FileTestUtils.assertDirectoryContentMatches;
@@ -38,8 +38,9 @@ public class DocumentationGeneratorTest {
// Generate the documentation
final Path templateDirectory = Paths.get("src/test/resources/templates");
- DocumentationGenerator.generateDocumentation(
+ final DocumentationGeneratorArgs generatorArgs = new DocumentationGeneratorArgs(
Set.of(pluginSet), templateDirectory, "scalars.ftl", "plugin.ftl", "interface.ftl", outputDir);
+ DocumentationGenerator.generateDocumentation(generatorArgs);
// Verify the output
final Path expectedDir = Paths.get("src/test/resources/plugins-to-freemarker-output");
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/SchemaGeneratorTest.java
similarity index 92%
rename from log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
rename to log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/SchemaGeneratorTest.java
index bb14b9c..d21155f 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/SchemaGeneratorTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.docgen.internal;
+package org.apache.logging.log4j.docgen.generator;
import static org.assertj.core.api.Assertions.assertThat;
@@ -54,7 +54,8 @@ public class SchemaGeneratorTest {
// Generate the schema
final Path schemaFile = outputDir.resolve("config.xsd");
- SchemaGenerator.generateSchema(Set.of(pluginSet), schemaFile);
+ final SchemaGeneratorArgs generatorArgs = new SchemaGeneratorArgs(Set.of(pluginSet), schemaFile);
+ SchemaGenerator.generateSchema(generatorArgs);
// Return the generated XSD file path
assertThat(schemaFile).isNotEmptyFile();
diff --git a/log4j-docgen/src/test/resources/templates/interface.ftl b/log4j-docgen/src/test/resources/templates/interface.ftl
index 11f8818..b7fcb32 100644
--- a/log4j-docgen/src/test/resources/templates/interface.ftl
+++ b/log4j-docgen/src/test/resources/templates/interface.ftl
@@ -16,7 +16,7 @@
limitations under the License.
-->
<#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.model.AbstractType" -->
-<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.util.TypeLookup" -->
+<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
<#include "license.ftl">
= ${type.className?keep_after_last('.')}
<#if type.description??>
diff --git a/log4j-docgen/src/test/resources/templates/plugin.ftl b/log4j-docgen/src/test/resources/templates/plugin.ftl
index 52f3ce8..245a075 100644
--- a/log4j-docgen/src/test/resources/templates/plugin.ftl
+++ b/log4j-docgen/src/test/resources/templates/plugin.ftl
@@ -16,7 +16,7 @@
limitations under the License.
-->
<#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.PluginType" -->
-<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.util.TypeLookup" -->
+<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
<#include "license.ftl">
= ${type.name}
(logging-log4j-tools) 04/29: Simplify test resource access
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 6e04662174a2d4e37a5b9bfe8f8d09dfa0c49c7f
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 10:50:53 2024 +0100
Simplify test resource access
---
.../org/apache/logging/log4j/docgen/TestUtils.java | 58 ----------------------
.../docgen/internal/FreeMarkerGeneratorTest.java | 9 ++--
.../log4j/docgen/internal/SchemaGeneratorTest.java | 7 +--
.../docgen/processor/AsciidocConverterTest.java | 22 ++++----
.../docgen/processor/DocGenProcessorTest.java | 7 +--
5 files changed, 16 insertions(+), 87 deletions(-)
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/TestUtils.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/TestUtils.java
deleted file mode 100644
index 3bd9def..0000000
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/TestUtils.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.docgen;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
-public final class TestUtils {
-
- private TestUtils() {}
-
- public static Path resourcePath(final String name) {
- final URI uri = resourceUri(name);
- return Paths.get(uri);
- }
-
- public static URI resourceUri(final String name) {
- final URL url = resourceUrl(name);
- try {
- return url.toURI();
- } catch (URISyntaxException error) {
- final String message = String.format("failed to obtain URI from URL `%s`", url);
- throw new RuntimeException(message, error);
- }
- }
-
- public static InputStream resourceStream(final String name) throws IOException {
- final URL url = resourceUrl(name);
- return url.openStream();
- }
-
- public static URL resourceUrl(final String name) {
- final URL url = TestUtils.class.getResource(name);
- assertThat(url).as("URL for resource `%s`", name).isNotNull();
- return url;
- }
-}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
index 7b36bca..1648607 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
@@ -16,8 +16,6 @@
*/
package org.apache.logging.log4j.docgen.internal;
-import static org.apache.logging.log4j.docgen.TestUtils.resourcePath;
-import static org.apache.logging.log4j.docgen.TestUtils.resourceStream;
import static org.assertj.core.api.Assertions.assertThat;
import java.nio.charset.StandardCharsets;
@@ -26,7 +24,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.apache.logging.log4j.docgen.PluginSet;
-import org.apache.logging.log4j.docgen.TestUtils;
import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGenerator;
import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGeneratorRequest;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
@@ -37,9 +34,9 @@ public class FreeMarkerGeneratorTest {
@Test
void generatePluginDocumentation() throws Exception {
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- final PluginSet set = reader.read(resourceStream("/META-INF/log4j/plugins-sample.xml"));
- final Path templateDir = TestUtils.resourcePath("/templates");
- final Path expectedDirectory = resourcePath("/expected/freemarker");
+ final PluginSet set = reader.read("src/test/resources/META-INF/log4j/plugins-sample.xml");
+ final Path templateDir = Paths.get("src/test/resources/templates");
+ final Path expectedDirectory = Paths.get("src/test/resources/expected/freemarker");
final Path outputDirectory = Paths.get("target/test-site/freemarker");
final FreeMarkerGenerator generator = new DefaultFreeMarkerGenerator();
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
index 70c0c1a..149e0a7 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
@@ -16,12 +16,9 @@
*/
package org.apache.logging.log4j.docgen.internal;
-import static org.apache.logging.log4j.docgen.TestUtils.resourceStream;
-import static org.apache.logging.log4j.docgen.TestUtils.resourceUrl;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import java.io.IOException;
-import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -41,7 +38,7 @@ public class SchemaGeneratorTest {
void schemaGeneration() {
final Source xmlSchema =
Input.fromURI("https://www.w3.org/2001/XMLSchema.xsd").build();
- final URL expectedSchema = resourceUrl("/expected/xsd/log4j-config.xsd");
+ final Path expectedSchema = Paths.get("src/test/resources/expected/xsd/log4j-config.xsd");
final Path actualSchema = assertDoesNotThrow(SchemaGeneratorTest::generateSchema);
XmlAssert.assertThat(actualSchema)
.isValidAgainst(xmlSchema)
@@ -53,7 +50,7 @@ public class SchemaGeneratorTest {
private static Path generateSchema() throws XMLStreamException, IOException {
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- final PluginSet set = reader.read(resourceStream("/META-INF/log4j/plugins-sample.xml"));
+ final PluginSet set = reader.read("src/test/resources/META-INF/log4j/plugins-sample.xml");
final SchemaGenerator generator = new DefaultSchemaGenerator();
final SchemaGeneratorRequest request = new SchemaGeneratorRequest();
final Path outputDirectory = Paths.get("target/test-site/xsd");
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
index d4191a9..76af48d 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
@@ -17,7 +17,6 @@
package org.apache.logging.log4j.docgen.processor;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.logging.log4j.docgen.TestUtils.resourcePath;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
@@ -28,7 +27,6 @@ import java.nio.file.Paths;
import java.util.List;
import java.util.Locale;
import java.util.Set;
-import java.util.stream.Collectors;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
import javax.tools.Diagnostic;
@@ -48,31 +46,29 @@ import org.junit.jupiter.api.Test;
public class AsciidocConverterTest {
- private static final Path LICENSE_PATH = resourcePath("/templates/license.ftl");
+ private static final Path LICENSE_PATH = Paths.get("src/test/resources/templates/license.ftl");
@Test
void convertToAsciidoc() throws Exception {
final DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
- final DiagnosticCollector<JavaFileObject> ds = new DiagnosticCollector<>();
+ final DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
final StandardJavaFileManager fileManager = tool.getStandardFileManager(null, Locale.ROOT, UTF_8);
- final Path basePath = Paths.get(System.getProperty("basedir", "."));
- final Path sourcePath = resourcePath("/processor/asciidoc/example/JavadocExample.java");
+ final Path sourcePath = Paths.get("src/test/resources/processor/asciidoc/example/JavadocExample.java");
final Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjects(sourcePath);
+ final Path basePath = Paths.get(System.getProperty("basedir", "."));
final Path destPath = basePath.resolve("target/test-site");
Files.createDirectories(destPath);
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(destPath));
- final DocumentationTask task = tool.getTask(null, fileManager, ds, TestDoclet.class, null, sources);
+ final DocumentationTask task =
+ tool.getTask(null, fileManager, diagnosticCollector, TestDoclet.class, null, sources);
task.call();
- final List<String> warnings = ds.getDiagnostics().stream()
- .filter(d -> d.getKind() != Diagnostic.Kind.NOTE)
- .map(d -> d.getMessage(Locale.ROOT))
- .collect(Collectors.toList());
- assertThat(warnings).isEmpty();
- final Path expectedPath = resourcePath("/expected/processor/JavadocExample.adoc");
+ List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticCollector.getDiagnostics();
+ assertThat(diagnostics).noneMatch(diagnostic -> diagnostic.getKind() != Diagnostic.Kind.NOTE);
+ final Path expectedPath = Paths.get("src/test/resources/expected/processor/JavadocExample.adoc");
assertThat(destPath.resolve("processor/JavadocExample.adoc")).hasSameTextualContentAs(expectedPath, UTF_8);
}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
index 5b1db38..e2b6af3 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
@@ -16,12 +16,9 @@
*/
package org.apache.logging.log4j.docgen.processor;
-import static org.apache.logging.log4j.docgen.TestUtils.resourcePath;
-import static org.apache.logging.log4j.docgen.TestUtils.resourceUrl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -55,7 +52,7 @@ public class DocGenProcessorTest {
void descriptorGenerationSucceeds(final String version) {
final Path basePath = Paths.get(System.getProperty("basedir", "."));
final Path schema = basePath.resolve("target/generated-site/resources/xsd/plugins-0.1.0.xsd");
- final URL expected = resourceUrl("/expected/processor/META-INF/log4j/plugins.xml");
+ final Path expected = Paths.get("src/test/resources/expected/processor/META-INF/log4j/plugins.xml");
final Path actual = assertDoesNotThrow(() -> generateDescriptor(version));
XmlAssert.assertThat(actual)
.isValidAgainst(schema)
@@ -72,7 +69,7 @@ public class DocGenProcessorTest {
compiler.getStandardFileManager(null, Locale.ROOT, StandardCharsets.UTF_8);
final Path basePath = Paths.get(System.getProperty("basedir", "."));
- final Path sourcePath = resourcePath("/processor/" + version);
+ final Path sourcePath = Paths.get("src/test/resources/processor/" + version);
final Iterable<? extends JavaFileObject> sources;
try (final Stream<Path> files = Files.walk(sourcePath)) {
sources = fileManager.getJavaFileObjects(
(logging-log4j-tools) 08/29: Refactor `DocGenProcessorTest`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 3794610c1d55f37b174abddde8fd6fa38544b43c
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 13:26:31 2024 +0100
Refactor `DocGenProcessorTest`
---
.../log4j/docgen/processor/DocGenProcessor.java | 18 ++---
.../docgen/processor/AsciiDocConverterTest.java | 3 +-
.../docgen/processor/DocGenProcessorTest.java | 79 +++++++++++-----------
.../log4j/plugins.xml => generated-plugins.xml} | 0
.../example/AbstractAppender.java | 0
.../example/Appender.java | 0
.../example/BaseAppender.java | 0
.../example/Filter.java | 0
.../example/Layout.java | 0
.../example/MyAppender.java | 0
.../example/MyEnum.java | 0
.../example/MyOldLayout.java | 0
.../example/AbstractAppender.java | 0
.../example/Appender.java | 0
.../example/BaseAppender.java | 0
.../example/Filter.java | 0
.../example/Layout.java | 0
.../example/MyAppender.java | 0
.../example/MyEnum.java | 0
.../example/MyOldLayout.java | 0
20 files changed, 52 insertions(+), 48 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
index 57eb55c..96cbd25 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
@@ -86,6 +86,11 @@ import org.jspecify.annotations.Nullable;
@NullMarked
public class DocGenProcessor extends AbstractProcessor {
+ /**
+ * The file path generated descriptor will be written to.
+ */
+ public static final String DESCRIPTOR_FILE_PATH = "META-INF/log4j/plugins.xml";
+
private static final String MULTIPLICITY_UNBOUNDED = "*";
private static final CharSequence[] GETTER_SETTER_PREFIXES = {"get", "is", "set"};
/**
@@ -126,7 +131,6 @@ public class DocGenProcessor extends AbstractProcessor {
this(new PluginSet());
}
- @SuppressWarnings("DataFlowIssue")
public DocGenProcessor(final PluginSet pluginSet) {
this.pluginSet = pluginSet;
// Will be initialized later
@@ -207,17 +211,15 @@ public class DocGenProcessor extends AbstractProcessor {
private void writePluginDescriptor() {
try {
- final FileObject output = processingEnv
- .getFiler()
- .createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/log4j/plugins.xml");
+ final FileObject output =
+ processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", DESCRIPTOR_FILE_PATH);
try (final Writer writer = output.openWriter()) {
new PluginBundleStaxWriter().write(writer, pluginSet);
}
- } catch (final IOException | XMLStreamException e) {
- messager.printMessage(
- Diagnostic.Kind.ERROR,
- "An error occurred while writing to `META-INF/log4j/plugins.xml`: " + e.getMessage());
+ } catch (final IOException | XMLStreamException error) {
+ final String message = String.format("An error occurred while writing to `%s`", DESCRIPTOR_FILE_PATH);
+ throw new RuntimeException(message, error);
}
}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
index d70358c..90be680 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
@@ -66,8 +66,7 @@ public class AsciiDocConverterTest {
final StandardJavaFileManager fileManager = tool.getStandardFileManager(null, Locale.ROOT, CHARSET);
// Populate sources (aka. compilation units)
- final Path sourcePath =
- Paths.get("src/test/resources/javadoc-input/example/" + TEST_CLASS_NAME + ".java");
+ final Path sourcePath = Paths.get("src/test/resources/javadoc-input/example/" + TEST_CLASS_NAME + ".java");
final Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjects(sourcePath);
// Set the target path used by `Javadoc2AsciiDocDoclet` to dump the generated files
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
index e2b6af3..9cd1faa 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
@@ -16,18 +16,16 @@
*/
package org.apache.logging.log4j.docgen.processor;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Set;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
@@ -37,65 +35,70 @@ import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.CleanupMode;
+import org.junit.jupiter.api.io.TempDir;
import org.xmlunit.assertj3.XmlAssert;
public class DocGenProcessorTest {
- static Stream<String> descriptorGenerationSucceeds() {
- return Stream.of("v2", "v3");
+ @Test
+ void log4j2_plugins_should_be_extracted(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir)
+ throws Exception {
+ test(outputDir, Paths.get("src/test/resources/plugins-using-log4j2"));
}
- @ParameterizedTest
- @MethodSource
- void descriptorGenerationSucceeds(final String version) {
- final Path basePath = Paths.get(System.getProperty("basedir", "."));
- final Path schema = basePath.resolve("target/generated-site/resources/xsd/plugins-0.1.0.xsd");
- final Path expected = Paths.get("src/test/resources/expected/processor/META-INF/log4j/plugins.xml");
- final Path actual = assertDoesNotThrow(() -> generateDescriptor(version));
- XmlAssert.assertThat(actual)
- .isValidAgainst(schema)
- .and(expected)
+ @Test
+ void log4j3_plugins_should_be_extracted(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir)
+ throws Exception {
+ test(outputDir, Paths.get("src/test/resources/plugins-using-log4j3"));
+ }
+
+ private static void test(final Path outputDir, final Path sourceDir) throws Exception {
+ final Path modelloGeneratedSchema = Paths.get("target/generated-site/resources/xsd/plugins-0.1.0.xsd");
+ final Path expectedDescriptor = Paths.get("src/test/resources/generated-plugins.xml");
+ final Path actualDescriptor = generateDescriptor(outputDir, sourceDir);
+ XmlAssert.assertThat(actualDescriptor)
+ .isValidAgainst(modelloGeneratedSchema)
+ .and(expectedDescriptor)
.ignoreComments()
.ignoreWhitespace()
.areIdentical();
}
- private static Path generateDescriptor(final String version) throws Exception {
+ private static Path generateDescriptor(final Path outputDir, final Path sourceDir) throws Exception {
+
+ // Instantiate the tooling
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- final DiagnosticCollector<JavaFileObject> ds = new DiagnosticCollector<>();
- final StandardJavaFileManager fileManager =
- compiler.getStandardFileManager(null, Locale.ROOT, StandardCharsets.UTF_8);
+ final StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, Locale.ROOT, UTF_8);
- final Path basePath = Paths.get(System.getProperty("basedir", "."));
- final Path sourcePath = Paths.get("src/test/resources/processor/" + version);
+ // Populate sources
final Iterable<? extends JavaFileObject> sources;
- try (final Stream<Path> files = Files.walk(sourcePath)) {
- sources = fileManager.getJavaFileObjects(
- files.filter(Files::isRegularFile).toArray(Path[]::new));
+ try (final Stream<Path> files = Files.walk(sourceDir)) {
+ Path[] sourceFiles = files.filter(Files::isRegularFile).toArray(Path[]::new);
+ sources = fileManager.getJavaFileObjects(sourceFiles);
}
- final Path destPath = basePath.resolve("target/test-site/processor/" + version);
- Files.createDirectories(destPath);
- fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(destPath));
+ // Set the target path used by `DocGenProcessor` to dump the generated files
+ fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(outputDir));
+ // Compile the sources
+ final DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
final CompilationTask task = compiler.getTask(
null,
fileManager,
- ds,
- Arrays.asList("-proc:only", "-processor", DocGenProcessor.class.getName()),
+ diagnosticCollector,
+ asList("-proc:only", "-processor", DocGenProcessor.class.getName()),
null,
sources);
task.call();
- final List<String> warnings = ds.getDiagnostics().stream()
- .filter(d -> d.getKind() != Diagnostic.Kind.NOTE)
- .map(d -> d.getMessage(Locale.ROOT))
- .collect(Collectors.toList());
- assertThat(warnings).isEmpty();
+ // Verify successful compilation
+ List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticCollector.getDiagnostics();
+ assertThat(diagnostics).noneMatch(diagnostic -> diagnostic.getKind() != Diagnostic.Kind.NOTE);
- final Path descriptor = destPath.resolve("META-INF/log4j/plugins.xml");
+ // Resolve the descriptor file
+ final Path descriptor = outputDir.resolve(DocGenProcessor.DESCRIPTOR_FILE_PATH);
assertThat(descriptor).isNotEmptyFile();
return descriptor;
}
diff --git a/log4j-docgen/src/test/resources/expected/processor/META-INF/log4j/plugins.xml b/log4j-docgen/src/test/resources/generated-plugins.xml
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/processor/META-INF/log4j/plugins.xml
rename to log4j-docgen/src/test/resources/generated-plugins.xml
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/AbstractAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/AbstractAppender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/AbstractAppender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/AbstractAppender.java
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/Appender.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/Appender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/Appender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/Appender.java
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/BaseAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/BaseAppender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/BaseAppender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/BaseAppender.java
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/Filter.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/Filter.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/Filter.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/Filter.java
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/Layout.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/Layout.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/Layout.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/Layout.java
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/MyAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyAppender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/MyAppender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyAppender.java
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/MyEnum.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyEnum.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/MyEnum.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyEnum.java
diff --git a/log4j-docgen/src/test/resources/processor/v2/example/MyOldLayout.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyOldLayout.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v2/example/MyOldLayout.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyOldLayout.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/AbstractAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/AbstractAppender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/AbstractAppender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/AbstractAppender.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/Appender.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/Appender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/Appender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/Appender.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/BaseAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/BaseAppender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/BaseAppender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/BaseAppender.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/Filter.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/Filter.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/Filter.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/Filter.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/Layout.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/Layout.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/Layout.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/Layout.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/MyAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyAppender.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/MyAppender.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyAppender.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/MyEnum.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyEnum.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/MyEnum.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyEnum.java
diff --git a/log4j-docgen/src/test/resources/processor/v3/example/MyOldLayout.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyOldLayout.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/v3/example/MyOldLayout.java
rename to log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyOldLayout.java
(logging-log4j-tools) 27/29: Add group ID, artifact ID, version, and description options to `DescriptorGenerator`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit f88e7d50d990b3a0076197881fa1a08f77eccaa5
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 21 13:31:42 2024 +0100
Add group ID, artifact ID, version, and description options to `DescriptorGenerator`
---
.../docgen/processor/DescriptorGenerator.java | 60 ++++++++++++++++++----
.../docgen/processor/DescriptorGeneratorTest.java | 6 ++-
.../src/test/resources/generated-plugins.xml | 4 ++
3 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
index d3f0a6e..f4cfd4e 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
@@ -83,11 +83,25 @@ import org.jspecify.annotations.Nullable;
@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
@SupportedAnnotationTypes({"org.apache.logging.log4j.core.config.plugins.*", "org.apache.logging.log4j.plugins.*"})
-@SupportedOptions({DescriptorGenerator.DESCRIPTOR_FILE_PATH_PROPERTY_NAME})
+@SupportedOptions({
+ DescriptorGenerator.DESCRIPTOR_FILE_PATH_OPTION_KEY,
+ DescriptorGenerator.GROUP_ID_OPTION_KEY,
+ DescriptorGenerator.ARTIFACT_ID_OPTION_KEY,
+ DescriptorGenerator.VERSION_OPTION_KEY,
+ DescriptorGenerator.DESCRIPTION_OPTION_KEY
+})
@NullMarked
public class DescriptorGenerator extends AbstractProcessor {
- static final String DESCRIPTOR_FILE_PATH_PROPERTY_NAME = "log4j.docgen.descriptorFilePath";
+ static final String DESCRIPTOR_FILE_PATH_OPTION_KEY = "log4j.docgen.descriptorFilePath";
+
+ static final String GROUP_ID_OPTION_KEY = "log4j.docgen.groupId";
+
+ static final String ARTIFACT_ID_OPTION_KEY = "log4j.docgen.artifactId";
+
+ static final String VERSION_OPTION_KEY = "log4j.docgen.version";
+
+ static final String DESCRIPTION_OPTION_KEY = "log4j.docgen.description";
private static final String MULTIPLICITY_UNBOUNDED = "*";
@@ -107,14 +121,14 @@ public class DescriptorGenerator extends AbstractProcessor {
"java.lang.Double",
"java.lang.String");
- private final PluginSet pluginSet = new PluginSet();
-
// Abstract types to process
private final Collection<TypeElement> abstractTypesToDocument = new HashSet<>();
// Scalar types to process
private final Collection<TypeElement> scalarTypesToDocument = new HashSet<>();
+ private PluginSet pluginSet;
+
private Path descriptorFilePath;
private DocTrees docTrees;
@@ -138,7 +152,8 @@ public class DescriptorGenerator extends AbstractProcessor {
@Override
public synchronized void init(final ProcessingEnvironment processingEnv) {
super.init(processingEnv);
- descriptorFilePath = getDescriptorFilePath(processingEnv);
+ pluginSet = createPluginSet(processingEnv);
+ descriptorFilePath = Path.of(requireOption(processingEnv, DESCRIPTOR_FILE_PATH_OPTION_KEY));
docTrees = DocTrees.instance(processingEnv);
elements = processingEnv.getElementUtils();
messager = processingEnv.getMessager();
@@ -149,13 +164,36 @@ public class DescriptorGenerator extends AbstractProcessor {
enumType = getDeclaredType(processingEnv, "java.lang.Enum");
}
- private static Path getDescriptorFilePath(final ProcessingEnvironment processingEnv) {
- @Nullable String descriptorFilePath = processingEnv.getOptions().get(DESCRIPTOR_FILE_PATH_PROPERTY_NAME);
- if (StringUtils.isBlank(descriptorFilePath)) {
- final String message = String.format("missing property: `%s`", DESCRIPTOR_FILE_PATH_PROPERTY_NAME);
- throw new IllegalStateException(message);
+ private static PluginSet createPluginSet(final ProcessingEnvironment processingEnv) {
+ final PluginSet pluginSet = new PluginSet();
+ final String groupId = requireOption(processingEnv, GROUP_ID_OPTION_KEY);
+ final String artifactId = requireOption(processingEnv, ARTIFACT_ID_OPTION_KEY);
+ @Nullable final String version = getOption(processingEnv, VERSION_OPTION_KEY);
+ @Nullable final String description = getOption(processingEnv, DESCRIPTION_OPTION_KEY);
+ pluginSet.setGroupId(groupId);
+ pluginSet.setArtifactId(artifactId);
+ pluginSet.setVersion(version);
+ if (description != null) {
+ final Description descriptionModel = new Description();
+ descriptionModel.setText(description);
+ pluginSet.setDescription(descriptionModel);
}
- return Path.of(descriptorFilePath);
+ return pluginSet;
+ }
+
+ private static String requireOption(final ProcessingEnvironment processingEnv, final String key) {
+ @Nullable final String value = getOption(processingEnv, key);
+ if (value == null) {
+ final String message = String.format("missing option: `%s`", key);
+ throw new IllegalArgumentException(message);
+ }
+ return value;
+ }
+
+ @Nullable
+ private static String getOption(final ProcessingEnvironment processingEnv, final String key) {
+ @Nullable final String value = processingEnv.getOptions().get(key);
+ return StringUtils.isBlank(value) ? null : value.trim();
}
private static DeclaredType getDeclaredType(final ProcessingEnvironment processingEnv, final String className) {
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
index 7791fc3..bd3aca4 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
@@ -100,7 +100,11 @@ public class DescriptorGeneratorTest {
"-proc:only",
"-processor",
DescriptorGenerator.class.getName(),
- "-A" + DescriptorGenerator.DESCRIPTOR_FILE_PATH_PROPERTY_NAME + "=" + descriptorFilePath),
+ "-A" + DescriptorGenerator.DESCRIPTOR_FILE_PATH_OPTION_KEY + "=" + descriptorFilePath,
+ "-A" + DescriptorGenerator.GROUP_ID_OPTION_KEY + "=com.example.groupId",
+ "-A" + DescriptorGenerator.ARTIFACT_ID_OPTION_KEY + "=example-artifactId",
+ "-A" + DescriptorGenerator.VERSION_OPTION_KEY + "=1.2.3",
+ "-A" + DescriptorGenerator.DESCRIPTION_OPTION_KEY + "=example description"),
null,
sources);
task.call();
diff --git a/log4j-docgen/src/test/resources/generated-plugins.xml b/log4j-docgen/src/test/resources/generated-plugins.xml
index c0e8d08..0a37586 100644
--- a/log4j-docgen/src/test/resources/generated-plugins.xml
+++ b/log4j-docgen/src/test/resources/generated-plugins.xml
@@ -16,6 +16,10 @@
~ limitations under the License.
-->
<pluginSet xmlns="https://logging.apache.org/xml/ns/plugins" version="0.1.0">
+ <groupId>com.example.groupId</groupId>
+ <artifactId>example-artifactId</artifactId>
+ <version>1.2.3</version>
+ <description>example description</description>
<scalars>
<scalar className="example.MyEnum">
<values>
(logging-log4j-tools) 06/29: Rename occurrences of `[Aa]sciidoc` to `[Aa]sciiDoc`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 45b991f6bf811570fa99ca64d424880411d0f4a0
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 11:50:45 2024 +0100
Rename occurrences of `[Aa]sciidoc` to `[Aa]sciiDoc`
---
...sitor.java => AbstractAsciiDocTreeVisitor.java} | 22 +++++++++++-----------
...ciidocConverter.java => AsciiDocConverter.java} | 20 ++++++++++----------
.../{AsciidocData.java => AsciiDocData.java} | 8 ++++----
.../log4j/docgen/processor/DocGenProcessor.java | 12 ++++++------
...nverterTest.java => AsciiDocConverterTest.java} | 7 ++++---
5 files changed, 35 insertions(+), 34 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciidocTreeVisitor.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java
similarity index 95%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciidocTreeVisitor.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java
index cf78c22..0548451 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciidocTreeVisitor.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java
@@ -46,7 +46,7 @@ import org.asciidoctor.ast.Section;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.ast.Table;
-abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, AsciidocData> {
+abstract class AbstractAsciiDocTreeVisitor extends SimpleDocTreeVisitor<Void, AsciiDocData> {
private static final String JAVA_SOURCE_STYLE = "source,java";
private static final String XML_SOURCE_STYLE = "source,xml";
@@ -60,7 +60,7 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
private static final Pattern XML_TAG = Pattern.compile("<\\w+\\s*(\\w+=[\"'][^\"']*[\"']\\s*)*/?>");
@Override
- public Void visitStartElement(final StartElementTree node, final AsciidocData data) {
+ public Void visitStartElement(final StartElementTree node, final AsciiDocData data) {
final String elementName = node.getName().toString();
switch (elementName) {
case "p":
@@ -133,7 +133,7 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
}
@Override
- public Void visitEndElement(final EndElementTree node, final AsciidocData data) {
+ public Void visitEndElement(final EndElementTree node, final AsciiDocData data) {
final String elementName = node.getName().toString();
switch (elementName) {
case "p":
@@ -224,7 +224,7 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
}
@Override
- public Void visitLink(final LinkTree node, final AsciidocData data) {
+ public Void visitLink(final LinkTree node, final AsciiDocData data) {
final String className = substringBefore(node.getReference().getSignature(), '#');
final String simpleName = StringUtils.substringAfterLast(className, '.');
data.appendAdjustingSpace(" xref:")
@@ -236,7 +236,7 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
}
@Override
- public Void visitLiteral(final LiteralTree node, final AsciidocData data) {
+ public Void visitLiteral(final LiteralTree node, final AsciiDocData data) {
if (node.getKind() == DocTree.Kind.CODE) {
data.newTextSpan();
node.getBody().accept(this, data);
@@ -248,7 +248,7 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
}
@Override
- public Void visitEntity(final EntityTree node, final AsciidocData asciidocData) {
+ public Void visitEntity(final EntityTree node, final AsciiDocData asciiDocData) {
final String text;
switch (node.getName().toString()) {
case "amp":
@@ -270,13 +270,13 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
text = null;
}
if (text != null) {
- asciidocData.append(text);
+ asciiDocData.append(text);
}
- return super.visitEntity(node, asciidocData);
+ return super.visitEntity(node, asciiDocData);
}
@Override
- public Void visitText(final TextTree node, final AsciidocData data) {
+ public Void visitText(final TextTree node, final AsciiDocData data) {
final Block currentParagraph = data.getCurrentParagraph();
if (BlockImpl.PARAGRAPH_CONTEXT.equals(currentParagraph.getContext())) {
appendSentences(node.getBody(), data);
@@ -286,7 +286,7 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
return super.visitText(node, data);
}
- private static void appendSentences(final String text, final AsciidocData data) {
+ private static void appendSentences(final String text, final AsciiDocData data) {
final String[] sentences = text.split("(?<=\\w{2}[.!?])", -1);
// Full sentences
for (int i = 0; i < sentences.length - 1; i++) {
@@ -296,7 +296,7 @@ abstract class AbstractAsciidocTreeVisitor extends SimpleDocTreeVisitor<Void, As
data.appendAdjustingSpace(sentences[sentences.length - 1]);
}
- private void appendSpan(final AsciidocData data, final String delimiter) {
+ private void appendSpan(final AsciiDocData data, final String delimiter) {
final String body = data.popTextSpan();
data.append(delimiter);
final boolean needsEscaping = body.contains(delimiter);
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocConverter.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverter.java
similarity index 87%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocConverter.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverter.java
index 1266ec6..504728c 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocConverter.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverter.java
@@ -26,13 +26,13 @@ import javax.lang.model.element.Element;
/**
* Converts a {@link DocCommentTree} into AsciiDoc text.
*/
-final class AsciidocConverter {
+final class AsciiDocConverter {
private final DocTrees docTrees;
- private final DocTreeVisitor<Void, AsciidocData> docCommentTreeVisitor;
- private final DocTreeVisitor<Void, AsciidocData> paramTreeVisitor;
+ private final DocTreeVisitor<Void, AsciiDocData> docCommentTreeVisitor;
+ private final DocTreeVisitor<Void, AsciiDocData> paramTreeVisitor;
- AsciidocConverter(final DocTrees docTrees) {
+ AsciiDocConverter(final DocTrees docTrees) {
this.docTrees = docTrees;
this.docCommentTreeVisitor = new DocCommentTreeVisitor();
this.paramTreeVisitor = new ParamTreeVisitor();
@@ -44,20 +44,20 @@ final class AsciidocConverter {
}
public String toAsciiDoc(final DocCommentTree tree) {
- final AsciidocData data = new AsciidocData();
+ final AsciiDocData data = new AsciiDocData();
tree.accept(docCommentTreeVisitor, data);
return data.getDocument().convert();
}
public String toAsciiDoc(final ParamTree tree) {
- final AsciidocData data = new AsciidocData();
+ final AsciiDocData data = new AsciiDocData();
tree.accept(paramTreeVisitor, data);
return data.getDocument().convert();
}
- private static final class DocCommentTreeVisitor extends AbstractAsciidocTreeVisitor {
+ private static final class DocCommentTreeVisitor extends AbstractAsciiDocTreeVisitor {
@Override
- public Void visitDocComment(final DocCommentTree node, final AsciidocData data) {
+ public Void visitDocComment(final DocCommentTree node, final AsciiDocData data) {
// Summary block wrapped in a new paragraph.
for (final DocTree docTree : node.getFirstSentence()) {
docTree.accept(this, data);
@@ -73,9 +73,9 @@ final class AsciidocConverter {
}
}
- private static final class ParamTreeVisitor extends AbstractAsciidocTreeVisitor {
+ private static final class ParamTreeVisitor extends AbstractAsciiDocTreeVisitor {
@Override
- public Void visitParam(final ParamTree node, final AsciidocData data) {
+ public Void visitParam(final ParamTree node, final AsciiDocData data) {
for (final DocTree docTree : node.getDescription()) {
docTree.accept(this, data);
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocData.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciiDocData.java
similarity index 97%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocData.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciiDocData.java
index 90f5531..e7d2adb 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocData.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciiDocData.java
@@ -31,7 +31,7 @@ import org.asciidoctor.ast.Block;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.StructuralNode;
-final class AsciidocData {
+final class AsciiDocData {
private static final Pattern WHITESPACE_SEQUENCE = Pattern.compile("\\s+");
private static final String SPACE = " ";
private static final char SPACE_CHAR = ' ';
@@ -44,7 +44,7 @@ final class AsciidocData {
private final Deque<Block> paragraphs = new ArrayDeque<>();
private final Deque<StringBuilder> lines = new ArrayDeque<>();
- public AsciidocData() {
+ public AsciiDocData() {
document = new DocumentImpl();
currentSectionLevel = 1;
currentNode = document;
@@ -62,7 +62,7 @@ final class AsciidocData {
getCurrentLine().setLength(0);
}
- public AsciidocData append(final String text) {
+ public AsciiDocData append(final String text) {
final String[] lines = text.split("\r?\n", -1);
for (int i = 0; i < lines.length; i++) {
getCurrentLine().append(lines[i]);
@@ -73,7 +73,7 @@ final class AsciidocData {
return this;
}
- public AsciidocData appendAdjustingSpace(final CharSequence text) {
+ public AsciiDocData appendAdjustingSpace(final CharSequence text) {
final String normalized = WHITESPACE_SEQUENCE.matcher(text).replaceAll(SPACE);
if (!normalized.isEmpty()) {
final StringBuilder currentLine = getCurrentLine();
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
index 42f9a0b..57eb55c 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DocGenProcessor.java
@@ -109,7 +109,7 @@ public class DocGenProcessor extends AbstractProcessor {
// Scalar types to process
private final Collection<TypeElement> scalarTypesToDocument = new HashSet<>();
- private AsciidocConverter converter;
+ private AsciiDocConverter converter;
private DocTrees docTrees;
private Elements elements;
private Types types;
@@ -148,7 +148,7 @@ public class DocGenProcessor extends AbstractProcessor {
messager = processingEnv.getMessager();
types = processingEnv.getTypeUtils();
- converter = new AsciidocConverter(docTrees);
+ converter = new AsciiDocConverter(docTrees);
annotations = new Annotations(elements, types);
collectionType = (DeclaredType)
@@ -315,8 +315,8 @@ public class DocGenProcessor extends AbstractProcessor {
// Gather documentation, which can be on any member.
for (final Element member : members) {
final String name = getAttributeOrPropertyName(member);
- final String asciidoc = converter.toAsciiDoc(member);
- descriptions.compute(name, (key, value) -> Stream.of(value, asciidoc)
+ final String asciiDoc = converter.toAsciiDoc(member);
+ descriptions.compute(name, (key, value) -> Stream.of(value, asciiDoc)
.filter(StringUtils::isNotEmpty)
.collect(Collectors.joining("\n")));
}
@@ -340,9 +340,9 @@ public class DocGenProcessor extends AbstractProcessor {
pluginElements.forEach(pluginType::addElement);
}
- private Description createDescription(final String asciidoc) {
+ private Description createDescription(final String asciiDoc) {
final Description description = new Description();
- description.setText(StringUtils.stripToEmpty(asciidoc));
+ description.setText(StringUtils.stripToEmpty(asciiDoc));
return description;
}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
similarity index 95%
rename from log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
rename to log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
index 0fe77b4..05b9267 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
@@ -49,7 +49,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
-public class AsciidocConverterTest {
+public class AsciiDocConverterTest {
private static final Path LICENSE_PATH = Paths.get("src/test/resources/templates/license.ftl");
@@ -58,7 +58,8 @@ public class AsciidocConverterTest {
private static final Charset CHARSET = UTF_8;
@Test
- void convertToAsciidoc(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir) throws Exception {
+ void Javadoc_to_AsciiDoc_conversion_should_work(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir)
+ throws Exception {
// Instantiate the tooling
final DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
@@ -113,7 +114,7 @@ public class AsciidocConverterTest {
@Override
public boolean run(final DocletEnvironment environment) {
- final AsciidocConverter converter = new AsciidocConverter(environment.getDocTrees());
+ final AsciiDocConverter converter = new AsciiDocConverter(environment.getDocTrees());
final JavaFileManager fileManager = environment.getJavaFileManager();
try {
for (final Element element : environment.getIncludedElements()) {
(logging-log4j-tools) 03/29: Move test resource loading to `TestUtils`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit ecab88c94d45a3faf9315561bb323581c5b556d3
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 10:15:04 2024 +0100
Move test resource loading to `TestUtils`
---
.../org/apache/logging/log4j/docgen/TestUtils.java | 58 ++++++++++++++++++++++
.../docgen/internal/FreeMarkerGeneratorTest.java | 13 +++--
.../log4j/docgen/internal/SchemaGeneratorTest.java | 11 ++--
.../docgen/processor/AsciidocConverterTest.java | 22 ++------
.../docgen/processor/DocGenProcessorTest.java | 8 +--
5 files changed, 78 insertions(+), 34 deletions(-)
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/TestUtils.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/TestUtils.java
new file mode 100644
index 0000000..3bd9def
--- /dev/null
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/TestUtils.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public final class TestUtils {
+
+ private TestUtils() {}
+
+ public static Path resourcePath(final String name) {
+ final URI uri = resourceUri(name);
+ return Paths.get(uri);
+ }
+
+ public static URI resourceUri(final String name) {
+ final URL url = resourceUrl(name);
+ try {
+ return url.toURI();
+ } catch (URISyntaxException error) {
+ final String message = String.format("failed to obtain URI from URL `%s`", url);
+ throw new RuntimeException(message, error);
+ }
+ }
+
+ public static InputStream resourceStream(final String name) throws IOException {
+ final URL url = resourceUrl(name);
+ return url.openStream();
+ }
+
+ public static URL resourceUrl(final String name) {
+ final URL url = TestUtils.class.getResource(name);
+ assertThat(url).as("URL for resource `%s`", name).isNotNull();
+ return url;
+ }
+}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
index 8910ff3..7b36bca 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.logging.log4j.docgen.internal;
+import static org.apache.logging.log4j.docgen.TestUtils.resourcePath;
+import static org.apache.logging.log4j.docgen.TestUtils.resourceStream;
import static org.assertj.core.api.Assertions.assertThat;
import java.nio.charset.StandardCharsets;
@@ -24,6 +26,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.TestUtils;
import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGenerator;
import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGeneratorRequest;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
@@ -34,13 +37,9 @@ public class FreeMarkerGeneratorTest {
@Test
void generatePluginDocumentation() throws Exception {
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- final PluginSet set =
- reader.read(FreeMarkerGeneratorTest.class.getResourceAsStream("/META-INF/log4j/plugins-sample.xml"));
- final Path templateDir = Paths.get(
- FreeMarkerGeneratorTest.class.getResource("/templates").toURI());
- final Path expectedDirectory = Paths.get(FreeMarkerGeneratorTest.class
- .getResource("/expected/freemarker")
- .toURI());
+ final PluginSet set = reader.read(resourceStream("/META-INF/log4j/plugins-sample.xml"));
+ final Path templateDir = TestUtils.resourcePath("/templates");
+ final Path expectedDirectory = resourcePath("/expected/freemarker");
final Path outputDirectory = Paths.get("target/test-site/freemarker");
final FreeMarkerGenerator generator = new DefaultFreeMarkerGenerator();
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
index 3fbbcb8..70c0c1a 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.logging.log4j.docgen.internal;
+import static org.apache.logging.log4j.docgen.TestUtils.resourceStream;
+import static org.apache.logging.log4j.docgen.TestUtils.resourceUrl;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import java.io.IOException;
@@ -36,11 +38,11 @@ import org.xmlunit.builder.Input;
public class SchemaGeneratorTest {
@Test
- void schemaGeneration() throws Exception {
+ void schemaGeneration() {
final Source xmlSchema =
Input.fromURI("https://www.w3.org/2001/XMLSchema.xsd").build();
- final URL expectedSchema = SchemaGenerator.class.getResource("/expected/xsd/log4j-config.xsd");
- final Path actualSchema = assertDoesNotThrow(() -> generateSchema());
+ final URL expectedSchema = resourceUrl("/expected/xsd/log4j-config.xsd");
+ final Path actualSchema = assertDoesNotThrow(SchemaGeneratorTest::generateSchema);
XmlAssert.assertThat(actualSchema)
.isValidAgainst(xmlSchema)
.and(expectedSchema)
@@ -51,8 +53,7 @@ public class SchemaGeneratorTest {
private static Path generateSchema() throws XMLStreamException, IOException {
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- final PluginSet set =
- reader.read(SchemaGeneratorTest.class.getResourceAsStream("/META-INF/log4j/plugins-sample.xml"));
+ final PluginSet set = reader.read(resourceStream("/META-INF/log4j/plugins-sample.xml"));
final SchemaGenerator generator = new DefaultSchemaGenerator();
final SchemaGeneratorRequest request = new SchemaGeneratorRequest();
final Path outputDirectory = Paths.get("target/test-site/xsd");
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
index 5dc1888..d4191a9 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
@@ -17,11 +17,11 @@
package org.apache.logging.log4j.docgen.processor;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.logging.log4j.docgen.TestUtils.resourcePath;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.OutputStream;
-import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -48,17 +48,7 @@ import org.junit.jupiter.api.Test;
public class AsciidocConverterTest {
- private static final Path LICENSE_PATH;
-
- static {
- try {
- LICENSE_PATH = Paths.get(AsciidocConverterTest.class
- .getResource("/templates/license.ftl")
- .toURI());
- } catch (final URISyntaxException e) {
- throw new RuntimeException(e);
- }
- }
+ private static final Path LICENSE_PATH = resourcePath("/templates/license.ftl");
@Test
void convertToAsciidoc() throws Exception {
@@ -67,9 +57,7 @@ public class AsciidocConverterTest {
final StandardJavaFileManager fileManager = tool.getStandardFileManager(null, Locale.ROOT, UTF_8);
final Path basePath = Paths.get(System.getProperty("basedir", "."));
- final Path sourcePath = Paths.get(AsciidocConverterTest.class
- .getResource("/processor/asciidoc/example/JavadocExample.java")
- .toURI());
+ final Path sourcePath = resourcePath("/processor/asciidoc/example/JavadocExample.java");
final Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjects(sourcePath);
final Path destPath = basePath.resolve("target/test-site");
@@ -84,9 +72,7 @@ public class AsciidocConverterTest {
.map(d -> d.getMessage(Locale.ROOT))
.collect(Collectors.toList());
assertThat(warnings).isEmpty();
- final Path expectedPath = Paths.get(AsciidocConverterTest.class
- .getResource("/expected/processor/JavadocExample.adoc")
- .toURI());
+ final Path expectedPath = resourcePath("/expected/processor/JavadocExample.adoc");
assertThat(destPath.resolve("processor/JavadocExample.adoc")).hasSameTextualContentAs(expectedPath, UTF_8);
}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
index 98bde56..5b1db38 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DocGenProcessorTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.logging.log4j.docgen.processor;
+import static org.apache.logging.log4j.docgen.TestUtils.resourcePath;
+import static org.apache.logging.log4j.docgen.TestUtils.resourceUrl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -38,7 +40,6 @@ import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
import javax.tools.ToolProvider;
-import org.apache.logging.log4j.docgen.xsd.SchemaGenerator;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.xmlunit.assertj3.XmlAssert;
@@ -54,7 +55,7 @@ public class DocGenProcessorTest {
void descriptorGenerationSucceeds(final String version) {
final Path basePath = Paths.get(System.getProperty("basedir", "."));
final Path schema = basePath.resolve("target/generated-site/resources/xsd/plugins-0.1.0.xsd");
- final URL expected = SchemaGenerator.class.getResource("/expected/processor/META-INF/log4j/plugins.xml");
+ final URL expected = resourceUrl("/expected/processor/META-INF/log4j/plugins.xml");
final Path actual = assertDoesNotThrow(() -> generateDescriptor(version));
XmlAssert.assertThat(actual)
.isValidAgainst(schema)
@@ -71,8 +72,7 @@ public class DocGenProcessorTest {
compiler.getStandardFileManager(null, Locale.ROOT, StandardCharsets.UTF_8);
final Path basePath = Paths.get(System.getProperty("basedir", "."));
- final Path sourcePath = Paths.get(
- DocGenProcessorTest.class.getResource("/processor/" + version).toURI());
+ final Path sourcePath = resourcePath("/processor/" + version);
final Iterable<? extends JavaFileObject> sources;
try (final Stream<Path> files = Files.walk(sourcePath)) {
sources = fileManager.getJavaFileObjects(
(logging-log4j-tools) 20/29: Improve `scalars.adoc.ftl`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 424b431317e474cd7b3eb4c6150f461d1c033b68
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Fri Feb 16 10:39:02 2024 +0100
Improve `scalars.adoc.ftl`
---
.../plugins-to-freemarker-output/scalars.adoc | 30 +++++++++++-----------
.../src/test/resources/templates/scalars.adoc.ftl | 2 +-
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
index 8393e5c..3562590 100644
--- a/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
+++ b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
@@ -30,8 +30,8 @@ a|A boolean value.
Possible values:
-* `false`: false
-* `true`: true
+`false`:: false
+`true`:: true
|[[byte]]
byte
a|An 8-bit signed integer from `-128` to `127`
@@ -57,32 +57,32 @@ NOTE: The Log4j API supports custom levels, the following list contains only the
Possible values:
-* `OFF`: Special level that disables logging.
+`OFF`:: Special level that disables logging.
No events should be logged at this level.
-* `FATAL`: A fatal event that will prevent the application from continuing
-* `ERROR`: An error in the application, possibly recoverable
-* `WARN`: An event that might possible lead to an error
-* `INFO`: An event for informational purposes
-* `DEBUG`: A general debugging event
-* `TRACE`: A fine-grained debug message, typically capturing the flow through the application
-* `ALL`: Special level indicating all events should be logged
+`FATAL`:: A fatal event that will prevent the application from continuing
+`ERROR`:: An error in the application, possibly recoverable
+`WARN`:: An event that might possible lead to an error
+`INFO`:: An event for informational purposes
+`DEBUG`:: A general debugging event
+`TRACE`:: A fine-grained debug message, typically capturing the flow through the application
+`ALL`:: Special level indicating all events should be logged
|[[org.apache.logging.log4j.core.Filter.Result]]
o.a.l.l.core.Filter.Result
a|The result that can returned from a filter method call.
Possible values:
-* `ACCEPT`: The event will be processed without further filtering based on the log Level.
-* `NEUTRAL`: No decision could be made, further filtering should occur.
-* `DENY`: The event should not be processed.
+`ACCEPT`:: The event will be processed without further filtering based on the log Level.
+`NEUTRAL`:: No decision could be made, further filtering should occur.
+`DENY`:: The event should not be processed.
|[[org.apache.logging.log4j.core.appender.ConsoleAppender.Target]]
o.a.l.l.core.appender.ConsoleAppender.Target
a|Specifies the target of a console appender.
Possible values:
-* `SYSTEM_OUT`: Logs to the standard output.
-* `SYSTEM_ERR`: Logs to the standard error.
+`SYSTEM_OUT`:: Logs to the standard output.
+`SYSTEM_ERR`:: Logs to the standard error.
|[[short]]
short
a|A 16-bit signed integer from `-32768` to `32767`
diff --git a/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
index 42ca665..6e646c6 100644
--- a/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
+++ b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
@@ -36,7 +36,7 @@ a|${scalar.description.text}
Possible values:
<#list scalar.values as value>
-* `${value.name}`: ${value.description.text}
+`${value.name}`:: ${value.description.text}
</#list>
</#if>
</#list>
(logging-log4j-tools) 13/29: Relocate `log4j-changelog-maven-plugin` to an individual package
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 9c9f552c6ffaa7c228cca8933fda0e520d85a749
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 14 11:11:52 2024 +0100
Relocate `log4j-changelog-maven-plugin` to an individual package
---
.../java/org/apache/logging/log4j/{ => changelog/maven}/ExportMojo.java | 2 +-
.../java/org/apache/logging/log4j/{ => changelog/maven}/ImportMojo.java | 2 +-
.../org/apache/logging/log4j/{ => changelog/maven}/ReleaseMojo.java | 2 +-
.../org/apache/logging/log4j/{ => changelog/maven}/TemplateMojo.java | 2 +-
.../org/apache/logging/log4j/{ => changelog/maven}/package-info.java | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ExportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java
similarity index 98%
rename from log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ExportMojo.java
rename to log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java
index 0f0df71..6fb5438 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ExportMojo.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j;
+package org.apache.logging.log4j.changelog.maven;
import java.io.File;
import java.util.Collection;
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ImportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java
similarity index 98%
rename from log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ImportMojo.java
rename to log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java
index 0f3a22a..21b4ef4 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ImportMojo.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j;
+package org.apache.logging.log4j.changelog.maven;
import java.io.File;
import org.apache.logging.log4j.changelog.importer.MavenChangesImporter;
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ReleaseMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java
similarity index 98%
rename from log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ReleaseMojo.java
rename to log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java
index 91953ff..2028575 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/ReleaseMojo.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j;
+package org.apache.logging.log4j.changelog.maven;
import java.io.File;
import java.time.LocalDate;
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/TemplateMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/TemplateMojo.java
similarity index 97%
rename from log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/TemplateMojo.java
rename to log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/TemplateMojo.java
index 70a288c..f55faf4 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/TemplateMojo.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/TemplateMojo.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j;
+package org.apache.logging.log4j.changelog.maven;
import org.apache.maven.plugins.annotations.Parameter;
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/package-info.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/package-info.java
similarity index 94%
rename from log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/package-info.java
rename to log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/package-info.java
index 4cc8d48..5792019 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/package-info.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/package-info.java
@@ -15,6 +15,6 @@
* limitations under the License.
*/
@Version("0.5.0")
-package org.apache.logging.log4j;
+package org.apache.logging.log4j.changelog.maven;
import org.osgi.annotation.versioning.Version;
(logging-log4j-tools) 10/29: Close `OutputStream` in `DefaultSchemaGenerator`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit c2b0d29125274675b1e7b9ab1c2652b2f4e95634
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 14 09:52:16 2024 +0100
Close `OutputStream` in `DefaultSchemaGenerator`
---
.../docgen/internal/DefaultSchemaGenerator.java | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultSchemaGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultSchemaGenerator.java
index 4144b8a..8e23275 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultSchemaGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultSchemaGenerator.java
@@ -17,6 +17,7 @@
package org.apache.logging.log4j.docgen.internal;
import java.io.IOException;
+import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -51,7 +52,7 @@ public class DefaultSchemaGenerator implements SchemaGenerator {
private static final String LOG4J_NAMESPACE = "http://logging.apache.org/xml/ns/config";
private static final String XSD_NAMESPACE = XMLConstants.W3C_XML_SCHEMA_NS_URI;
private static final String MULTIPLICITY_UNBOUNDED = "*";
- private static final String UTF_8 = "UTF-8";
+ private static final String ENCODING = "UTF-8";
@Override
public void generateSchema(final SchemaGeneratorRequest request) throws XMLStreamException {
@@ -63,19 +64,21 @@ public class DefaultSchemaGenerator implements SchemaGenerator {
final TypeLookup lookup = TypeLookup.of(extendedSets);
final XMLOutputFactory factory = XMLOutputFactory.newFactory();
final Path schemaPath = request.getOutputDirectory().resolve(request.getFileName());
- final XMLStreamWriter writer = factory.createXMLStreamWriter(Files.newOutputStream(schemaPath), UTF_8);
- try {
- writeSchema(lookup, writer);
- } finally {
- writer.close();
+ try (final OutputStream schemaPathOutputStream = Files.newOutputStream(schemaPath)) {
+ final XMLStreamWriter writer = factory.createXMLStreamWriter(schemaPathOutputStream, ENCODING);
+ try {
+ writeSchema(lookup, writer);
+ } finally {
+ writer.close();
+ }
}
- } catch (IOException e) {
- throw new XMLStreamException(e);
+ } catch (final IOException error) {
+ throw new XMLStreamException(error);
}
}
private static void writeSchema(final TypeLookup lookup, final XMLStreamWriter writer) throws XMLStreamException {
- writer.writeStartDocument(UTF_8, "1.0");
+ writer.writeStartDocument(ENCODING, "1.0");
writer.setDefaultNamespace(XSD_NAMESPACE);
writer.writeStartElement(XSD_NAMESPACE, "schema");
writer.writeDefaultNamespace(XSD_NAMESPACE);
(logging-log4j-tools) 28/29: Fix `PathMatcherMojo#pathPatterns` javadoc
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 6c61b31581daba1c4b054401c14262b1d87b2221
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 21 15:17:03 2024 +0100
Fix `PathMatcherMojo#pathPatterns` javadoc
---
.../java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java
index 9f5cfa7..0ed18d6 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java
@@ -50,7 +50,7 @@ public final class PathMatcherMojo {
private boolean dotFilesExcluded;
/**
- * The path patterns (e.g., {@code glob:*.xml}) that will be used to filter paths found in {@link #baseDirectory}.
+ * The path patterns (e.g., <code>glob:**/*.xml</code>) that will be used to filter paths found in {@link #baseDirectory}.
* @see FileSystem#getPathMatcher(String)
*/
@Nullable
(logging-log4j-tools) 25/29: Improve empty description handling
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit e8b009ec6522df1444e414d8e97cda3c81a6fd9c
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 20 14:28:47 2024 +0100
Improve empty description handling
---
.../log4j/docgen/generator/SchemaGenerator.java | 20 ++++++++---------
.../docgen/processor/DescriptorGenerator.java | 25 ++++++++++++++--------
.../src/test/resources/generated-plugins.xml | 2 ++
.../plugins-using-log4j2/example/MyAppender.java | 2 ++
.../plugins-using-log4j2/example/MyEnum.java | 3 ++-
.../plugins-using-log4j3/example/MyAppender.java | 2 ++
.../plugins-using-log4j3/example/MyEnum.java | 3 ++-
7 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
index ab13a87..b7bf166 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
@@ -42,6 +42,7 @@ import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.ScalarType;
import org.apache.logging.log4j.docgen.ScalarValue;
import org.apache.logging.log4j.docgen.Type;
+import org.jspecify.annotations.Nullable;
@Singleton
@Named("default")
@@ -189,10 +190,7 @@ public final class SchemaGenerator {
throws XMLStreamException {
writer.writeStartElement(XSD_NAMESPACE, "group");
writer.writeAttribute("name", abstractType.getClassName());
- final Description description = abstractType.getDescription();
- if (description != null) {
- writeDocumentation(description, writer);
- }
+ writeDocumentation(abstractType.getDescription(), writer);
writer.writeStartElement(XSD_NAMESPACE, "choice");
final Set<String> implementations = abstractType.getImplementations();
@@ -212,13 +210,15 @@ public final class SchemaGenerator {
writer.writeEndElement();
}
- private static void writeDocumentation(final Description description, final XMLStreamWriter writer)
+ private static void writeDocumentation(@Nullable final Description description, final XMLStreamWriter writer)
throws XMLStreamException {
- writer.writeStartElement(XSD_NAMESPACE, "annotation");
- writer.writeStartElement(XSD_NAMESPACE, "documentation");
- writer.writeCharacters(description.getText());
- writer.writeEndElement();
- writer.writeEndElement();
+ if (description != null) {
+ writer.writeStartElement(XSD_NAMESPACE, "annotation");
+ writer.writeStartElement(XSD_NAMESPACE, "documentation");
+ writer.writeCharacters(description.getText());
+ writer.writeEndElement();
+ writer.writeEndElement();
+ }
}
private static void writeScalarValue(final ScalarValue value, final XMLStreamWriter writer)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
index 56d1018..d3f0a6e 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
@@ -16,7 +16,6 @@
*/
package org.apache.logging.log4j.docgen.processor;
-import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
import static org.apache.commons.lang3.StringUtils.defaultString;
import aQute.bnd.annotation.Resolution;
@@ -162,7 +161,8 @@ public class DescriptorGenerator extends AbstractProcessor {
private static DeclaredType getDeclaredType(final ProcessingEnvironment processingEnv, final String className) {
final Types typeUtils = processingEnv.getTypeUtils();
final Elements elementUtils = processingEnv.getElementUtils();
- return (DeclaredType) typeUtils.erasure(elementUtils.getTypeElement(className).asType());
+ return (DeclaredType)
+ typeUtils.erasure(elementUtils.getTypeElement(className).asType());
}
@Override
@@ -209,7 +209,8 @@ public class DescriptorGenerator extends AbstractProcessor {
try {
final AbstractType abstractType = new AbstractType();
populateAbstractType(element, abstractType);
- if (!abstractType.getDescription().getText().isEmpty()) {
+ @Nullable final Description description = abstractType.getDescription();
+ if (description != null) {
pluginSet.addAbstractType(abstractType);
}
} catch (final Exception error) {
@@ -359,16 +360,22 @@ public class DescriptorGenerator extends AbstractProcessor {
pluginElements.forEach(pluginType::addElement);
}
- private Description createDescription(final String asciiDoc) {
+ @Nullable
+ private Description createDescription(final Element element, final @Nullable String fallbackDescriptionText) {
+ @Nullable String descriptionText = converter.toAsciiDoc(element);
+ if (StringUtils.isBlank(descriptionText)) {
+ if (StringUtils.isBlank(fallbackDescriptionText)) {
+ return null;
+ } else {
+ descriptionText = fallbackDescriptionText;
+ }
+ }
+ descriptionText = descriptionText.trim();
final Description description = new Description();
- description.setText(StringUtils.stripToEmpty(asciiDoc));
+ description.setText(descriptionText);
return description;
}
- private Description createDescription(final Element element, final @Nullable String fallback) {
- return createDescription(defaultIfEmpty(converter.toAsciiDoc(element), defaultString(fallback)));
- }
-
private PluginAttribute createPluginAttribute(
final Element element, final String description, final String specifiedName) {
final PluginAttribute attribute = new PluginAttribute();
diff --git a/log4j-docgen/src/test/resources/generated-plugins.xml b/log4j-docgen/src/test/resources/generated-plugins.xml
index 274d743..c0e8d08 100644
--- a/log4j-docgen/src/test/resources/generated-plugins.xml
+++ b/log4j-docgen/src/test/resources/generated-plugins.xml
@@ -31,6 +31,7 @@
<value name="D">
<description>Value D.</description>
</value>
+ <value name="WITHOUT_DESCRIPTION"/>
</values>
<description>A very important enum.</description>
</scalar>
@@ -77,6 +78,7 @@
<attribute name="stringAtt" required="true">
<description>A `String` attribute.</description>
</attribute>
+ <attribute name="undocumentedAttribute" type="double"/>
</attributes>
<elements>
<element type="example.AbstractAppender">
diff --git a/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyAppender.java
index f99d07f..acc4ccc 100644
--- a/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyAppender.java
+++ b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyAppender.java
@@ -111,6 +111,8 @@ public final class MyAppender extends AbstractAppender implements Appender {
*/
private @PluginBuilderAttribute double aDouble;
+ private @PluginBuilderAttribute double undocumentedAttribute;
+
private Object notAnAttribute;
/**
diff --git a/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyEnum.java b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyEnum.java
index 4d7afa8..08f7e75 100644
--- a/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyEnum.java
+++ b/log4j-docgen/src/test/resources/plugins-using-log4j2/example/MyEnum.java
@@ -35,5 +35,6 @@ public enum MyEnum {
/**
* Value D.
*/
- D;
+ D,
+ WITHOUT_DESCRIPTION;
}
diff --git a/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyAppender.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyAppender.java
index e6a36c2..70c45d1 100644
--- a/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyAppender.java
+++ b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyAppender.java
@@ -113,6 +113,8 @@ public final class MyAppender extends AbstractAppender implements Appender {
*/
private @PluginBuilderAttribute double aDouble;
+ private @PluginBuilderAttribute double undocumentedAttribute;
+
private Object notAnAttribute;
/**
diff --git a/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyEnum.java b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyEnum.java
index 4d7afa8..08f7e75 100644
--- a/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyEnum.java
+++ b/log4j-docgen/src/test/resources/plugins-using-log4j3/example/MyEnum.java
@@ -35,5 +35,6 @@ public enum MyEnum {
/**
* Value D.
*/
- D;
+ D,
+ WITHOUT_DESCRIPTION;
}
(logging-log4j-tools) 19/29: Rename template files
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 52399469ebf78cd1e16190b9572507de9eb50ec2
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Thu Feb 15 15:48:25 2024 +0100
Rename template files
---
.../log4j/docgen/generator/DocumentationFiles.java | 26 ++++++++++++++++++++++
.../generator/DocumentationGeneratorArgs.java | 17 +++++++++++---
.../generator/DocumentationGeneratorTest.java | 7 +++++-
.../docgen/processor/AsciiDocConverterTest.java | 2 +-
.../{interface.ftl => interface.adoc.ftl} | 2 +-
.../templates/{license.ftl => license.adoc.ftl} | 0
.../templates/{plugin.ftl => plugin.adoc.ftl} | 2 +-
.../templates/{scalars.ftl => scalars.adoc.ftl} | 2 +-
8 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
new file mode 100644
index 0000000..43de35f
--- /dev/null
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.generator;
+
+final class DocumentationFiles {
+
+ private DocumentationFiles() {}
+
+ public static String templateFileNameExtension() {
+ return "ftl";
+ }
+}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
index 789e317..b013797 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
@@ -21,6 +21,7 @@ import static java.util.Objects.requireNonNull;
import java.nio.file.Path;
import java.util.Set;
import org.apache.logging.log4j.docgen.PluginSet;
+import org.jspecify.annotations.Nullable;
public final class DocumentationGeneratorArgs {
@@ -45,9 +46,19 @@ public final class DocumentationGeneratorArgs {
final Path outputDirectory) {
this.pluginSets = requireNonNull(pluginSets, "pluginSets");
this.templateDirectory = requireNonNull(templateDirectory, "templateDirectory");
- this.scalarsTemplateName = requireNonNull(scalarsTemplateName, "scalarsTemplateName");
- this.pluginTemplateName = requireNonNull(pluginTemplateName, "pluginTemplateName");
- this.interfaceTemplateName = requireNonNull(interfaceTemplateName, "interfaceTemplateName");
+ this.scalarsTemplateName = requireValidTemplateName(scalarsTemplateName, "scalarsTemplateName");
+ this.pluginTemplateName = requireValidTemplateName(pluginTemplateName, "pluginTemplateName");
+ this.interfaceTemplateName = requireValidTemplateName(interfaceTemplateName, "interfaceTemplateName");
this.outputDirectory = requireNonNull(outputDirectory, "outputDirectory");
}
+
+ private static String requireValidTemplateName(@Nullable final String value, final String name) {
+ final String extension = '.' + DocumentationFiles.templateFileNameExtension();
+ if (value == null || !value.endsWith(extension)) {
+ final String message =
+ String.format("was expecting `%s` to end with a `%s` suffix: `%s`", name, extension, value);
+ throw new IllegalArgumentException(message);
+ }
+ return value;
+ }
}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
index 7701c4f..22de8ee 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
@@ -39,7 +39,12 @@ public class DocumentationGeneratorTest {
// Generate the documentation
final Path templateDirectory = Paths.get("src/test/resources/templates");
final DocumentationGeneratorArgs generatorArgs = new DocumentationGeneratorArgs(
- Set.of(pluginSet), templateDirectory, "scalars.ftl", "plugin.ftl", "interface.ftl", outputDir);
+ Set.of(pluginSet),
+ templateDirectory,
+ "scalars.adoc.ftl",
+ "plugin.adoc.ftl",
+ "interface.adoc.ftl",
+ outputDir);
DocumentationGenerator.generateDocumentation(generatorArgs);
// Verify the output
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
index 90be680..a1e9233 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
@@ -51,7 +51,7 @@ import org.junit.jupiter.api.io.TempDir;
public class AsciiDocConverterTest {
- private static final Path LICENSE_PATH = Paths.get("src/test/resources/templates/license.ftl");
+ private static final Path LICENSE_PATH = Paths.get("src/test/resources/templates/license.adoc.ftl");
private static final String TEST_CLASS_NAME = "JavadocExample";
diff --git a/log4j-docgen/src/test/resources/templates/interface.ftl b/log4j-docgen/src/test/resources/templates/interface.adoc.ftl
similarity index 97%
rename from log4j-docgen/src/test/resources/templates/interface.ftl
rename to log4j-docgen/src/test/resources/templates/interface.adoc.ftl
index b7fcb32..415107c 100644
--- a/log4j-docgen/src/test/resources/templates/interface.ftl
+++ b/log4j-docgen/src/test/resources/templates/interface.adoc.ftl
@@ -17,7 +17,7 @@
-->
<#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.model.AbstractType" -->
<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
-<#include "license.ftl">
+<#include "license.adoc.ftl">
= ${type.className?keep_after_last('.')}
<#if type.description??>
diff --git a/log4j-docgen/src/test/resources/templates/license.ftl b/log4j-docgen/src/test/resources/templates/license.adoc.ftl
similarity index 100%
rename from log4j-docgen/src/test/resources/templates/license.ftl
rename to log4j-docgen/src/test/resources/templates/license.adoc.ftl
diff --git a/log4j-docgen/src/test/resources/templates/plugin.ftl b/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
similarity index 99%
rename from log4j-docgen/src/test/resources/templates/plugin.ftl
rename to log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
index 245a075..ab4b72b 100644
--- a/log4j-docgen/src/test/resources/templates/plugin.ftl
+++ b/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
@@ -17,7 +17,7 @@
-->
<#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.PluginType" -->
<#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
-<#include "license.ftl">
+<#include "license.adoc.ftl">
= ${type.name}
${type.description.text}
diff --git a/log4j-docgen/src/test/resources/templates/scalars.ftl b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
similarity index 97%
rename from log4j-docgen/src/test/resources/templates/scalars.ftl
rename to log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
index 1c50f18..42ca665 100644
--- a/log4j-docgen/src/test/resources/templates/scalars.ftl
+++ b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<#-- @ftlvariable name="scalars" type="org.apache.logging.log4j.docgen.model.ScalarType[]" -->
-<#include "license.ftl">
+<#include "license.adoc.ftl">
= Type converters
Type converter plugins are used to convert simple `String` values into other types.
(logging-log4j-tools) 07/29: Improve test resource naming
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit b6016b3ae61efd8f4d1e86a2177b0152f3a11606
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 12:44:30 2024 +0100
Improve test resource naming
---
.../apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java | 4 ++--
.../example/JavadocExample.java | 0
.../JavadocExample.adoc | 0
3 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
index 05b9267..d70358c 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
@@ -67,7 +67,7 @@ public class AsciiDocConverterTest {
// Populate sources (aka. compilation units)
final Path sourcePath =
- Paths.get("src/test/resources/AsciiDocConverterTest-input/example/" + TEST_CLASS_NAME + ".java");
+ Paths.get("src/test/resources/javadoc-input/example/" + TEST_CLASS_NAME + ".java");
final Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjects(sourcePath);
// Set the target path used by `Javadoc2AsciiDocDoclet` to dump the generated files
@@ -85,7 +85,7 @@ public class AsciiDocConverterTest {
// Verify the generated AsciiDoc
final Path expectedPath =
- Paths.get("src/test/resources/AsciiDocConverterTest-reference-output/" + TEST_CLASS_NAME + ".adoc");
+ Paths.get("src/test/resources/javadoc-to-asciidoc-output/" + TEST_CLASS_NAME + ".adoc");
assertThat(outputDir.resolve(TEST_CLASS_NAME + ".adoc")).hasSameTextualContentAs(expectedPath, CHARSET);
}
diff --git a/log4j-docgen/src/test/resources/AsciiDocConverterTest-input/example/JavadocExample.java b/log4j-docgen/src/test/resources/javadoc-input/example/JavadocExample.java
similarity index 100%
rename from log4j-docgen/src/test/resources/AsciiDocConverterTest-input/example/JavadocExample.java
rename to log4j-docgen/src/test/resources/javadoc-input/example/JavadocExample.java
diff --git a/log4j-docgen/src/test/resources/AsciiDocConverterTest-reference-output/JavadocExample.adoc b/log4j-docgen/src/test/resources/javadoc-to-asciidoc-output/JavadocExample.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/AsciiDocConverterTest-reference-output/JavadocExample.adoc
rename to log4j-docgen/src/test/resources/javadoc-to-asciidoc-output/JavadocExample.adoc
(logging-log4j-tools) 17/29: Add `DocumentationGeneratorMojo`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 15321d77698536abc996e992a76be15422ad390f
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Thu Feb 15 12:57:54 2024 +0100
Add `DocumentationGeneratorMojo`
---
.../docgen/maven/DocumentationGeneratorMojo.java | 83 ++++++++++++++++++++++
.../logging/log4j/docgen/maven/PluginSets.java | 41 +++++++++++
.../log4j/docgen/maven/SchemaGeneratorMojo.java | 23 +-----
...rGenerator.java => DocumentationGenerator.java} | 4 +-
...orTest.java => DocumentationGeneratorTest.java} | 4 +-
5 files changed, 129 insertions(+), 26 deletions(-)
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
new file mode 100644
index 0000000..db7b406
--- /dev/null
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.maven;
+
+import java.io.File;
+import java.util.Set;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.internal.DocumentationGenerator;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Goal generating documentation by feeding the configuration collected from the provided plugin descriptors (e.g., {@code plugins.xml}) to the FreeMarker templates provided.
+ *
+ * @see DocumentationGenerator
+ */
+@Mojo(name = "generate-documentation", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
+public class DocumentationGeneratorMojo extends AbstractMojo {
+
+ /**
+ * The paths of the plugin descriptor XML files
+ */
+ @Parameter(property = "log4j.docgen.descriptorFiles", required = true)
+ private File[] descriptorFiles;
+
+ /**
+ * The path to the FreeMarker template directory
+ */
+ @Parameter(property = "log4j.docgen.templateDirectory", required = true)
+ private File templateDirectory;
+
+ /**
+ * The name of the FreeMarker template to document scalars (e.g., {@code scalars.adoc.ftl})
+ */
+ @Parameter(property = "log4j.docgen.scalarsTemplateName", required = true)
+ private String scalarsTemplateName;
+
+ /**
+ * The name of the FreeMarker template to document plugins (e.g., {@code plugin.adoc.ftl})
+ */
+ @Parameter(property = "log4j.docgen.pluginTemplateName", required = true)
+ private String pluginTemplateName;
+
+ /**
+ * The name of the FreeMarker template to document interfaces (e.g., {@code interface.adoc.ftl})
+ */
+ @Parameter(property = "log4j.docgen.interfaceTemplateName", required = true)
+ private String interfaceTemplateName;
+
+ /**
+ * The path to output the generated documentation
+ */
+ @Parameter(property = "log4j.docgen.outputDirectory", required = true)
+ private File outputDirectory;
+
+ @Override
+ public void execute() {
+ final Set<PluginSet> pluginSets = PluginSets.ofDescriptorFiles(descriptorFiles);
+ DocumentationGenerator.generateDocumentation(
+ pluginSets,
+ templateDirectory.toPath(),
+ scalarsTemplateName,
+ pluginTemplateName,
+ interfaceTemplateName,
+ outputDirectory.toPath());
+ }
+}
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java
new file mode 100644
index 0000000..42b8fc6
--- /dev/null
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.maven;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
+
+final class PluginSets {
+
+ static Set<PluginSet> ofDescriptorFiles(File[] descriptorFiles) {
+ final PluginBundleStaxReader reader = new PluginBundleStaxReader();
+ return Arrays.stream(descriptorFiles)
+ .map(descriptorFile -> {
+ try {
+ return reader.read(descriptorFile.toString());
+ } catch (final Exception error) {
+ final String message = String.format("failed reading descriptor file `%s`", descriptorFile);
+ throw new RuntimeException(message, error);
+ }
+ })
+ .collect(Collectors.toSet());
+ }
+}
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
index 825082e..3773bd9 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
@@ -17,13 +17,10 @@
package org.apache.logging.log4j.docgen.maven;
import java.io.File;
-import java.util.Arrays;
import java.util.Set;
-import java.util.stream.Collectors;
import javax.xml.stream.XMLStreamException;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.internal.SchemaGenerator;
-import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -52,25 +49,7 @@ public class SchemaGeneratorMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {
- final Set<PluginSet> pluginSet = readPluginSets();
- generateSchema(pluginSet);
- }
-
- private Set<PluginSet> readPluginSets() {
- final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- return Arrays.stream(descriptorFiles)
- .map(descriptorFile -> {
- try {
- return reader.read(descriptorFile.toString());
- } catch (final Exception error) {
- final String message = String.format("failed reading descriptor file `%s`", descriptorFile);
- throw new RuntimeException(message, error);
- }
- })
- .collect(Collectors.toSet());
- }
-
- private void generateSchema(final Set<PluginSet> pluginSets) throws MojoExecutionException {
+ final Set<PluginSet> pluginSets = PluginSets.ofDescriptorFiles(descriptorFiles);
try {
SchemaGenerator.generateSchema(pluginSets, schemaFile.toPath());
} catch (final XMLStreamException error) {
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DocumentationGenerator.java
similarity index 98%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGenerator.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DocumentationGenerator.java
index 2057bfb..2956e34 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DocumentationGenerator.java
@@ -35,9 +35,9 @@ import org.apache.logging.log4j.docgen.ScalarType;
import org.apache.logging.log4j.docgen.Type;
import org.apache.logging.log4j.docgen.util.TypeLookup;
-public final class FreeMarkerGenerator {
+public final class DocumentationGenerator {
- private FreeMarkerGenerator() {}
+ private DocumentationGenerator() {}
public static void generateDocumentation(
final Set<PluginSet> pluginSets,
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/DocumentationGeneratorTest.java
similarity index 95%
rename from log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
rename to log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/DocumentationGeneratorTest.java
index 38e8c14..ab4b987 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/DocumentationGeneratorTest.java
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
-public class FreeMarkerGeneratorTest {
+public class DocumentationGeneratorTest {
@Test
void generatePluginDocumentation(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir) throws Exception {
@@ -38,7 +38,7 @@ public class FreeMarkerGeneratorTest {
// Generate the documentation
final Path templateDirectory = Paths.get("src/test/resources/templates");
- FreeMarkerGenerator.generateDocumentation(
+ DocumentationGenerator.generateDocumentation(
Set.of(pluginSet), templateDirectory, "scalars.ftl", "plugin.ftl", "interface.ftl", outputDir);
// Verify the output
(logging-log4j-tools) 12/29: Fix typos in `plugins-model.xml`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 1085e6ccbd4cb12af35cf62a5fb1976baa65f2e5
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 14 11:05:39 2024 +0100
Fix typos in `plugins-model.xml`
---
log4j-docgen/src/main/mdo/plugins-model.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/log4j-docgen/src/main/mdo/plugins-model.xml b/log4j-docgen/src/main/mdo/plugins-model.xml
index d556f14..a4fea45 100644
--- a/log4j-docgen/src/main/mdo/plugins-model.xml
+++ b/log4j-docgen/src/main/mdo/plugins-model.xml
@@ -50,12 +50,12 @@
<field>
<name>groupId</name>
<type>String</type>
- <description>The group id of the set.</description>
+ <description>The group ID of the set.</description>
</field>
<field>
<name>artifactId</name>
<type>String</type>
- <description>The artifact id of the set.</description>
+ <description>The artifact ID of the set.</description>
</field>
<field>
<name>version</name>
(logging-log4j-tools) 16/29: Add `SchemaGeneratorMojo`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit debb6435f4ca2251c8ec6c44760eef6bcba8db04
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Thu Feb 15 11:59:07 2024 +0100
Add `SchemaGeneratorMojo`
---
log4j-changelog/pom.xml | 6 +-
.../changelog/exporter/ChangelogExporter.java | 1 +
.../logging/log4j/changelog/util/XmlWriter.java | 10 +-
.../log4j/changelog/ChangelogExporterTest.java | 2 +-
.../log4j/changelog/ChangelogReleaserTest.java | 2 +-
.../log4j/changelog/MavenChangesImporterTest.java | 2 +-
.../pom.xml | 28 +++-
.../log4j/docgen/maven/SchemaGeneratorMojo.java | 81 ++++++++++
log4j-docgen/pom.xml | 6 +-
.../log4j/docgen/internal/ConfigurationXml.java | 23 ++-
.../internal/DefaultFreeMarkerGenerator.java | 164 ---------------------
.../log4j/docgen/internal/FreeMarkerGenerator.java | 96 ++++++++++++
...ltSchemaGenerator.java => SchemaGenerator.java} | 33 +++--
log4j-docgen/src/main/mdo/plugins-model.xml | 121 ---------------
.../docgen/internal/FreeMarkerGeneratorTest.java | 13 +-
.../log4j/docgen/internal/SchemaGeneratorTest.java | 15 +-
.../src/test/resources/generated-plugins.xsd | 4 +-
.../pom.xml | 11 +-
.../internal/freemarker/util}/FreeMarkerUtils.java | 20 +--
.../pom.xml | 8 +-
.../tools/internal/test/util}/FileTestUtils.java | 2 +-
log4j-tools-parent/pom.xml | 11 +-
pom.xml | 1 +
23 files changed, 300 insertions(+), 360 deletions(-)
diff --git a/log4j-changelog/pom.xml b/log4j-changelog/pom.xml
index 78aceea..5bba4c5 100644
--- a/log4j-changelog/pom.xml
+++ b/log4j-changelog/pom.xml
@@ -43,13 +43,13 @@
</dependency>
<dependency>
- <groupId>org.freemarker</groupId>
- <artifactId>freemarker</artifactId>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-tools-internal-freemarker-util</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <artifactId>log4j-tools-internal-test-util</artifactId>
<scope>test</scope>
</dependency>
diff --git a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/ChangelogExporter.java b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/ChangelogExporter.java
index 235ac5f..8a12319 100644
--- a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/ChangelogExporter.java
+++ b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/ChangelogExporter.java
@@ -33,6 +33,7 @@ import org.apache.logging.log4j.changelog.ChangelogEntry;
import org.apache.logging.log4j.changelog.ChangelogFiles;
import org.apache.logging.log4j.changelog.ChangelogRelease;
import org.apache.logging.log4j.changelog.util.FileUtils;
+import org.apache.logging.log4j.tools.internal.freemarker.util.FreeMarkerUtils;
public final class ChangelogExporter {
diff --git a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/XmlWriter.java b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/XmlWriter.java
index 0ce9848..a682d8b 100644
--- a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/XmlWriter.java
+++ b/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/XmlWriter.java
@@ -19,6 +19,8 @@ package org.apache.logging.log4j.changelog.util;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -36,6 +38,10 @@ import org.w3c.dom.Element;
public final class XmlWriter {
+ private static final Charset CHARSET = StandardCharsets.UTF_8;
+
+ private static final String CHARSET_NAME = CHARSET.name();
+
private static final String LS = System.lineSeparator();
private XmlWriter() {}
@@ -44,7 +50,7 @@ public final class XmlWriter {
final Path filepath, final String rootElementName, final BiConsumer<Document, Element> documentConsumer) {
try {
final String xml = toString(rootElementName, documentConsumer);
- final byte[] xmlBytes = xml.getBytes(CharsetUtils.CHARSET);
+ final byte[] xmlBytes = xml.getBytes(CHARSET);
@Nullable final Path filepathParent = filepath.getParent();
if (filepathParent != null) {
Files.createDirectories(filepathParent);
@@ -105,7 +111,7 @@ public final class XmlWriter {
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
final StreamResult result = new StreamResult(new StringWriter());
final DOMSource source = new DOMSource(document);
- transformer.setOutputProperty(OutputKeys.ENCODING, CharsetUtils.CHARSET_NAME);
+ transformer.setOutputProperty(OutputKeys.ENCODING, CHARSET_NAME);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(source, result);
diff --git a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java
index 7f4e53f..b420460 100644
--- a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java
+++ b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.changelog;
-import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
+import static org.apache.logging.log4j.tools.internal.test.util.FileTestUtils.assertDirectoryContentMatches;
import java.nio.file.Path;
import java.nio.file.Paths;
diff --git a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
index 9b40b09..b5f3805 100644
--- a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
+++ b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
@@ -17,7 +17,7 @@
package org.apache.logging.log4j.changelog;
import static org.apache.commons.io.FileUtils.copyDirectory;
-import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
+import static org.apache.logging.log4j.tools.internal.test.util.FileTestUtils.assertDirectoryContentMatches;
import java.io.File;
import java.nio.file.Path;
diff --git a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java
index d9ad463..49cedbe 100644
--- a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java
+++ b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.changelog;
-import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
+import static org.apache.logging.log4j.tools.internal.test.util.FileTestUtils.assertDirectoryContentMatches;
import java.nio.file.Path;
import java.nio.file.Paths;
diff --git a/log4j-tools-internal-test-utils/pom.xml b/log4j-docgen-maven-plugin/pom.xml
similarity index 66%
copy from log4j-tools-internal-test-utils/pom.xml
copy to log4j-docgen-maven-plugin/pom.xml
index 9a230ae..914a9a1 100644
--- a/log4j-tools-internal-test-utils/pom.xml
+++ b/log4j-docgen-maven-plugin/pom.xml
@@ -26,18 +26,36 @@
<relativePath>../log4j-tools-parent</relativePath>
</parent>
- <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <artifactId>log4j-docgen-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
<properties>
- <bnd.baseline.skip>true</bnd.baseline.skip>
- <maven.deploy.skip>true</maven.deploy.skip>
+
+ <!-- Disabling `bnd-baseline-maven-plugin`, since we don't have a release yet to compare against. -->
+ <bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
+
+ <bnd.packagingTypes>maven-plugin</bnd.packagingTypes>
+
</properties>
<dependencies>
+
<dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-docgen</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ </dependency>
+
</dependencies>
</project>
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
new file mode 100644
index 0000000..825082e
--- /dev/null
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.maven;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+import javax.xml.stream.XMLStreamException;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.internal.SchemaGenerator;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+/**
+ * Goal generating an XSD from a given plugin descriptor, e.g., {@code plugins.xml}.
+ *
+ * @see org.apache.logging.log4j.docgen.internal.SchemaGenerator
+ */
+@Mojo(name = "generate-schema", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
+public class SchemaGeneratorMojo extends AbstractMojo {
+
+ /**
+ * The paths of the plugin descriptor XML files
+ */
+ @Parameter(property = "log4j.docgen.descriptorFiles", required = true)
+ private File[] descriptorFiles;
+
+ /**
+ * The path of the XSD file to write to
+ */
+ @Parameter(property = "log4j.docgen.schemaFile", required = true)
+ private File schemaFile;
+
+ @Override
+ public void execute() throws MojoExecutionException {
+ final Set<PluginSet> pluginSet = readPluginSets();
+ generateSchema(pluginSet);
+ }
+
+ private Set<PluginSet> readPluginSets() {
+ final PluginBundleStaxReader reader = new PluginBundleStaxReader();
+ return Arrays.stream(descriptorFiles)
+ .map(descriptorFile -> {
+ try {
+ return reader.read(descriptorFile.toString());
+ } catch (final Exception error) {
+ final String message = String.format("failed reading descriptor file `%s`", descriptorFile);
+ throw new RuntimeException(message, error);
+ }
+ })
+ .collect(Collectors.toSet());
+ }
+
+ private void generateSchema(final Set<PluginSet> pluginSets) throws MojoExecutionException {
+ try {
+ SchemaGenerator.generateSchema(pluginSets, schemaFile.toPath());
+ } catch (final XMLStreamException error) {
+ final String message = String.format("failed generating the schema file `%s`", schemaFile);
+ throw new MojoExecutionException(message, error);
+ }
+ }
+}
diff --git a/log4j-docgen/pom.xml b/log4j-docgen/pom.xml
index cd58c1d..0889635 100644
--- a/log4j-docgen/pom.xml
+++ b/log4j-docgen/pom.xml
@@ -74,13 +74,13 @@
</dependency>
<dependency>
- <groupId>org.freemarker</groupId>
- <artifactId>freemarker</artifactId>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-tools-internal-freemarker-util</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <artifactId>log4j-tools-internal-test-util</artifactId>
<scope>test</scope>
</dependency>
diff --git a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/CharsetUtils.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/ConfigurationXml.java
similarity index 50%
rename from log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/CharsetUtils.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/ConfigurationXml.java
index 6e2d335..0dde0f2 100644
--- a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/util/CharsetUtils.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/ConfigurationXml.java
@@ -14,16 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.changelog.util;
+package org.apache.logging.log4j.docgen.internal;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
+import java.io.InputStream;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
-public final class CharsetUtils {
+final class ConfigurationXml {
- private CharsetUtils() {}
+ static final PluginSet PLUGIN_SET = readConfigurationSet();
- public static final Charset CHARSET = StandardCharsets.UTF_8;
-
- public static final String CHARSET_NAME = CHARSET.name();
+ private static PluginSet readConfigurationSet() {
+ final String resourceName = "configuration.xml";
+ try (final InputStream inputStream = ConfigurationXml.class.getResourceAsStream(resourceName)) {
+ return new PluginBundleStaxReader().read(inputStream);
+ } catch (final Exception error) {
+ final String message = String.format("failed reading plugins from `%s` resource", resourceName);
+ throw new RuntimeException(message, error);
+ }
+ }
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultFreeMarkerGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultFreeMarkerGenerator.java
deleted file mode 100644
index d3b396b..0000000
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultFreeMarkerGenerator.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.logging.log4j.docgen.internal;
-
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import freemarker.cache.FileTemplateLoader;
-import freemarker.template.Configuration;
-import freemarker.template.DefaultObjectWrapper;
-import freemarker.template.DefaultObjectWrapperBuilder;
-import freemarker.template.Template;
-import freemarker.template.TemplateExceptionHandler;
-import freemarker.template.Version;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.UncheckedIOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeSet;
-import javax.xml.stream.XMLStreamException;
-import org.apache.logging.log4j.docgen.AbstractType;
-import org.apache.logging.log4j.docgen.PluginSet;
-import org.apache.logging.log4j.docgen.PluginType;
-import org.apache.logging.log4j.docgen.ScalarType;
-import org.apache.logging.log4j.docgen.Type;
-import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGenerator;
-import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGeneratorRequest;
-import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
-import org.apache.logging.log4j.docgen.util.TypeLookup;
-
-public class DefaultFreeMarkerGenerator implements FreeMarkerGenerator {
-
- private static final String CHARSET = "UTF-8";
-
- @Override
- public void generateDocumentation(final FreeMarkerGeneratorRequest request) throws IOException {
- final PluginSet configurationSet;
- try {
- configurationSet = new PluginBundleStaxReader().read(getClass().getResourceAsStream("configuration.xml"));
- } catch (final XMLStreamException e) {
- throw new RuntimeException("Internal error: unable to parse resource `configuration.xml`.", e);
- }
- final Collection<PluginSet> extendedSets = new ArrayList<>(request.getPluginSets());
- extendedSets.add(configurationSet);
-
- final Configuration configuration = createConfiguration(request.getTemplateDirectory());
- final TypeLookup lookup = TypeLookup.of(extendedSets);
- final Collection<ScalarType> scalarTypes = new TreeSet<>(Comparator.comparing(ScalarType::getClassName));
- for (final Type type : lookup.values()) {
- if (type instanceof AbstractType) {
- final String template =
- type instanceof PluginType ? request.getPluginTemplate() : request.getInterfaceTemplate();
- documentAbstractType(
- (AbstractType) type, lookup, configuration, template, request.getOutputDirectory());
- }
- if (type instanceof ScalarType) {
- scalarTypes.add((ScalarType) type);
- }
- }
- documentScalarTypes(scalarTypes, configuration, request.getScalarsTemplate(), request.getOutputDirectory());
- }
-
- private static void documentAbstractType(
- final AbstractType abstractType,
- final TypeLookup lookup,
- final Configuration configuration,
- final String template,
- final Path outputDir) {
- final Map<String, Object> templateData = new HashMap<>();
- templateData.put("type", abstractType);
- templateData.put("lookup", lookup);
-
- final Path outputFile = createOutputFile(abstractType, outputDir);
- render(configuration, template, templateData, outputFile);
- }
-
- private static void documentScalarTypes(
- final Collection<ScalarType> scalarTypes,
- final Configuration configuration,
- final String template,
- final Path outputDir) {
- final Map<String, Object> templateData = new HashMap<>();
- templateData.put("scalars", scalarTypes);
-
- final Path outputFile = outputDir.resolve("scalars.adoc");
- render(configuration, template, templateData, outputFile);
- }
-
- private static Path createOutputFile(final Type type, final Path outputDir) {
- final Path outputFile = outputDir.resolve("Core").resolve(type.getClassName() + ".adoc");
- if (!outputFile.startsWith(outputDir)) {
- throw new RuntimeException("Class name '" + type.getClassName() + "' caused a path traversal attempt.");
- }
- return outputFile;
- }
-
- @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
- private static Configuration createConfiguration(final Path templateDirectory) {
- final Version configurationVersion = Configuration.VERSION_2_3_29;
- final Configuration configuration = new Configuration(configurationVersion);
- configuration.setDefaultEncoding(CHARSET);
- configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
- try {
- configuration.setTemplateLoader(new FileTemplateLoader(templateDirectory.toFile()));
- } catch (final IOException error) {
- throw new UncheckedIOException(error);
- }
- final DefaultObjectWrapperBuilder objectWrapperBuilder = new DefaultObjectWrapperBuilder(configurationVersion);
- objectWrapperBuilder.setExposeFields(true);
- final DefaultObjectWrapper objectWrapper = objectWrapperBuilder.build();
- configuration.setObjectWrapper(objectWrapper);
- configuration.setLogTemplateExceptions(false);
- configuration.setWrapUncheckedExceptions(true);
- configuration.setFallbackOnNullLoopVariable(false);
- return configuration;
- }
-
- @SuppressFBWarnings("TEMPLATE_INJECTION_FREEMARKER")
- static void render(
- final Configuration configuration,
- final String templateName,
- final Object templateData,
- final Path outputFile) {
- try {
- final Template template = configuration.getTemplate(templateName);
- final Path outputFileParent = outputFile.getParent();
- if (outputFileParent != null) {
- Files.createDirectories(outputFileParent);
- }
- try (final BufferedWriter outputFileWriter = Files.newBufferedWriter(
- outputFile,
- StandardCharsets.UTF_8,
- StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING)) {
- template.process(templateData, outputFileWriter);
- }
- } catch (final Exception error) {
- final String message = String.format(
- "failed rendering template `%s` in directory `%s` to file `%s`",
- templateName, configuration, outputFile);
- throw new RuntimeException(message, error);
- }
- }
-}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGenerator.java
new file mode 100644
index 0000000..2057bfb
--- /dev/null
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGenerator.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.internal;
+
+import static org.apache.logging.log4j.tools.internal.freemarker.util.FreeMarkerUtils.render;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.logging.log4j.docgen.AbstractType;
+import org.apache.logging.log4j.docgen.PluginSet;
+import org.apache.logging.log4j.docgen.PluginType;
+import org.apache.logging.log4j.docgen.ScalarType;
+import org.apache.logging.log4j.docgen.Type;
+import org.apache.logging.log4j.docgen.util.TypeLookup;
+
+public final class FreeMarkerGenerator {
+
+ private FreeMarkerGenerator() {}
+
+ public static void generateDocumentation(
+ final Set<PluginSet> pluginSets,
+ final Path templateDirectory,
+ final String scalarsTemplateName,
+ final String pluginTemplateName,
+ final String interfaceTemplateName,
+ final Path outputDirectory) {
+ final List<PluginSet> extendedSets = Stream.concat(Stream.of(ConfigurationXml.PLUGIN_SET), pluginSets.stream())
+ .collect(Collectors.toList());
+ final TypeLookup lookup = TypeLookup.of(extendedSets);
+ final Collection<ScalarType> scalarTypes = new TreeSet<>(Comparator.comparing(ScalarType::getClassName));
+ for (final Type type : lookup.values()) {
+ if (type instanceof AbstractType) {
+ final String template = type instanceof PluginType ? pluginTemplateName : interfaceTemplateName;
+ documentAbstractType((AbstractType) type, lookup, templateDirectory, template, outputDirectory);
+ }
+ if (type instanceof ScalarType) {
+ scalarTypes.add((ScalarType) type);
+ }
+ }
+ documentScalarTypes(scalarTypes, templateDirectory, scalarsTemplateName, outputDirectory);
+ }
+
+ private static void documentAbstractType(
+ final AbstractType abstractType,
+ final TypeLookup lookup,
+ final Path templateDirectory,
+ final String templateName,
+ final Path outputDir) {
+ final Map<String, Object> templateData = new HashMap<>();
+ templateData.put("type", abstractType);
+ templateData.put("lookup", lookup);
+ final Path outputFile = createOutputFile(abstractType, outputDir);
+ render(templateDirectory, templateName, templateData, outputFile);
+ }
+
+ private static void documentScalarTypes(
+ final Collection<ScalarType> scalarTypes,
+ final Path templateDirectory,
+ final String templateName,
+ final Path outputDir) {
+ final Map<String, Object> templateData = new HashMap<>();
+ templateData.put("scalars", scalarTypes);
+ final Path outputFile = outputDir.resolve("scalars.adoc");
+ render(templateDirectory, templateName, templateData, outputFile);
+ }
+
+ private static Path createOutputFile(final Type type, final Path outputDir) {
+ final Path outputFile = outputDir.resolve("Core").resolve(type.getClassName() + ".adoc");
+ if (!outputFile.startsWith(outputDir)) {
+ throw new RuntimeException("Class name '" + type.getClassName() + "' caused a path traversal attempt.");
+ }
+ return outputFile;
+ }
+}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultSchemaGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/SchemaGenerator.java
similarity index 92%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultSchemaGenerator.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/SchemaGenerator.java
index 8e23275..2d1c862 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/DefaultSchemaGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/internal/SchemaGenerator.java
@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.XMLConstants;
@@ -39,33 +41,34 @@ import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.ScalarType;
import org.apache.logging.log4j.docgen.ScalarValue;
import org.apache.logging.log4j.docgen.Type;
-import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
import org.apache.logging.log4j.docgen.util.TypeLookup;
-import org.apache.logging.log4j.docgen.xsd.SchemaGenerator;
-import org.apache.logging.log4j.docgen.xsd.SchemaGeneratorRequest;
@Singleton
@Named("default")
-public class DefaultSchemaGenerator implements SchemaGenerator {
+public final class SchemaGenerator {
private static final String LOG4J_PREFIX = "log4j";
+
private static final String LOG4J_NAMESPACE = "http://logging.apache.org/xml/ns/config";
+
private static final String XSD_NAMESPACE = XMLConstants.W3C_XML_SCHEMA_NS_URI;
+
private static final String MULTIPLICITY_UNBOUNDED = "*";
- private static final String ENCODING = "UTF-8";
- @Override
- public void generateSchema(final SchemaGeneratorRequest request) throws XMLStreamException {
+ private static final String CHARSET_NAME = "UTF-8";
+
+ private SchemaGenerator() {}
+
+ public static void generateSchema(final Set<PluginSet> pluginSets, final Path schemaFile)
+ throws XMLStreamException {
try {
- final PluginSet configurationSet =
- new PluginBundleStaxReader().read(getClass().getResourceAsStream("configuration.xml"));
- final List<PluginSet> extendedSets = new ArrayList<>(request.getPluginSets());
- extendedSets.add(configurationSet);
+ final List<PluginSet> extendedSets = Stream.concat(
+ Stream.of(ConfigurationXml.PLUGIN_SET), pluginSets.stream())
+ .collect(Collectors.toList());
final TypeLookup lookup = TypeLookup.of(extendedSets);
final XMLOutputFactory factory = XMLOutputFactory.newFactory();
- final Path schemaPath = request.getOutputDirectory().resolve(request.getFileName());
- try (final OutputStream schemaPathOutputStream = Files.newOutputStream(schemaPath)) {
- final XMLStreamWriter writer = factory.createXMLStreamWriter(schemaPathOutputStream, ENCODING);
+ try (final OutputStream schemaPathOutputStream = Files.newOutputStream(schemaFile)) {
+ final XMLStreamWriter writer = factory.createXMLStreamWriter(schemaPathOutputStream, CHARSET_NAME);
try {
writeSchema(lookup, writer);
} finally {
@@ -78,7 +81,7 @@ public class DefaultSchemaGenerator implements SchemaGenerator {
}
private static void writeSchema(final TypeLookup lookup, final XMLStreamWriter writer) throws XMLStreamException {
- writer.writeStartDocument(ENCODING, "1.0");
+ writer.writeStartDocument(CHARSET_NAME, "1.0");
writer.setDefaultNamespace(XSD_NAMESPACE);
writer.writeStartElement(XSD_NAMESPACE, "schema");
writer.writeDefaultNamespace(XSD_NAMESPACE);
diff --git a/log4j-docgen/src/main/mdo/plugins-model.xml b/log4j-docgen/src/main/mdo/plugins-model.xml
index a4fea45..a9dc5bf 100644
--- a/log4j-docgen/src/main/mdo/plugins-model.xml
+++ b/log4j-docgen/src/main/mdo/plugins-model.xml
@@ -387,126 +387,5 @@ If the type is an array or collection, this returns the type of the element.</de
</codeSegment>
</codeSegments>
</class>
- <!-- Models for various generators -->
- <class>
- <name>DocumentationRequest</name>
- <fields>
- <field xml.transient="true">
- <name>pluginSets</name>
- <association>
- <type>PluginSet</type>
- <multiplicity>*</multiplicity>
- </association>
- <required>true</required>
- <description>The set of plugins to document.</description>
- </field>
- <field xml.transient="true">
- <name>outputDirectory</name>
- <association>
- <type>java.nio.file.Path</type>
- </association>
- <required>true</required>
- <description>The directory to use for output.</description>
- </field>
- </fields>
- </class>
- <class>
- <packageName>org.apache.logging.log4j.docgen.xsd</packageName>
- <name>SchemaGeneratorRequest</name>
- <superClass>DocumentationRequest</superClass>
- <fields>
- <field xml.transient="true">
- <name>fileName</name>
- <type>String</type>
- <defaultValue>log4j-config.xml</defaultValue>
- <description>The path to the generated schema file. If it is relative, it will be resolved against `outputDirectory`.</description>
- </field>
- </fields>
- </class>
- <class>
- <name>FreeMarkerGeneratorRequest</name>
- <packageName>org.apache.logging.log4j.docgen.freemarker</packageName>
- <superClass>DocumentationRequest</superClass>
- <fields>
- <field xml.transient="true">
- <name>templateDirectory</name>
- <association>
- <type>java.nio.file.Path</type>
- </association>
- <required>true</required>
- <description>
- The directory containing the FreeMarker templates.
- </description>
- </field>
- <field xml.transient="true">
- <name>pluginTemplate</name>
- <type>String</type>
- <defaultValue>plugin.ftl</defaultValue>
- <description><![CDATA[FreeMarker template to apply for to each {@link PluginType}.
-<p>
-Template parameters:
-</p>
-<ul>
- <li>`type`: the {@link PluginType} to format,</li>
- <li>`lookup`: a {@link org.apache.logging.log4j.docgen.util.TypeLookup} containing type information for other plugins.</li>
-</ul>]]></description>
- </field>
- <field xml.transient="true">
- <name>interfaceTemplate</name>
- <type>String</type>
- <defaultValue>interface.ftl</defaultValue>
- <description><![CDATA[A FreeMarker template to apply for to each {@link AbstractType}.
-<p>
-Template parameters:
-</p>
-<ul>
- <li>`type`: the {@link AbstractType} to format,</li>
- <li>`lookup`: a {@link org.apache.logging.log4j.docgen.util.TypeLookup} containing type information for other plugins.</li>
-</ul>]]></description>
- </field>
- <field xml.transient="true">
- <name>scalarsTemplate</name>
- <type>String</type>
- <defaultValue>scalars.ftl</defaultValue>
- <description><![CDATA[A FreeMarker template to describe all {@link ScalarType} types.
-<p>
-Template parameters:
-</p>
-<ul>
- <li>`scalars`: a list of all {@link ScalarType} elements to format.</li>
-</ul>]]></description>
- </field>
- </fields>
- </class>
- <!-- External classes -->
- <class java.enabled="false">
- <name>java.nio.file.Path</name>
- </class>
</classes>
- <interfaces>
- <interface>
- <packageName>org.apache.logging.log4j.docgen.xsd</packageName>
- <name>SchemaGenerator</name>
- <codeSegments>
- <codeSegment>
- <comment>Generates an XML schema.
-
-@param request configuration data for the generated schema.</comment>
- <code>void generateSchema(SchemaGeneratorRequest request) throws javax.xml.stream.XMLStreamException;</code>
- </codeSegment>
- </codeSegments>
- </interface>
- <interface>
- <packageName>org.apache.logging.log4j.docgen.freemarker</packageName>
- <name>FreeMarkerGenerator</name>
- <codeSegments>
- <codeSegment>
- <comment>Generates documentation using FreeMarker.
-
-@param request configuration data for the generated documentation.</comment>
- <code>void generateDocumentation(FreeMarkerGeneratorRequest request) throws java.io.IOException;</code>
- </codeSegment>
- </codeSegments>
- </interface>
- </interfaces>
</model>
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
index 09eee2c..38e8c14 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
@@ -16,13 +16,12 @@
*/
package org.apache.logging.log4j.docgen.internal;
-import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
+import static org.apache.logging.log4j.tools.internal.test.util.FileTestUtils.assertDirectoryContentMatches;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Set;
import org.apache.logging.log4j.docgen.PluginSet;
-import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGenerator;
-import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGeneratorRequest;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
@@ -38,13 +37,9 @@ public class FreeMarkerGeneratorTest {
final PluginSet pluginSet = reader.read("src/test/resources/example-plugins.xml");
// Generate the documentation
- final FreeMarkerGenerator generator = new DefaultFreeMarkerGenerator();
- final FreeMarkerGeneratorRequest request = new FreeMarkerGeneratorRequest();
- request.addPluginSet(pluginSet);
final Path templateDirectory = Paths.get("src/test/resources/templates");
- request.setTemplateDirectory(templateDirectory);
- request.setOutputDirectory(outputDir);
- generator.generateDocumentation(request);
+ FreeMarkerGenerator.generateDocumentation(
+ Set.of(pluginSet), templateDirectory, "scalars.ftl", "plugin.ftl", "interface.ftl", outputDir);
// Verify the output
final Path expectedDir = Paths.get("src/test/resources/plugins-to-freemarker-output");
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
index adee706..bb14b9c 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/SchemaGeneratorTest.java
@@ -16,13 +16,14 @@
*/
package org.apache.logging.log4j.docgen.internal;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Set;
import javax.xml.transform.Source;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
-import org.apache.logging.log4j.docgen.xsd.SchemaGenerator;
-import org.apache.logging.log4j.docgen.xsd.SchemaGeneratorRequest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
@@ -52,13 +53,11 @@ public class SchemaGeneratorTest {
final PluginSet pluginSet = reader.read("src/test/resources/example-plugins.xml");
// Generate the schema
- final SchemaGeneratorRequest request = new SchemaGeneratorRequest();
- request.addPluginSet(pluginSet);
- request.setOutputDirectory(outputDir);
- final SchemaGenerator generator = new DefaultSchemaGenerator();
- generator.generateSchema(request);
+ final Path schemaFile = outputDir.resolve("config.xsd");
+ SchemaGenerator.generateSchema(Set.of(pluginSet), schemaFile);
// Return the generated XSD file path
- return outputDir.resolve(request.getFileName());
+ assertThat(schemaFile).isNotEmptyFile();
+ return schemaFile;
}
}
diff --git a/log4j-docgen/src/test/resources/generated-plugins.xsd b/log4j-docgen/src/test/resources/generated-plugins.xsd
index 643cda9..a553813 100644
--- a/log4j-docgen/src/test/resources/generated-plugins.xsd
+++ b/log4j-docgen/src/test/resources/generated-plugins.xsd
@@ -16,8 +16,8 @@
~ limitations under the License.
-->
<!--
- ~ This is a test schema used in SchemaGeneratorTest.
- ~ Unlike this file the DefaultSchemaGenerator strips whitespace.
+ ~ This is a test schema used in `SchemaGeneratorTest`.
+ ~ Unlike this file the `SchemaGenerator` strips whitespace.
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:log4j="http://logging.apache.org/xml/ns/config" elementFormDefault="qualified" targetNamespace="http://logging.apache.org/xml/ns/config">
<element type="log4j:org.apache.logging.log4j.core.config.Configuration" name="Configuration"/>
diff --git a/log4j-tools-internal-test-utils/pom.xml b/log4j-tools-internal-freemarker-util/pom.xml
similarity index 83%
copy from log4j-tools-internal-test-utils/pom.xml
copy to log4j-tools-internal-freemarker-util/pom.xml
index 9a230ae..71b2b72 100644
--- a/log4j-tools-internal-test-utils/pom.xml
+++ b/log4j-tools-internal-freemarker-util/pom.xml
@@ -26,17 +26,20 @@
<relativePath>../log4j-tools-parent</relativePath>
</parent>
- <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <artifactId>log4j-tools-internal-freemarker-util</artifactId>
<properties>
+
+ <!-- This is an internal library and is not intended for public consumption.
+ Hence, tolerate backward incompatible changes: -->
<bnd.baseline.skip>true</bnd.baseline.skip>
- <maven.deploy.skip>true</maven.deploy.skip>
+
</properties>
<dependencies>
<dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
+ <groupId>org.freemarker</groupId>
+ <artifactId>freemarker</artifactId>
</dependency>
</dependencies>
diff --git a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java b/log4j-tools-internal-freemarker-util/src/main/java/org/apache/logging/log4j/tools/internal/freemarker/util/FreeMarkerUtils.java
similarity index 87%
rename from log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java
rename to log4j-tools-internal-freemarker-util/src/main/java/org/apache/logging/log4j/tools/internal/freemarker/util/FreeMarkerUtils.java
index 44a9712..cc31133 100644
--- a/log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/FreeMarkerUtils.java
+++ b/log4j-tools-internal-freemarker-util/src/main/java/org/apache/logging/log4j/tools/internal/freemarker/util/FreeMarkerUtils.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.changelog.exporter;
+package org.apache.logging.log4j.tools.internal.freemarker.util;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import freemarker.cache.FileTemplateLoader;
@@ -27,12 +27,17 @@ import freemarker.template.Version;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
-import org.apache.logging.log4j.changelog.util.CharsetUtils;
-final class FreeMarkerUtils {
+public final class FreeMarkerUtils {
+
+ private static final Charset CHARSET = StandardCharsets.UTF_8;
+
+ private static final String CHARSET_NAME = CHARSET.name();
private FreeMarkerUtils() {}
@@ -40,7 +45,7 @@ final class FreeMarkerUtils {
private static Configuration createConfiguration(final Path templateDirectory) {
final Version configurationVersion = Configuration.VERSION_2_3_29;
final Configuration configuration = new Configuration(configurationVersion);
- configuration.setDefaultEncoding(CharsetUtils.CHARSET_NAME);
+ configuration.setDefaultEncoding(CHARSET_NAME);
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
try {
configuration.setTemplateLoader(new FileTemplateLoader(templateDirectory.toFile()));
@@ -58,7 +63,7 @@ final class FreeMarkerUtils {
}
@SuppressFBWarnings("TEMPLATE_INJECTION_FREEMARKER")
- static void render(
+ public static void render(
final Path templateDirectory, final String templateName, final Object templateData, final Path outputFile) {
try {
final Configuration configuration = createConfiguration(templateDirectory);
@@ -68,10 +73,7 @@ final class FreeMarkerUtils {
Files.createDirectories(outputFileParent);
}
try (final BufferedWriter outputFileWriter = Files.newBufferedWriter(
- outputFile,
- CharsetUtils.CHARSET,
- StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING)) {
+ outputFile, CHARSET, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
template.process(templateData, outputFileWriter);
}
} catch (final Exception error) {
diff --git a/log4j-tools-internal-test-utils/pom.xml b/log4j-tools-internal-test-util/pom.xml
similarity index 84%
rename from log4j-tools-internal-test-utils/pom.xml
rename to log4j-tools-internal-test-util/pom.xml
index 9a230ae..6ad6897 100644
--- a/log4j-tools-internal-test-utils/pom.xml
+++ b/log4j-tools-internal-test-util/pom.xml
@@ -26,11 +26,17 @@
<relativePath>../log4j-tools-parent</relativePath>
</parent>
- <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <artifactId>log4j-tools-internal-test-util</artifactId>
<properties>
+
+ <!-- This is an internal library and is not intended for public consumption.
+ Hence, tolerate backward incompatible changes: -->
<bnd.baseline.skip>true</bnd.baseline.skip>
+
+ <!-- This library is intended only for tests, hence, does not need to be deployed: -->
<maven.deploy.skip>true</maven.deploy.skip>
+
</properties>
<dependencies>
diff --git a/log4j-tools-internal-test-utils/src/main/java/org/apache/logging/log4j/tools/internal/test/utils/FileTestUtils.java b/log4j-tools-internal-test-util/src/main/java/org/apache/logging/log4j/tools/internal/test/util/FileTestUtils.java
similarity index 98%
rename from log4j-tools-internal-test-utils/src/main/java/org/apache/logging/log4j/tools/internal/test/utils/FileTestUtils.java
rename to log4j-tools-internal-test-util/src/main/java/org/apache/logging/log4j/tools/internal/test/util/FileTestUtils.java
index d9054c4..5229526 100644
--- a/log4j-tools-internal-test-utils/src/main/java/org/apache/logging/log4j/tools/internal/test/utils/FileTestUtils.java
+++ b/log4j-tools-internal-test-util/src/main/java/org/apache/logging/log4j/tools/internal/test/util/FileTestUtils.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.tools.internal.test.utils;
+package org.apache.logging.log4j.tools.internal.test.util;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/log4j-tools-parent/pom.xml b/log4j-tools-parent/pom.xml
index 62ce2dc..272b3fa 100644
--- a/log4j-tools-parent/pom.xml
+++ b/log4j-tools-parent/pom.xml
@@ -30,7 +30,8 @@
<packaging>pom</packaging>
<modules>
- <module>../log4j-tools-internal-test-utils</module>
+ <module>../log4j-tools-internal-freemarker-util</module>
+ <module>../log4j-tools-internal-test-util</module>
</modules>
<properties>
@@ -58,7 +59,13 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <artifactId>log4j-tools-internal-freemarker-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-tools-internal-test-util</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/pom.xml b/pom.xml
index 97cea2c..66e555f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -87,6 +87,7 @@
<module>log4j-changelog</module>
<module>log4j-changelog-maven-plugin</module>
<module>log4j-docgen</module>
+ <module>log4j-docgen-maven-plugin</module>
</modules>
(logging-log4j-tools) 15/29: Removed unnecessary `synchronized` keyword from changelog plugin MOJOs (#80)
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 1a7aa689488d85a84ea2e60d57a885df0dbd8f15
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 14 13:18:01 2024 +0100
Removed unnecessary `synchronized` keyword from changelog plugin MOJOs (#80)
---
.../main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java | 2 +-
.../main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java | 2 +-
.../java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java | 2 +-
src/changelog/0.5.0/make-maven-plugin-thread-safe.xml | 3 +--
4 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java
index 6fb5438..d051f37 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ExportMojo.java
@@ -72,7 +72,7 @@ public final class ExportMojo extends AbstractMojo {
private File outputDirectory;
@Override
- public synchronized void execute() {
+ public void execute() {
final Set<ChangelogExporterTemplate> translatedIndexTemplates = toExporterTemplates(indexTemplates);
final Set<ChangelogExporterTemplate> translatedReleaseChangelogTemplates =
toExporterTemplates(changelogTemplates);
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java
index 21b4ef4..05249bf 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ImportMojo.java
@@ -57,7 +57,7 @@ public final class ImportMojo extends AbstractMojo {
private int releaseVersionMajor;
@Override
- public synchronized void execute() {
+ public void execute() {
final MavenChangesImporterArgs args =
new MavenChangesImporterArgs(changelogDirectory.toPath(), changesXmlFile.toPath(), releaseVersionMajor);
MavenChangesImporter.performImport(args);
diff --git a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java
index 2028575..01204b6 100644
--- a/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java
+++ b/log4j-changelog-maven-plugin/src/main/java/org/apache/logging/log4j/changelog/maven/ReleaseMojo.java
@@ -65,7 +65,7 @@ public final class ReleaseMojo extends AbstractMojo {
private String versionPattern;
@Override
- public synchronized void execute() {
+ public void execute() {
Pattern compiledVersionPattern = versionPattern != null ? Pattern.compile(versionPattern) : null;
final ChangelogReleaserArgs args = new ChangelogReleaserArgs(
changelogDirectory.toPath(),
diff --git a/src/changelog/0.5.0/make-maven-plugin-thread-safe.xml b/src/changelog/0.5.0/make-maven-plugin-thread-safe.xml
index c64a51c..2442ce2 100644
--- a/src/changelog/0.5.0/make-maven-plugin-thread-safe.xml
+++ b/src/changelog/0.5.0/make-maven-plugin-thread-safe.xml
@@ -34,7 +34,6 @@
- Check thread-safety of any other third party libraries.
This last item can be a bit hard, but inquiries on mailing lists can get you a long way.
- I think we are not prone to any of the problems shared above.
- To be certain, I have added `synchronized` modifier to each `execute()` method. -->
+ I think we are not prone to any of the problems shared above. -->
<description format="asciidoc">Make `log4j-changelog-maven-plugin` thread-safe</description>
</entry>
(logging-log4j-tools) 29/29: Merge `Documented` into `Type` type in plugin model
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit d153adbcadf95f4933f15e00344d9744e8a611c5
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 21 15:21:08 2024 +0100
Merge `Documented` into `Type` type in plugin model
---
log4j-docgen/src/main/mdo/plugins-model.xml | 23 +++++++----------------
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/log4j-docgen/src/main/mdo/plugins-model.xml b/log4j-docgen/src/main/mdo/plugins-model.xml
index a9dc5bf..0354bcc 100644
--- a/log4j-docgen/src/main/mdo/plugins-model.xml
+++ b/log4j-docgen/src/main/mdo/plugins-model.xml
@@ -99,25 +99,9 @@
</fields>
</class>
- <class>
- <name>Documented</name>
- <description>Any documented element.</description>
- <fields>
- <field>
- <name>description</name>
- <association>
- <type>Description</type>
- </association>
- <required>true</required>
- <description>Description of the plugin.</description>
- </field>
- </fields>
- </class>
-
<class>
<name>Type</name>
<description>Any Java type used in a Log4j configuration.</description>
- <superClass>Documented</superClass>
<interfaces>
<interface>java.lang.Comparable<Type></interface>
</interfaces>
@@ -128,6 +112,13 @@
<required>true</required>
<description>Fully qualified name of the class implementing the plugin.</description>
</field>
+ <field>
+ <name>description</name>
+ <association>
+ <type>Description</type>
+ </association>
+ <description>Description of the plugin.</description>
+ </field>
</fields>
<codeSegments>
<codeSegment>
(logging-log4j-tools) 01/29: Syntactic `pom.xml` improvements
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit c6d465c6bcbd342feaddd1dab15b8b94a436560a
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Mon Feb 12 21:16:19 2024 +0100
Syntactic `pom.xml` improvements
---
log4j-docgen/pom.xml | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/log4j-docgen/pom.xml b/log4j-docgen/pom.xml
index cf97aa3..2b2eb9c 100644
--- a/log4j-docgen/pom.xml
+++ b/log4j-docgen/pom.xml
@@ -16,7 +16,9 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
<modelVersion>4.0.0</modelVersion>
+
<parent>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-tools-parent</artifactId>
@@ -28,13 +30,16 @@
<properties>
<maven.compiler.release>11</maven.compiler.release>
+
+ <!-- Disabling `bnd-baseline-maven-plugin`, since we don't have a release yet to compare against. -->
<bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
<!-- Dependency versions -->
<asciidoctorj-api.version>3.0.0-alpha.2</asciidoctorj-api.version>
- <!-- We explicitly test against `log4j-core` 2.x -->
+ <!-- We explicitly test against Log4j 2 -->
<log4j-core.version>2.22.1</log4j-core.version>
<log4j-plugins.version>3.0.0-beta1</log4j-plugins.version>
+
</properties>
<dependencies>
@@ -110,18 +115,21 @@
<build>
<plugins>
+ <!-- We split the compilation into two executions:
+ 1. One that is tolerant to warnings while compiling Modello-generated sources
+ 2. One that is strict and fails on warnings while compiling the rest -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
- <!--
- ~ We split compilation in two executions, so we can fail on warnings for our sources,
- ~ but be more tolerant for generated sources.
- -->
+
+ <!-- Disable the default execution -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
+
+ <!-- Tolerant (i.e., `failOnWarning=false`) execution for Modello-generated sources -->
<execution>
<id>compile-modello-sources</id>
<goals>
@@ -137,6 +145,8 @@
</includes>
</configuration>
</execution>
+
+ <!-- Strict (i.e., `failOnWarning=true`) execution for the rest -->
<execution>
<id>compile-main</id>
<goals>
@@ -153,6 +163,7 @@
<failOnWarning>true</failOnWarning>
</configuration>
</execution>
+
</executions>
</plugin>
@@ -192,6 +203,7 @@
</execution>
</executions>
</plugin>
+
</plugins>
</build>
(logging-log4j-tools) 05/29: Refactor `AsciidocConverterTest`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit a2cde8b522059b32e8c8c863ba928401e1ecfbea
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 13 11:45:00 2024 +0100
Refactor `AsciidocConverterTest`
---
.../docgen/processor/AsciidocConverterTest.java | 55 +++++++++++++++-------
.../example/JavadocExample.java | 0
.../JavadocExample.adoc | 0
3 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
index 76af48d..0fe77b4 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciidocConverterTest.java
@@ -21,6 +21,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -29,6 +31,7 @@ import java.util.Locale;
import java.util.Set;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.DocumentationTool;
@@ -43,36 +46,52 @@ import jdk.javadoc.doclet.Doclet;
import jdk.javadoc.doclet.DocletEnvironment;
import jdk.javadoc.doclet.Reporter;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.CleanupMode;
+import org.junit.jupiter.api.io.TempDir;
public class AsciidocConverterTest {
private static final Path LICENSE_PATH = Paths.get("src/test/resources/templates/license.ftl");
+ private static final String TEST_CLASS_NAME = "JavadocExample";
+
+ private static final Charset CHARSET = UTF_8;
+
@Test
- void convertToAsciidoc() throws Exception {
+ void convertToAsciidoc(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir) throws Exception {
+
+ // Instantiate the tooling
final DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
- final DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
- final StandardJavaFileManager fileManager = tool.getStandardFileManager(null, Locale.ROOT, UTF_8);
+ final StandardJavaFileManager fileManager = tool.getStandardFileManager(null, Locale.ROOT, CHARSET);
- final Path sourcePath = Paths.get("src/test/resources/processor/asciidoc/example/JavadocExample.java");
+ // Populate sources (aka. compilation units)
+ final Path sourcePath =
+ Paths.get("src/test/resources/AsciiDocConverterTest-input/example/" + TEST_CLASS_NAME + ".java");
final Iterable<? extends JavaFileObject> sources = fileManager.getJavaFileObjects(sourcePath);
- final Path basePath = Paths.get(System.getProperty("basedir", "."));
- final Path destPath = basePath.resolve("target/test-site");
- Files.createDirectories(destPath);
- fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(destPath));
+ // Set the target path used by `Javadoc2AsciiDocDoclet` to dump the generated files
+ fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(outputDir));
+ // Compile the sources
+ final DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
final DocumentationTask task =
- tool.getTask(null, fileManager, diagnosticCollector, TestDoclet.class, null, sources);
+ tool.getTask(null, fileManager, diagnosticCollector, Javadoc2AsciiDocDoclet.class, null, sources);
task.call();
+ // Verify successful compilation
List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticCollector.getDiagnostics();
assertThat(diagnostics).noneMatch(diagnostic -> diagnostic.getKind() != Diagnostic.Kind.NOTE);
- final Path expectedPath = Paths.get("src/test/resources/expected/processor/JavadocExample.adoc");
- assertThat(destPath.resolve("processor/JavadocExample.adoc")).hasSameTextualContentAs(expectedPath, UTF_8);
+
+ // Verify the generated AsciiDoc
+ final Path expectedPath =
+ Paths.get("src/test/resources/AsciiDocConverterTest-reference-output/" + TEST_CLASS_NAME + ".adoc");
+ assertThat(outputDir.resolve(TEST_CLASS_NAME + ".adoc")).hasSameTextualContentAs(expectedPath, CHARSET);
}
- public static class TestDoclet implements Doclet {
+ /**
+ * A {@link Doclet} converting Javadoc to AsciiDoc only for the class called {@value #TEST_CLASS_NAME}.
+ */
+ public static final class Javadoc2AsciiDocDoclet implements Doclet {
@Override
public void init(final Locale locale, final Reporter reporter) {}
@@ -98,18 +117,20 @@ public class AsciidocConverterTest {
final JavaFileManager fileManager = environment.getJavaFileManager();
try {
for (final Element element : environment.getIncludedElements()) {
- if ("JavadocExample".equals(element.getSimpleName().toString())) {
+ if (ElementKind.CLASS.equals(element.getKind())
+ && TEST_CLASS_NAME.equals(element.getSimpleName().toString())) {
final FileObject output = fileManager.getFileForOutput(
- StandardLocation.CLASS_OUTPUT, "processor", "JavadocExample.adoc", null);
+ StandardLocation.CLASS_OUTPUT, "", "JavadocExample.adoc", null);
final String asciiDoc = converter.toAsciiDoc(element);
+ assertThat(asciiDoc).isNotNull();
try (final OutputStream os = output.openOutputStream()) {
Files.copy(LICENSE_PATH, os);
- os.write(asciiDoc.getBytes(UTF_8));
+ os.write(asciiDoc.getBytes(CHARSET));
}
}
}
- } catch (final IOException e) {
- throw new RuntimeException(e);
+ } catch (final IOException error) {
+ throw new UncheckedIOException(error);
}
return true;
}
diff --git a/log4j-docgen/src/test/resources/processor/asciidoc/example/JavadocExample.java b/log4j-docgen/src/test/resources/AsciiDocConverterTest-input/example/JavadocExample.java
similarity index 100%
rename from log4j-docgen/src/test/resources/processor/asciidoc/example/JavadocExample.java
rename to log4j-docgen/src/test/resources/AsciiDocConverterTest-input/example/JavadocExample.java
diff --git a/log4j-docgen/src/test/resources/expected/processor/JavadocExample.adoc b/log4j-docgen/src/test/resources/AsciiDocConverterTest-reference-output/JavadocExample.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/processor/JavadocExample.adoc
rename to log4j-docgen/src/test/resources/AsciiDocConverterTest-reference-output/JavadocExample.adoc
(logging-log4j-tools) 21/29: Avoid hardcoded file names in `DocumentationGenerator`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 4531832bfe2674c578c5c61082f38f92f929ea64
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Fri Feb 16 10:39:52 2024 +0100
Avoid hardcoded file names in `DocumentationGenerator`
---
.../docgen/maven/DocumentationGeneratorMojo.java | 36 ++++++------
.../docgen/maven/DocumentationTemplateMojo.java | 20 +++++--
.../{ConfigurationXml.java => BaseTypes.java} | 18 ++++--
.../docgen/generator/DocumentationGenerator.java | 53 ++++++++---------
.../generator/DocumentationGeneratorArgs.java | 33 +++--------
...tationFiles.java => DocumentationTemplate.java} | 13 +++--
.../log4j/docgen/generator/SchemaGenerator.java | 3 +-
.../log4j/docgen/generator/base-java-types.xml | 66 ++++++++++++++++++++++
.../{configuration.xml => base-log4j-types.xml} | 42 --------------
.../generator/DocumentationGeneratorTest.java | 10 ++--
10 files changed, 157 insertions(+), 137 deletions(-)
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
index 79b0f55..ae1de82 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
@@ -21,6 +21,7 @@ import java.util.Set;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.generator.DocumentationGenerator;
import org.apache.logging.log4j.docgen.generator.DocumentationGeneratorArgs;
+import org.apache.logging.log4j.docgen.generator.DocumentationTemplate;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -47,28 +48,22 @@ public class DocumentationGeneratorMojo extends AbstractMojo {
private File templateDirectory;
/**
- * The name of the FreeMarker template to document scalars (e.g., {@code scalars.adoc.ftl})
+ * The template that will be used to document scalar types
*/
- @Parameter(property = "log4j.docgen.scalarsTemplateName", required = true)
- private String scalarsTemplateName;
+ @Parameter(required = true)
+ private DocumentationTemplateMojo scalarsTemplate;
/**
- * The name of the FreeMarker template to document plugins (e.g., {@code plugin.adoc.ftl})
+ * The template that will be used to document plugins
*/
- @Parameter(property = "log4j.docgen.pluginTemplateName", required = true)
- private String pluginTemplateName;
+ @Parameter(required = true)
+ private DocumentationTemplateMojo pluginTemplateName;
/**
- * The name of the FreeMarker template to document interfaces (e.g., {@code interface.adoc.ftl})
+ * The template that will be used to document interfaces
*/
- @Parameter(property = "log4j.docgen.interfaceTemplateName", required = true)
- private String interfaceTemplateName;
-
- /**
- * The path to output the generated documentation
- */
- @Parameter(property = "log4j.docgen.outputDirectory", required = true)
- private File outputDirectory;
+ @Parameter(required = true)
+ private DocumentationTemplateMojo interfaceTemplate;
@Override
public void execute() {
@@ -76,10 +71,13 @@ public class DocumentationGeneratorMojo extends AbstractMojo {
final DocumentationGeneratorArgs generatorArgs = new DocumentationGeneratorArgs(
pluginSets,
templateDirectory.toPath(),
- scalarsTemplateName,
- pluginTemplateName,
- interfaceTemplateName,
- outputDirectory.toPath());
+ toApiModel(scalarsTemplate),
+ toApiModel(pluginTemplateName),
+ toApiModel(interfaceTemplate));
DocumentationGenerator.generateDocumentation(generatorArgs);
}
+
+ private static DocumentationTemplate toApiModel(final DocumentationTemplateMojo mojo) {
+ return new DocumentationTemplate(mojo.name, mojo.targetPath);
+ }
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
similarity index 63%
copy from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
copy to log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
index 43de35f..f93be5c 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
@@ -14,13 +14,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.docgen.generator;
+package org.apache.logging.log4j.docgen.maven;
-final class DocumentationFiles {
+import org.apache.maven.plugins.annotations.Parameter;
- private DocumentationFiles() {}
+public final class DocumentationTemplateMojo {
- public static String templateFileNameExtension() {
- return "ftl";
- }
+ /**
+ * The name of the template (e.g., {@code plugin.adoc.ftl}, {@code scalars.adoc.ftl})
+ */
+ @Parameter(required = true)
+ String name;
+
+ /**
+ * The target file path rendered content will be written to (e.g., {@code %g/%a/%c.adoc})
+ */
+ @Parameter(required = true)
+ String targetPath;
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ConfigurationXml.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/BaseTypes.java
similarity index 69%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ConfigurationXml.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/BaseTypes.java
index 40da480..355e4f3 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/ConfigurationXml.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/BaseTypes.java
@@ -17,16 +17,24 @@
package org.apache.logging.log4j.docgen.generator;
import java.io.InputStream;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
-final class ConfigurationXml {
+final class BaseTypes {
- static final PluginSet PLUGIN_SET = readConfigurationSet();
+ static final Set<PluginSet> PLUGIN_SETS = readBaseTypes();
- private static PluginSet readConfigurationSet() {
- final String resourceName = "configuration.xml";
- try (final InputStream inputStream = ConfigurationXml.class.getResourceAsStream(resourceName)) {
+ private static Set<PluginSet> readBaseTypes() {
+ return Stream.of("base-java-types.xml", "base-log4j-types.xml")
+ .map(BaseTypes::readBaseTypes)
+ .collect(Collectors.toSet());
+ }
+
+ private static PluginSet readBaseTypes(final String resourceName) {
+ try (final InputStream inputStream = BaseTypes.class.getResourceAsStream(resourceName)) {
return new PluginBundleStaxReader().read(inputStream);
} catch (final Exception error) {
final String message = String.format("failed reading plugins from `%s` resource", resourceName);
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
index bf5882a..38a1237 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGenerator.java
@@ -21,7 +21,6 @@ import static org.apache.logging.log4j.tools.internal.freemarker.util.FreeMarker
import java.nio.file.Path;
import java.util.Collection;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,7 +31,6 @@ import org.apache.logging.log4j.docgen.AbstractType;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.PluginType;
import org.apache.logging.log4j.docgen.ScalarType;
-import org.apache.logging.log4j.docgen.Type;
public final class DocumentationGenerator {
@@ -40,54 +38,47 @@ public final class DocumentationGenerator {
public static void generateDocumentation(final DocumentationGeneratorArgs args) {
requireNonNull(args, "args");
- final List<PluginSet> extendedSets = Stream.concat(
- Stream.of(ConfigurationXml.PLUGIN_SET), args.pluginSets.stream())
+ final List<PluginSet> extendedSets = Stream.concat(BaseTypes.PLUGIN_SETS.stream(), args.pluginSets.stream())
.collect(Collectors.toList());
final TypeLookup lookup = TypeLookup.of(extendedSets);
- final Collection<ScalarType> scalarTypes = new TreeSet<>(Comparator.comparing(ScalarType::getClassName));
- for (final Type type : lookup.values()) {
- if (type instanceof AbstractType) {
- final String template =
- type instanceof PluginType ? args.pluginTemplateName : args.interfaceTemplateName;
- documentAbstractType(
- (AbstractType) type, lookup, args.templateDirectory, template, args.outputDirectory);
- }
- if (type instanceof ScalarType) {
+ final Collection<ScalarType> scalarTypes = new TreeSet<>();
+ lookup.forEach((typeKey, type) -> {
+ if (type instanceof PluginType) {
+ documentAbstractType((AbstractType) type, lookup, args.templateDirectory, args.pluginTemplate);
+ } else if (type instanceof AbstractType) {
+ documentAbstractType((AbstractType) type, lookup, args.templateDirectory, args.interfaceTemplate);
+ } else if (type instanceof ScalarType) {
scalarTypes.add((ScalarType) type);
+ } else {
+ throw new RuntimeException("unknown type: `" + type + "`");
}
- }
- documentScalarTypes(scalarTypes, args.templateDirectory, args.scalarsTemplateName, args.outputDirectory);
+ });
+ documentScalarTypes(scalarTypes, args.templateDirectory, args.scalarsTemplate);
}
private static void documentAbstractType(
final AbstractType abstractType,
final TypeLookup lookup,
final Path templateDirectory,
- final String templateName,
- final Path outputDir) {
+ final DocumentationTemplate template) {
final Map<String, Object> templateData = new HashMap<>();
templateData.put("type", abstractType);
templateData.put("lookup", lookup);
- final Path outputFile = createOutputFile(abstractType, outputDir);
- render(templateDirectory, templateName, templateData, outputFile);
+ final Path targetPath = createAbstractTypeTargetPath(abstractType, template.targetPath);
+ render(templateDirectory, template.name, templateData, targetPath);
+ }
+
+ private static Path createAbstractTypeTargetPath(final AbstractType abstractType, final String targetPathPattern) {
+ final String targetPath = targetPathPattern.replaceAll("%c", abstractType.getClassName());
+ return Path.of(targetPath);
}
private static void documentScalarTypes(
final Collection<ScalarType> scalarTypes,
final Path templateDirectory,
- final String templateName,
- final Path outputDir) {
+ final DocumentationTemplate template) {
final Map<String, Object> templateData = new HashMap<>();
templateData.put("scalars", scalarTypes);
- final Path outputFile = outputDir.resolve("scalars.adoc");
- render(templateDirectory, templateName, templateData, outputFile);
- }
-
- private static Path createOutputFile(final Type type, final Path outputDir) {
- final Path outputFile = outputDir.resolve("Core").resolve(type.getClassName() + ".adoc");
- if (!outputFile.startsWith(outputDir)) {
- throw new RuntimeException("Class name '" + type.getClassName() + "' caused a path traversal attempt.");
- }
- return outputFile;
+ render(templateDirectory, template.name, templateData, Path.of(template.targetPath));
}
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
index b013797..f2dbfde 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
@@ -21,7 +21,6 @@ import static java.util.Objects.requireNonNull;
import java.nio.file.Path;
import java.util.Set;
import org.apache.logging.log4j.docgen.PluginSet;
-import org.jspecify.annotations.Nullable;
public final class DocumentationGeneratorArgs {
@@ -29,36 +28,22 @@ public final class DocumentationGeneratorArgs {
final Path templateDirectory;
- final String scalarsTemplateName;
+ final DocumentationTemplate scalarsTemplate;
- final String pluginTemplateName;
+ final DocumentationTemplate pluginTemplate;
- final String interfaceTemplateName;
-
- final Path outputDirectory;
+ final DocumentationTemplate interfaceTemplate;
public DocumentationGeneratorArgs(
final Set<PluginSet> pluginSets,
final Path templateDirectory,
- final String scalarsTemplateName,
- final String pluginTemplateName,
- final String interfaceTemplateName,
- final Path outputDirectory) {
+ final DocumentationTemplate scalarsTemplate,
+ final DocumentationTemplate pluginTemplate,
+ final DocumentationTemplate interfaceTemplate) {
this.pluginSets = requireNonNull(pluginSets, "pluginSets");
this.templateDirectory = requireNonNull(templateDirectory, "templateDirectory");
- this.scalarsTemplateName = requireValidTemplateName(scalarsTemplateName, "scalarsTemplateName");
- this.pluginTemplateName = requireValidTemplateName(pluginTemplateName, "pluginTemplateName");
- this.interfaceTemplateName = requireValidTemplateName(interfaceTemplateName, "interfaceTemplateName");
- this.outputDirectory = requireNonNull(outputDirectory, "outputDirectory");
- }
-
- private static String requireValidTemplateName(@Nullable final String value, final String name) {
- final String extension = '.' + DocumentationFiles.templateFileNameExtension();
- if (value == null || !value.endsWith(extension)) {
- final String message =
- String.format("was expecting `%s` to end with a `%s` suffix: `%s`", name, extension, value);
- throw new IllegalArgumentException(message);
- }
- return value;
+ this.scalarsTemplate = requireNonNull(scalarsTemplate, "scalarsTemplate");
+ this.pluginTemplate = requireNonNull(pluginTemplate, "pluginTemplate");
+ this.interfaceTemplate = requireNonNull(interfaceTemplate, "interfaceTemplate");
}
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationTemplate.java
similarity index 71%
rename from log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
rename to log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationTemplate.java
index 43de35f..59219f0 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationTemplate.java
@@ -16,11 +16,16 @@
*/
package org.apache.logging.log4j.docgen.generator;
-final class DocumentationFiles {
+import static java.util.Objects.requireNonNull;
- private DocumentationFiles() {}
+public final class DocumentationTemplate {
- public static String templateFileNameExtension() {
- return "ftl";
+ final String name;
+
+ final String targetPath;
+
+ public DocumentationTemplate(final String name, final String targetPath) {
+ this.name = requireNonNull(name, "name");
+ this.targetPath = requireNonNull(targetPath, "targetPath");
}
}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
index 310fcbd..652086c 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/SchemaGenerator.java
@@ -62,8 +62,7 @@ public final class SchemaGenerator {
public static void generateSchema(final SchemaGeneratorArgs args) throws XMLStreamException {
requireNonNull(args, "args");
try {
- final List<PluginSet> extendedSets = Stream.concat(
- Stream.of(ConfigurationXml.PLUGIN_SET), args.pluginSets.stream())
+ final List<PluginSet> extendedSets = Stream.concat(BaseTypes.PLUGIN_SETS.stream(), args.pluginSets.stream())
.collect(Collectors.toList());
final TypeLookup lookup = TypeLookup.of(extendedSets);
final XMLOutputFactory factory = XMLOutputFactory.newFactory();
diff --git a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml
new file mode 100644
index 0000000..bc2a8f1
--- /dev/null
+++ b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-java-types.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to you under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<pluginSet xmlns="https://logging.apache.org/xml/ns/plugins" version="0.1.0">
+
+ <description>Java type definitions untraceable from the plugin hierarchy.</description>
+
+ <scalars>
+
+ <scalar className="boolean">
+ <description>A boolean value.</description>
+ <values>
+ <value name="false">
+ <description>false</description>
+ </value>
+ <value name="true">
+ <description>true</description>
+ </value>
+ </values>
+ </scalar>
+
+ <scalar className="byte">
+ <description>An 8-bit signed integer from `-128` to `127`</description>
+ </scalar>
+
+ <scalar className="short">
+ <description>A 16-bit signed integer from `-32768` to `32767`</description>
+ </scalar>
+
+ <scalar className="int">
+ <description>A 32-bit signed integer from `-2147483648` to `2147483647`</description>
+ </scalar>
+
+ <scalar className="long">
+ <description>A 64-bit signed integer from `-9223372036854775808` to `9223372036854775807`</description>
+ </scalar>
+
+ <scalar className="float">
+ <description>A single precision floating number from `1.40239846e-45` to `3.40282347e+38`</description>
+ </scalar>
+
+ <scalar className="double">
+ <description>A double precision floating number from `4.94065645841246544e-324` to `1.79769313486231570e+308`</description>
+ </scalar>
+
+ <scalar className="java.lang.String">
+ <description>A string of characters</description>
+ </scalar>
+
+ </scalars>
+
+</pluginSet>
diff --git a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/configuration.xml b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-log4j-types.xml
similarity index 80%
rename from log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/configuration.xml
rename to log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-log4j-types.xml
index 7e2ad71..5a3d1de 100644
--- a/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/configuration.xml
+++ b/log4j-docgen/src/main/resources/org/apache/logging/log4j/docgen/generator/base-log4j-types.xml
@@ -23,48 +23,6 @@
<scalars>
- <!-- Primitive type definitions -->
-
- <scalar className="boolean">
- <description>A boolean value.</description>
- <values>
- <value name="false">
- <description>false</description>
- </value>
- <value name="true">
- <description>true</description>
- </value>
- </values>
- </scalar>
-
- <scalar className="byte">
- <description>An 8-bit signed integer from `-128` to `127`</description>
- </scalar>
-
- <scalar className="short">
- <description>A 16-bit signed integer from `-32768` to `32767`</description>
- </scalar>
-
- <scalar className="int">
- <description>A 32-bit signed integer from `-2147483648` to `2147483647`</description>
- </scalar>
-
- <scalar className="long">
- <description>A 64-bit signed integer from `-9223372036854775808` to `9223372036854775807`</description>
- </scalar>
-
- <scalar className="float">
- <description>A single precision floating number from `1.40239846e-45` to `3.40282347e+38`</description>
- </scalar>
-
- <scalar className="double">
- <description>A double precision floating number from `4.94065645841246544e-324` to `1.79769313486231570e+308`</description>
- </scalar>
-
- <scalar className="java.lang.String">
- <description>A string of characters</description>
- </scalar>
-
<!-- `Level` is not a scalar, but for the purpose of the XSD we can limit its values to the standard ones. -->
<scalar className="org.apache.logging.log4j.Level">
<description><![CDATA[Represents a logging level.
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
index 22de8ee..8c068ec 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
@@ -41,10 +41,12 @@ public class DocumentationGeneratorTest {
final DocumentationGeneratorArgs generatorArgs = new DocumentationGeneratorArgs(
Set.of(pluginSet),
templateDirectory,
- "scalars.adoc.ftl",
- "plugin.adoc.ftl",
- "interface.adoc.ftl",
- outputDir);
+ new DocumentationTemplate(
+ "scalars.adoc.ftl", outputDir.resolve("scalars.adoc").toString()),
+ new DocumentationTemplate(
+ "plugin.adoc.ftl", outputDir.resolve("Core/%c.adoc").toString()),
+ new DocumentationTemplate(
+ "interface.adoc.ftl", outputDir.resolve("Core/%c.adoc").toString()));
DocumentationGenerator.generateDocumentation(generatorArgs);
// Verify the output
(logging-log4j-tools) 26/29: Accept path pattern in the `log4j-docgen-maven-plugin`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit fa8708a35a71c05d03953518192014d7c40c1d70
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 21 12:56:33 2024 +0100
Accept path pattern in the `log4j-docgen-maven-plugin`
---
log4j-docgen-maven-plugin/pom.xml | 6 ++
.../docgen/maven/DocumentationGeneratorMojo.java | 36 +++++--
.../docgen/maven/DocumentationTemplateMojo.java | 7 +-
.../log4j/docgen/maven/PathMatcherMojo.java | 103 +++++++++++++++++++++
.../logging/log4j/docgen/maven/PluginSets.java | 24 ++++-
.../log4j/docgen/maven/SchemaGeneratorMojo.java | 22 ++++-
.../logging/log4j/docgen/maven/package-info.java | 20 ++++
7 files changed, 201 insertions(+), 17 deletions(-)
diff --git a/log4j-docgen-maven-plugin/pom.xml b/log4j-docgen-maven-plugin/pom.xml
index 914a9a1..9f3102d 100644
--- a/log4j-docgen-maven-plugin/pom.xml
+++ b/log4j-docgen-maven-plugin/pom.xml
@@ -40,6 +40,12 @@
<dependencies>
+ <dependency>
+ <groupId>org.jspecify</groupId>
+ <artifactId>jspecify</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-docgen</artifactId>
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
index ae1de82..16c3c41 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationGeneratorMojo.java
@@ -26,6 +26,7 @@ import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.jspecify.annotations.Nullable;
/**
* Goal generating documentation by feeding the configuration collected from the provided plugin descriptors (e.g., {@code plugins.xml}) to the FreeMarker templates provided.
@@ -36,48 +37,63 @@ import org.apache.maven.plugins.annotations.Parameter;
public class DocumentationGeneratorMojo extends AbstractMojo {
/**
- * The paths of the plugin descriptor XML files
+ * The paths of the plugin descriptor XML files.
+ * <p>
+ * If you want to provide to a multitude of files, you might want to use {@link #descriptorFileMatchers} instead.
+ * </p>
*/
- @Parameter(property = "log4j.docgen.descriptorFiles", required = true)
+ @Nullable
+ @Parameter(property = "log4j.docgen.descriptorFiles")
private File[] descriptorFiles;
/**
- * The path to the FreeMarker template directory
+ * The {@link java.nio.file.FileSystem#getPathMatcher(String) PathMatcher}s to populate the paths of the plugin descriptor XML files.
+ * <p>
+ * If you want to refer to a particular file, you might want to use {@link #descriptorFiles} instead.
+ * </p>
+ */
+ @Nullable
+ @Parameter
+ private PathMatcherMojo[] descriptorFileMatchers;
+
+ /**
+ * The path to the FreeMarker template directory.
*/
@Parameter(property = "log4j.docgen.templateDirectory", required = true)
private File templateDirectory;
/**
- * The template that will be used to document scalar types
+ * The template that will be used to document scalar types.
*/
@Parameter(required = true)
private DocumentationTemplateMojo scalarsTemplate;
/**
- * The template that will be used to document plugins
+ * The template that will be used to document plugins.
*/
@Parameter(required = true)
- private DocumentationTemplateMojo pluginTemplateName;
+ private DocumentationTemplateMojo pluginTemplate;
/**
- * The template that will be used to document interfaces
+ * The template that will be used to document interfaces.
*/
@Parameter(required = true)
private DocumentationTemplateMojo interfaceTemplate;
@Override
public void execute() {
- final Set<PluginSet> pluginSets = PluginSets.ofDescriptorFiles(descriptorFiles);
+ final Set<PluginSet> pluginSets =
+ PluginSets.ofDescriptorFilesAndFileMatchers(descriptorFiles, descriptorFileMatchers);
final DocumentationGeneratorArgs generatorArgs = new DocumentationGeneratorArgs(
pluginSets,
templateDirectory.toPath(),
toApiModel(scalarsTemplate),
- toApiModel(pluginTemplateName),
+ toApiModel(pluginTemplate),
toApiModel(interfaceTemplate));
DocumentationGenerator.generateDocumentation(generatorArgs);
}
private static DocumentationTemplate toApiModel(final DocumentationTemplateMojo mojo) {
- return new DocumentationTemplate(mojo.name, mojo.targetPath);
+ return new DocumentationTemplate(mojo.source, mojo.target);
}
}
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
index 1459d8b..1539ca2 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/DocumentationTemplateMojo.java
@@ -18,6 +18,9 @@ package org.apache.logging.log4j.docgen.maven;
import org.apache.maven.plugins.annotations.Parameter;
+/**
+ * Models a FreeMarker template source and target.
+ */
public final class DocumentationTemplateMojo {
/**
@@ -28,7 +31,7 @@ public final class DocumentationTemplateMojo {
* </p>
*/
@Parameter(required = true)
- String name;
+ String source;
/**
* The target file path rendered content will be written to.
@@ -50,5 +53,5 @@ public final class DocumentationTemplateMojo {
* </ul>
*/
@Parameter(required = true)
- String targetPath;
+ String target;
}
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java
new file mode 100644
index 0000000..9f5cfa7
--- /dev/null
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PathMatcherMojo.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.docgen.maven;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.jspecify.annotations.Nullable;
+
+/**
+ * Models a {@link java.nio.file.FileSystem#getPathMatcher(String) PathMatcher}-based path provider.
+ */
+public final class PathMatcherMojo {
+
+ /**
+ * The file path of the directory which will be scanned for matches.
+ */
+ @Parameter(required = true)
+ private File baseDirectory;
+
+ /**
+ * Indicates if dot-prefixed paths found in {@link #baseDirectory} should be excluded.
+ */
+ @Parameter(defaultValue = "true")
+ private boolean dotFilesExcluded;
+
+ /**
+ * The path patterns (e.g., {@code glob:*.xml}) that will be used to filter paths found in {@link #baseDirectory}.
+ * @see FileSystem#getPathMatcher(String)
+ */
+ @Nullable
+ @Parameter
+ private String[] pathPatterns;
+
+ void findPaths(final Consumer<Path> pathConsumer) {
+
+ // Create path matchers
+ final String[] effectivePathPatterns = pathPatterns != null ? pathPatterns : new String[0];
+ final FileSystem fileSystem = FileSystems.getDefault();
+ final Set<PathMatcher> pathMatchers = Arrays.stream(effectivePathPatterns)
+ .map(pathPattern -> {
+ try {
+ return fileSystem.getPathMatcher(pathPattern);
+ } catch (final Exception error) {
+ final String message =
+ String.format("failed to create matcher using path pattern `%s`", pathPattern);
+ throw new IllegalArgumentException(message, error);
+ }
+ })
+ .collect(Collectors.toSet());
+
+ // Walk the base directory
+ try (final Stream<Path> paths = Files.walk(baseDirectory.toPath())) {
+ paths.filter(path -> {
+
+ // Skip directories
+ if (Files.isDirectory(path)) {
+ return false;
+ }
+
+ // Skip dot files
+ final boolean dotFile = dotFilesExcluded
+ && path.getFileName().toString().startsWith(".");
+ if (dotFile) {
+ return false;
+ }
+
+ // Check against path matchers
+ return pathMatchers.isEmpty()
+ || pathMatchers.stream().anyMatch(pathMatcher -> pathMatcher.matches(path));
+ })
+ .forEach(pathConsumer);
+ } catch (final IOException error) {
+ final String message = String.format("failed walking directory: `%s`", baseDirectory);
+ throw new UncheckedIOException(message, error);
+ }
+ }
+}
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java
index 42b8fc6..f54f964 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/PluginSets.java
@@ -17,17 +17,37 @@
package org.apache.logging.log4j.docgen.maven;
import java.io.File;
+import java.nio.file.Path;
import java.util.Arrays;
+import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
+import org.jspecify.annotations.Nullable;
final class PluginSets {
- static Set<PluginSet> ofDescriptorFiles(File[] descriptorFiles) {
+ static Set<PluginSet> ofDescriptorFilesAndFileMatchers(
+ @Nullable final File[] descriptorFiles, @Nullable final PathMatcherMojo[] descriptorFileMatchers) {
+
+ // Check arguments
+ final File[] effectiveDescriptorFiles = descriptorFiles != null ? descriptorFiles : new File[0];
+ final PathMatcherMojo[] effectiveDescriptorFileMatchers =
+ descriptorFileMatchers != null ? descriptorFileMatchers : new PathMatcherMojo[0];
+ if (effectiveDescriptorFiles.length == 0 && effectiveDescriptorFileMatchers.length == 0) {
+ throw new IllegalArgumentException(
+ "at least one of the `descriptorFiles` and `descriptorFileMatchers` configurations must be provided");
+ }
+
+ // Collect paths
+ final Set<Path> foundDescriptorPaths = new LinkedHashSet<>();
+ Arrays.stream(effectiveDescriptorFiles).map(File::toPath).forEach(foundDescriptorPaths::add);
+ Arrays.stream(effectiveDescriptorFileMatchers).forEach(matcher -> matcher.findPaths(foundDescriptorPaths::add));
+
+ // Create plugin sets
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- return Arrays.stream(descriptorFiles)
+ return foundDescriptorPaths.stream()
.map(descriptorFile -> {
try {
return reader.read(descriptorFile.toString());
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
index a53da90..193db22 100644
--- a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/SchemaGeneratorMojo.java
@@ -27,6 +27,7 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.jspecify.annotations.Nullable;
/**
* Goal generating an XSD from a given plugin descriptor, e.g., {@code plugins.xml}.
@@ -37,11 +38,25 @@ import org.apache.maven.plugins.annotations.Parameter;
public class SchemaGeneratorMojo extends AbstractMojo {
/**
- * The paths of the plugin descriptor XML files
+ * The paths of the plugin descriptor XML files.
+ * <p>
+ * If you want to provide to a multitude of files, you might want to use {@link #descriptorFileMatchers} instead.
+ * </p>
*/
- @Parameter(property = "log4j.docgen.descriptorFiles", required = true)
+ @Nullable
+ @Parameter(property = "log4j.docgen.descriptorFiles")
private File[] descriptorFiles;
+ /**
+ * The {@link java.nio.file.FileSystem#getPathMatcher(String) PathMatcher}s to populate the paths of the plugin descriptor XML files.
+ * <p>
+ * If you want to refer to a particular file, you might want to use {@link #descriptorFiles} instead.
+ * </p>
+ */
+ @Nullable
+ @Parameter
+ private PathMatcherMojo[] descriptorFileMatchers;
+
/**
* The path of the XSD file to write to
*/
@@ -50,7 +65,8 @@ public class SchemaGeneratorMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {
- final Set<PluginSet> pluginSets = PluginSets.ofDescriptorFiles(descriptorFiles);
+ final Set<PluginSet> pluginSets =
+ PluginSets.ofDescriptorFilesAndFileMatchers(descriptorFiles, descriptorFileMatchers);
try {
final SchemaGeneratorArgs generatorArgs = new SchemaGeneratorArgs(pluginSets, schemaFile.toPath());
SchemaGenerator.generateSchema(generatorArgs);
diff --git a/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/package-info.java b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/package-info.java
new file mode 100644
index 0000000..08eb479
--- /dev/null
+++ b/log4j-docgen-maven-plugin/src/main/java/org/apache/logging/log4j/docgen/maven/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+@NullMarked
+package org.apache.logging.log4j.docgen.maven;
+
+import org.jspecify.annotations.NullMarked;
(logging-log4j-tools) 11/29: Refactor `FreeMarkerGeneratorTest`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit b52747a36b520e41ac6867dc4e2a5cc2b679f58b
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Wed Feb 14 09:52:34 2024 +0100
Refactor `FreeMarkerGeneratorTest`
---
log4j-changelog/pom.xml | 6 +++
.../log4j/changelog/ChangelogExporterTest.java | 2 +-
.../log4j/changelog/ChangelogReleaserTest.java | 2 +-
.../log4j/changelog/MavenChangesImporterTest.java | 2 +-
log4j-docgen/pom.xml | 6 +++
.../docgen/internal/FreeMarkerGeneratorTest.java | 40 +++++++-----------
.../org.apache.logging.log4j.core.Appender.adoc | 0
.../Core/org.apache.logging.log4j.core.Filter.adoc | 0
.../Core/org.apache.logging.log4j.core.Layout.adoc | 0
...ogging.log4j.core.appender.ConsoleAppender.adoc | 0
...ache.logging.log4j.core.config.AppenderRef.adoc | 0
....logging.log4j.core.config.AppendersPlugin.adoc | 0
...he.logging.log4j.core.config.Configuration.adoc | 0
...ogging.log4j.core.config.CustomLevelConfig.adoc | 0
...che.logging.log4j.core.config.CustomLevels.adoc | 0
....log4j.core.config.LoggerConfig.RootLogger.adoc | 0
...che.logging.log4j.core.config.LoggerConfig.adoc | 0
...he.logging.log4j.core.config.LoggersPlugin.adoc | 0
...logging.log4j.core.config.PropertiesPlugin.adoc | 0
....apache.logging.log4j.core.config.Property.adoc | 0
...ache.logging.log4j.core.filter.BurstFilter.adoc | 0
...he.logging.log4j.core.layout.PatternLayout.adoc | 0
.../scalars.adoc | 0
.../pom.xml | 47 ++++------------------
.../tools/internal/test/utils}/FileTestUtils.java | 6 +--
log4j-tools-parent/pom.xml | 10 +++++
26 files changed, 50 insertions(+), 71 deletions(-)
diff --git a/log4j-changelog/pom.xml b/log4j-changelog/pom.xml
index c30adab..78aceea 100644
--- a/log4j-changelog/pom.xml
+++ b/log4j-changelog/pom.xml
@@ -47,6 +47,12 @@
<artifactId>freemarker</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
diff --git a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java
index 020db44..7f4e53f 100644
--- a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java
+++ b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogExporterTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.changelog;
-import static org.apache.logging.log4j.changelog.FileTestUtils.assertDirectoryContentMatches;
+import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
import java.nio.file.Path;
import java.nio.file.Paths;
diff --git a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
index 8eec57b..9b40b09 100644
--- a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
+++ b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/ChangelogReleaserTest.java
@@ -17,7 +17,7 @@
package org.apache.logging.log4j.changelog;
import static org.apache.commons.io.FileUtils.copyDirectory;
-import static org.apache.logging.log4j.changelog.FileTestUtils.assertDirectoryContentMatches;
+import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
import java.io.File;
import java.nio.file.Path;
diff --git a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java
index c73c970..d9ad463 100644
--- a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java
+++ b/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/MavenChangesImporterTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.changelog;
-import static org.apache.logging.log4j.changelog.FileTestUtils.assertDirectoryContentMatches;
+import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
import java.nio.file.Path;
import java.nio.file.Paths;
diff --git a/log4j-docgen/pom.xml b/log4j-docgen/pom.xml
index 2b2eb9c..cd58c1d 100644
--- a/log4j-docgen/pom.xml
+++ b/log4j-docgen/pom.xml
@@ -78,6 +78,12 @@
<artifactId>freemarker</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
index debcdde..09eee2c 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/internal/FreeMarkerGeneratorTest.java
@@ -16,48 +16,38 @@
*/
package org.apache.logging.log4j.docgen.internal;
-import static org.assertj.core.api.Assertions.assertThat;
+import static org.apache.logging.log4j.tools.internal.test.utils.FileTestUtils.assertDirectoryContentMatches;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.stream.Stream;
import org.apache.logging.log4j.docgen.PluginSet;
import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGenerator;
import org.apache.logging.log4j.docgen.freemarker.FreeMarkerGeneratorRequest;
import org.apache.logging.log4j.docgen.io.stax.PluginBundleStaxReader;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.CleanupMode;
+import org.junit.jupiter.api.io.TempDir;
public class FreeMarkerGeneratorTest {
@Test
- void generatePluginDocumentation() throws Exception {
+ void generatePluginDocumentation(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir) throws Exception {
+
+ // Read plugins
final PluginBundleStaxReader reader = new PluginBundleStaxReader();
- final PluginSet set = reader.read("src/test/resources/example-plugins.xml");
- final Path templateDir = Paths.get("src/test/resources/templates");
- final Path expectedDirectory = Paths.get("src/test/resources/expected/freemarker");
- final Path outputDirectory = Paths.get("target/test-site/freemarker");
+ final PluginSet pluginSet = reader.read("src/test/resources/example-plugins.xml");
+ // Generate the documentation
final FreeMarkerGenerator generator = new DefaultFreeMarkerGenerator();
final FreeMarkerGeneratorRequest request = new FreeMarkerGeneratorRequest();
- request.addPluginSet(set);
- request.setTemplateDirectory(templateDir);
- request.setOutputDirectory(outputDirectory);
-
+ request.addPluginSet(pluginSet);
+ final Path templateDirectory = Paths.get("src/test/resources/templates");
+ request.setTemplateDirectory(templateDirectory);
+ request.setOutputDirectory(outputDir);
generator.generateDocumentation(request);
- try (final Stream<Path> stream = Files.walk(expectedDirectory)) {
- stream.forEach(expectedPath -> {
- if (Files.isRegularFile(expectedPath)) {
- final Path path = expectedDirectory.relativize(expectedPath);
- final Path actualPath = outputDirectory.resolve(path);
- assertThat(actualPath)
- .exists()
- .usingCharset(StandardCharsets.UTF_8)
- .hasSameTextualContentAs(expectedPath);
- }
- });
- }
+ // Verify the output
+ final Path expectedDir = Paths.get("src/test/resources/plugins-to-freemarker-output");
+ assertDirectoryContentMatches(outputDir, expectedDir);
}
}
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.Appender.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Appender.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.Appender.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Appender.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.Filter.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Filter.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.Filter.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Filter.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.Layout.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Layout.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.Layout.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.Layout.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.appender.ConsoleAppender.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.AppenderRef.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppenderRef.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.AppenderRef.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppenderRef.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.AppendersPlugin.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Configuration.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Configuration.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Configuration.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Configuration.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevelConfig.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.CustomLevels.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevels.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.CustomLevels.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.CustomLevels.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.RootLogger.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.LoggerConfig.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggerConfig.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.LoggersPlugin.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.PropertiesPlugin.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Property.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Property.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.config.Property.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.config.Property.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.filter.BurstFilter.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.filter.BurstFilter.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.layout.PatternLayout.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/Core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/Core/org.apache.logging.log4j.core.layout.PatternLayout.adoc
diff --git a/log4j-docgen/src/test/resources/expected/freemarker/scalars.adoc b/log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
similarity index 100%
rename from log4j-docgen/src/test/resources/expected/freemarker/scalars.adoc
rename to log4j-docgen/src/test/resources/plugins-to-freemarker-output/scalars.adoc
diff --git a/log4j-changelog/pom.xml b/log4j-tools-internal-test-utils/pom.xml
similarity index 58%
copy from log4j-changelog/pom.xml
copy to log4j-tools-internal-test-utils/pom.xml
index c30adab..9a230ae 100644
--- a/log4j-changelog/pom.xml
+++ b/log4j-tools-internal-test-utils/pom.xml
@@ -23,54 +23,21 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-tools-parent</artifactId>
<version>${revision}</version>
- <relativePath>../log4j-tools-parent/pom.xml</relativePath>
+ <relativePath>../log4j-tools-parent</relativePath>
</parent>
- <artifactId>log4j-changelog</artifactId>
+ <artifactId>log4j-tools-internal-test-utils</artifactId>
- <dependencies>
-
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.annotation</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>com.github.spotbugs</groupId>
- <artifactId>spotbugs-annotations</artifactId>
- <optional>true</optional>
- </dependency>
-
- <dependency>
- <groupId>org.freemarker</groupId>
- <artifactId>freemarker</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-params</artifactId>
- <scope>test</scope>
- </dependency>
+ <properties>
+ <bnd.baseline.skip>true</bnd.baseline.skip>
+ <maven.deploy.skip>true</maven.deploy.skip>
+ </properties>
+ <dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
- <scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <scope>test</scope>
- </dependency>
-
</dependencies>
</project>
diff --git a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/FileTestUtils.java b/log4j-tools-internal-test-utils/src/main/java/org/apache/logging/log4j/tools/internal/test/utils/FileTestUtils.java
similarity index 93%
rename from log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/FileTestUtils.java
rename to log4j-tools-internal-test-utils/src/main/java/org/apache/logging/log4j/tools/internal/test/utils/FileTestUtils.java
index 40e3264..d9054c4 100644
--- a/log4j-changelog/src/test/java/org/apache/logging/log4j/changelog/FileTestUtils.java
+++ b/log4j-tools-internal-test-utils/src/main/java/org/apache/logging/log4j/tools/internal/test/utils/FileTestUtils.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.changelog;
+package org.apache.logging.log4j.tools.internal.test.utils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -29,11 +29,11 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-final class FileTestUtils {
+public final class FileTestUtils {
private FileTestUtils() {}
- static void assertDirectoryContentMatches(final Path actualPath, final Path expectedPath) {
+ public static void assertDirectoryContentMatches(final Path actualPath, final Path expectedPath) {
// Compare file paths
final Map<String, Path> actualContents = directoryContents(actualPath);
diff --git a/log4j-tools-parent/pom.xml b/log4j-tools-parent/pom.xml
index dfeace5..62ce2dc 100644
--- a/log4j-tools-parent/pom.xml
+++ b/log4j-tools-parent/pom.xml
@@ -29,6 +29,10 @@
<version>${revision}</version>
<packaging>pom</packaging>
+ <modules>
+ <module>../log4j-tools-internal-test-utils</module>
+ </modules>
+
<properties>
<!-- Dependency versions -->
@@ -52,6 +56,12 @@
<dependencyManagement>
<dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-tools-internal-test-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
(logging-log4j-tools) 24/29: Add `log4j.docgen.descriptorFilePath` argument to `DescriptorGenerator`
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git
commit 5c183e75db66b7773e8a90703c103064534ff7f7
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Tue Feb 20 09:17:00 2024 +0100
Add `log4j.docgen.descriptorFilePath` argument to `DescriptorGenerator`
---
.../docgen/processor/DescriptorGenerator.java | 87 +++++++++++-----------
.../docgen/processor/DescriptorGeneratorTest.java | 13 ++--
2 files changed, 52 insertions(+), 48 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
index 1ae19e3..56d1018 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
@@ -28,6 +28,8 @@ import com.sun.source.util.DocTrees;
import com.sun.source.util.SimpleDocTreeVisitor;
import java.io.IOException;
import java.io.Writer;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
@@ -44,6 +46,7 @@ import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedOptions;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
@@ -64,8 +67,6 @@ import javax.lang.model.util.SimpleElementVisitor8;
import javax.lang.model.util.SimpleTypeVisitor8;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
-import javax.tools.FileObject;
-import javax.tools.StandardLocation;
import javax.xml.stream.XMLStreamException;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.docgen.AbstractType;
@@ -83,19 +84,18 @@ import org.jspecify.annotations.Nullable;
@ServiceProvider(value = Processor.class, resolution = Resolution.OPTIONAL)
@SupportedAnnotationTypes({"org.apache.logging.log4j.core.config.plugins.*", "org.apache.logging.log4j.plugins.*"})
+@SupportedOptions({DescriptorGenerator.DESCRIPTOR_FILE_PATH_PROPERTY_NAME})
@NullMarked
public class DescriptorGenerator extends AbstractProcessor {
- /**
- * The file path generated descriptor will be written to.
- */
- public static final String DESCRIPTOR_FILE_PATH = "META-INF/log4j/plugins.xml";
+ static final String DESCRIPTOR_FILE_PATH_PROPERTY_NAME = "log4j.docgen.descriptorFilePath";
private static final String MULTIPLICITY_UNBOUNDED = "*";
+
private static final CharSequence[] GETTER_SETTER_PREFIXES = {"get", "is", "set"};
+
/**
- * Reference types from the {@code java.*} namespace that are described
- * in {@code org/apache/logging/log4j/docgen/internal/configuration.xml}
+ * Reference types from the {@code java.*} namespace that are described in {@code org/apache/logging/log4j/docgen/generator/base-java-types.xml}.
*/
private static final Set<String> KNOWN_SCALAR_TYPES = Set.of(
"java.lang.Boolean",
@@ -108,57 +108,61 @@ public class DescriptorGenerator extends AbstractProcessor {
"java.lang.Double",
"java.lang.String");
- private final PluginSet pluginSet;
+ private final PluginSet pluginSet = new PluginSet();
+
// Abstract types to process
private final Collection<TypeElement> abstractTypesToDocument = new HashSet<>();
+
// Scalar types to process
private final Collection<TypeElement> scalarTypesToDocument = new HashSet<>();
- private AsciiDocConverter converter;
+ private Path descriptorFilePath;
+
private DocTrees docTrees;
+
private Elements elements;
- private Types types;
+
private Messager messager;
+
+ private Types types;
+
+ private AsciiDocConverter converter;
+
private Annotations annotations;
- // Type corresponding to java.util.Collection
- private DeclaredType collectionType;
- // Type corresponding to java.lang.Enum
- private DeclaredType enumType;
- // Used by reflection
- @SuppressWarnings("unused")
- public DescriptorGenerator() {
- this(new PluginSet());
- }
+ // Type corresponding to `java.util.Collection`
+ private DeclaredType collectionType;
- public DescriptorGenerator(final PluginSet pluginSet) {
- this.pluginSet = pluginSet;
- // Will be initialized later
- annotations = null;
- collectionType = null;
- converter = null;
- docTrees = null;
- elements = null;
- enumType = null;
- messager = null;
- types = null;
- }
+ // Type corresponding to `java.lang.Enum`
+ private DeclaredType enumType;
@Override
public synchronized void init(final ProcessingEnvironment processingEnv) {
super.init(processingEnv);
+ descriptorFilePath = getDescriptorFilePath(processingEnv);
docTrees = DocTrees.instance(processingEnv);
elements = processingEnv.getElementUtils();
messager = processingEnv.getMessager();
types = processingEnv.getTypeUtils();
-
converter = new AsciiDocConverter(docTrees);
-
annotations = new Annotations(elements, types);
- collectionType = (DeclaredType)
- types.erasure(elements.getTypeElement("java.util.Collection").asType());
- enumType = (DeclaredType)
- types.erasure(elements.getTypeElement("java.lang.Enum").asType());
+ collectionType = getDeclaredType(processingEnv, "java.util.Collection");
+ enumType = getDeclaredType(processingEnv, "java.lang.Enum");
+ }
+
+ private static Path getDescriptorFilePath(final ProcessingEnvironment processingEnv) {
+ @Nullable String descriptorFilePath = processingEnv.getOptions().get(DESCRIPTOR_FILE_PATH_PROPERTY_NAME);
+ if (StringUtils.isBlank(descriptorFilePath)) {
+ final String message = String.format("missing property: `%s`", DESCRIPTOR_FILE_PATH_PROPERTY_NAME);
+ throw new IllegalStateException(message);
+ }
+ return Path.of(descriptorFilePath);
+ }
+
+ private static DeclaredType getDeclaredType(final ProcessingEnvironment processingEnv, final String className) {
+ final Types typeUtils = processingEnv.getTypeUtils();
+ final Elements elementUtils = processingEnv.getElementUtils();
+ return (DeclaredType) typeUtils.erasure(elementUtils.getTypeElement(className).asType());
}
@Override
@@ -227,14 +231,11 @@ public class DescriptorGenerator extends AbstractProcessor {
private void writePluginDescriptor() {
try {
- final FileObject output =
- processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", DESCRIPTOR_FILE_PATH);
-
- try (final Writer writer = output.openWriter()) {
+ try (final Writer writer = Files.newBufferedWriter(descriptorFilePath)) {
new PluginBundleStaxWriter().write(writer, pluginSet);
}
} catch (final IOException | XMLStreamException error) {
- final String message = String.format("An error occurred while writing to `%s`", DESCRIPTOR_FILE_PATH);
+ final String message = String.format("failed to write to `%s`", descriptorFilePath);
throw new RuntimeException(message, error);
}
}
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
index 201d68c..7791fc3 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
@@ -17,7 +17,6 @@
package org.apache.logging.log4j.docgen.processor;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -91,12 +90,17 @@ public class DescriptorGeneratorTest {
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(outputDir));
// Compile the sources
+ final Path descriptorFilePath = outputDir.resolve("plugins.xml");
final DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>();
final CompilationTask task = compiler.getTask(
null,
fileManager,
diagnosticCollector,
- asList("-proc:only", "-processor", DescriptorGenerator.class.getName()),
+ List.of(
+ "-proc:only",
+ "-processor",
+ DescriptorGenerator.class.getName(),
+ "-A" + DescriptorGenerator.DESCRIPTOR_FILE_PATH_PROPERTY_NAME + "=" + descriptorFilePath),
null,
sources);
task.call();
@@ -106,8 +110,7 @@ public class DescriptorGeneratorTest {
assertThat(diagnostics).noneMatch(diagnostic -> diagnostic.getKind() != Diagnostic.Kind.NOTE);
// Resolve the descriptor file
- final Path descriptor = outputDir.resolve(DescriptorGenerator.DESCRIPTOR_FILE_PATH);
- assertThat(descriptor).isNotEmptyFile();
- return descriptor;
+ assertThat(descriptorFilePath).isNotEmptyFile();
+ return descriptorFilePath;
}
}