Skip to content

Commit b0f4e46

Browse files
committed
Initial log4j-docgen usage
1 parent b4ef5dd commit b0f4e46

File tree

41 files changed

+674
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+674
-392
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is here to activate the `plugin-processing` Maven profile.

log4j-1.2-api/pom.xml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
~ limitations under the License.
1717
-->
1818
<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/maven-v4_0_0.xsd">
19+
1920
<modelVersion>4.0.0</modelVersion>
21+
2022
<parent>
2123
<groupId>org.apache.logging.log4j</groupId>
2224
<artifactId>log4j</artifactId>
2325
<version>${revision}</version>
2426
<relativePath>../log4j-parent</relativePath>
2527
</parent>
28+
2629
<artifactId>log4j-1.2-api</artifactId>
27-
<packaging>jar</packaging>
30+
2831
<name>Apache Log4j 1.x Compatibility API</name>
2932
<description>The Apache Log4j 1.x Compatibility API</description>
33+
3034
<properties>
3135
<module.name>org.apache.log4j</module.name>
3236

@@ -45,6 +49,7 @@
4549
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
4650
<!-- we have an `bnd.bnd` file to override the parent's defaults -->
4751
</properties>
52+
4853
<dependencies>
4954
<!-- Used for JMS appenders (needs an implementation of course) -->
5055
<dependency>
@@ -138,27 +143,6 @@
138143
</dependency>
139144
</dependencies>
140145

141-
<build>
142-
<plugins>
143-
144-
<!-- Enable Log4j plugin processing -->
145-
<plugin>
146-
<groupId>org.apache.maven.plugins</groupId>
147-
<artifactId>maven-compiler-plugin</artifactId>
148-
<configuration>
149-
<annotationProcessorPaths combine.children="append">
150-
<path>
151-
<groupId>org.apache.logging.log4j</groupId>
152-
<artifactId>log4j-core</artifactId>
153-
<version>${project.version}</version>
154-
</path>
155-
</annotationProcessorPaths>
156-
</configuration>
157-
</plugin>
158-
159-
</plugins>
160-
</build>
161-
162146
<profiles>
163147

164148
<!-- Fixes incompatible with Java 8 -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is here to activate the `plugin-processing` Maven profile.

log4j-cassandra/pom.xml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
~ limitations under the License.
1717
-->
1818
<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">
19+
1920
<modelVersion>4.0.0</modelVersion>
21+
2022
<parent>
2123
<groupId>org.apache.logging.log4j</groupId>
2224
<artifactId>log4j</artifactId>
@@ -25,8 +27,10 @@
2527
</parent>
2628

2729
<artifactId>log4j-cassandra</artifactId>
30+
2831
<name>Apache Log4j Cassandra</name>
2932
<description>Cassandra appender for Log4j.</description>
33+
3034
<properties>
3135

3236
<!--
@@ -108,26 +112,4 @@
108112
</dependency>
109113
</dependencies>
110114

111-
<build>
112-
<plugins>
113-
<plugin>
114-
<groupId>org.apache.maven.plugins</groupId>
115-
<artifactId>maven-compiler-plugin</artifactId>
116-
<configuration>
117-
<!--
118-
~ Modules that contain `log4j-core` plugins, must be compiled with:
119-
~
120-
~ org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor
121-
-->
122-
<annotationProcessorPaths combine.children="append">
123-
<path>
124-
<groupId>org.apache.logging.log4j</groupId>
125-
<artifactId>log4j-core</artifactId>
126-
<version>${project.version}</version>
127-
</path>
128-
</annotationProcessorPaths>
129-
</configuration>
130-
</plugin>
131-
</plugins>
132-
</build>
133115
</project>

log4j-core-java9/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
<properties>
3131
<maven.compiler.release>9</maven.compiler.release>
3232
<maven.deploy.skip>true</maven.deploy.skip>
33+
<maven.install.skip>true</maven.install.skip>
34+
<sign.skip>true</sign.skip>
3335
</properties>
3436
<dependencies>
3537
<!-- Naturally, all implementations require the log4j-api JAR -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is here to activate the `plugin-processing` Maven profile.

log4j-core-test/pom.xml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
~ limitations under the License.
1717
-->
1818
<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/maven-v4_0_0.xsd">
19+
1920
<modelVersion>4.0.0</modelVersion>
21+
2022
<parent>
2123
<groupId>org.apache.logging.log4j</groupId>
2224
<artifactId>log4j</artifactId>
@@ -25,9 +27,10 @@
2527
</parent>
2628

2729
<artifactId>log4j-core-test</artifactId>
28-
<packaging>jar</packaging>
30+
2931
<name>Apache Log4j Core Tests</name>
3032
<description>The Apache Log4j Implementation Tests</description>
33+
3134
<properties>
3235
<!-- Ignore less important (high rank) bugs for test artifacts -->
3336
<spotbugs.maxRank>9</spotbugs.maxRank>
@@ -351,21 +354,6 @@
351354
<build>
352355
<plugins>
353356

354-
<!-- Enable Log4j plugin processing -->
355-
<plugin>
356-
<groupId>org.apache.maven.plugins</groupId>
357-
<artifactId>maven-compiler-plugin</artifactId>
358-
<configuration>
359-
<annotationProcessorPaths combine.children="append">
360-
<path>
361-
<groupId>org.apache.logging.log4j</groupId>
362-
<artifactId>log4j-core</artifactId>
363-
<version>${project.version}</version>
364-
</path>
365-
</annotationProcessorPaths>
366-
</configuration>
367-
</plugin>
368-
369357
<plugin>
370358
<groupId>org.apache.maven.plugins</groupId>
371359
<artifactId>maven-surefire-plugin</artifactId>

log4j-core/pom.xml

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@
1616
~ limitations under the License.
1717
-->
1818
<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/maven-v4_0_0.xsd">
19+
1920
<modelVersion>4.0.0</modelVersion>
21+
2022
<parent>
2123
<groupId>org.apache.logging.log4j</groupId>
2224
<artifactId>log4j</artifactId>
2325
<version>${revision}</version>
2426
<relativePath>../log4j-parent</relativePath>
2527
</parent>
28+
2629
<artifactId>log4j-core</artifactId>
27-
<packaging>jar</packaging>
30+
2831
<name>Apache Log4j Core</name>
2932
<description>The Apache Log4j Implementation</description>
33+
3034
<properties>
35+
3136
<javadoc.skip>false</javadoc.skip>
3237

38+
<!-- Tests are located elsewhere, no need to do any processing for the `src/test` directory: -->
39+
<maven.test.skip>true</maven.test.skip>
40+
3341
<!--
3442
~ OSGi and JPMS options
3543
-->
@@ -82,6 +90,7 @@
8290
javax.mail.api;substitute="javax.mail-api";transitive=false;static=true
8391
</bnd-extra-module-options>
8492
</properties>
93+
8594
<dependencies>
8695
<dependency>
8796
<groupId>javax.activation</groupId>
@@ -200,13 +209,16 @@
200209
<optional>true</optional>
201210
</dependency>
202211
</dependencies>
212+
203213
<build>
204214
<plugins>
205215

206216
<plugin>
207217
<groupId>org.codehaus.mojo</groupId>
208218
<artifactId>build-helper-maven-plugin</artifactId>
209219
<executions>
220+
221+
<!-- Add Java 9+ code for the MRJ -->
210222
<execution>
211223
<id>add-source</id>
212224
<goals>
@@ -219,43 +231,82 @@
219231
</sources>
220232
</configuration>
221233
</execution>
234+
235+
<!-- Attach the generated `log4j-plugins.xml` -->
236+
<execution>
237+
<id>attach-plugin-descriptor</id>
238+
<goals>
239+
<goal>attach-artifact</goal>
240+
</goals>
241+
<phase>package</phase>
242+
<configuration>
243+
<artifacts>
244+
<artifact>
245+
<file>${project.build.directory}/log4j-plugins.xml</file>
246+
<type>xml</type>
247+
<classifier>log4j-plugins</classifier>
248+
</artifact>
249+
</artifacts>
250+
</configuration>
251+
</execution>
252+
222253
</executions>
223254
</plugin>
224255

256+
<!-- We can't use `plugin-processing` Maven profile activated by `.log4j-plugin-processing-activator` file, because...
257+
`log4j-core` contains `PluginProcessor`, that is responsible for generating `META-INF/org/apache/.../Log4j2Plugins.dat` from `@Plugin`-annotated members.
258+
`log4j-core` also contains `@Plugin`-annotated members too.
259+
That is, we need `log4j-core` to build `log4j-core`.
260+
To work around this chicken-and-egg problem, we build as follows:
261+
262+
1. Compile sources using the `default-compile` default compilation execution.
263+
This will generate the `PluginProcessor` class.
264+
265+
2. Make a second compilation pass using the generated `PluginProcessor`. -->
225266
<plugin>
226267
<artifactId>maven-compiler-plugin</artifactId>
227-
<configuration>
228-
<annotationProcessorPaths combine.self="override" />
229-
</configuration>
230268
<executions>
269+
270+
<!-- Compile sources as usual -->
231271
<execution>
232-
<!-- disable annotation processing for first pass -->
233272
<id>default-compile</id>
234273
<configuration>
235-
<annotationProcessorPaths>
274+
<annotationProcessorPaths combine.children="append">
275+
<!-- `org.apache.logging.log4j.docgen.processor.DescriptorGenerator` for generating `log4j-plugins.xml`: -->
236276
<path>
237-
<groupId>com.google.errorprone</groupId>
238-
<artifactId>error_prone_core</artifactId>
239-
<version>${error-prone.version}</version>
277+
<groupId>org.apache.logging.log4j</groupId>
278+
<artifactId>log4j-docgen</artifactId>
279+
<version>${log4j-docgen.version}</version>
240280
</path>
241281
</annotationProcessorPaths>
282+
<compilerArgs combine.children="append">
283+
<!-- Provide `org.apache.logging.log4j.docgen.processor.DescriptorGenerator` arguments: -->
284+
<arg>-Alog4j.docgen.descriptorFilePath=${project.build.directory}/log4j-plugins.xml</arg>
285+
<arg>-Alog4j.docgen.groupId=${project.groupId}</arg>
286+
<arg>-Alog4j.docgen.artifactId=${project.artifactId}</arg>
287+
<arg>-Alog4j.docgen.version=${project.version}</arg>
288+
<arg>-Alog4j.docgen.description=${project.description}</arg>
289+
</compilerArgs>
242290
</configuration>
243291
</execution>
292+
293+
<!-- Process sources using `PluginProcessor` to generate `META-INF/org/apache/.../Log4j2Plugins.dat` -->
244294
<execution>
245-
<!-- then do a processing-only pass to generate plugins .dat file -->
246295
<id>process-plugins</id>
247296
<goals>
248297
<goal>compile</goal>
249298
</goals>
250299
<phase>process-classes</phase>
251300
<configuration>
301+
<annotationProcessorPaths combine.self="override" />
252302
<annotationProcessors>
253303
<processor>org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor</processor>
254304
</annotationProcessors>
255305
<compilerArgs combine.self="override" />
256306
<proc>only</proc>
257307
</configuration>
258308
</execution>
309+
259310
</executions>
260311
</plugin>
261312

@@ -291,4 +342,5 @@
291342

292343
</plugins>
293344
</build>
345+
294346
</project>

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/ScriptCondition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public List<PathWithAttributes> selectFilesToDelete(
8989
* <li>pathList - a {@code java.util.List} containing {@link org.apache.logging.log4j.core.appender.rolling.action.PathWithAttributes} objects. (The script is
9090
* free to modify and return this list.)</li>
9191
* <li>substitutor - a {@link org.apache.logging.log4j.core.lookup.StrSubstitutor} that can be used to look up variables embedded in the base
92-
* dir or other properties
93-
* <li>statusLogger - the {@link StatusLogger} that can be used to log events during script execution
92+
* dir or other properties</li>
93+
* <li>statusLogger - the {@link StatusLogger} that can be used to log events during script execution</li>
9494
* <li>any properties declared in the configuration</li>
9595
* </ul>
9696
* @param configuration the configuration
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is here to activate the `plugin-processing` Maven profile.

0 commit comments

Comments
 (0)