Skip to content

Commit e8801fa

Browse files
authored
Add Maven plugin for log4j-changelog (#20)
2 parents 0243a02 + 1addafc commit e8801fa

File tree

14 files changed

+369
-34
lines changed

14 files changed

+369
-34
lines changed

CHANGELOG.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
////
1717
18+
== Unreleased
19+
20+
* Added `log4j-changelog-maven-plugin` module and renamed `log4j.changelog.exporter.outputDirectory` property to `log4j.changelog.outputDirectory` (for https://github.com/apache/logging-log4j-tools/issues/20[#20] by Ralph Goers, Volkan Yazıcı)
21+
1822
== 0.1.0 (2023-01-10)
1923
20-
* Added `log4j-tools-bom` and `log4j-changelog` modules (for https://issues.apache.org/jira/browse/LOG4J2-3628[LOG4J2-3628] by `vy`)
24+
* Added `log4j-tools-bom` and `log4j-changelog` modules (for https://issues.apache.org/jira/browse/LOG4J2-3628[LOG4J2-3628] by Volkan Yazıcı)

README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Tooling **internally** used by https://logging.apache.org/log4j/2.x/[the Apache
2424
xref:log4j-changelog/README.adoc[`log4j-changelog`]::
2525
Tooling to export AsciiDoc-formatted changelog files.
2626
27+
xref:log4j-changelog-maven-plugin/README.adoc[`log4j-changelog-maven-plugin`]::
28+
Maven plugin for xref:log4j-changelog/README.adoc[`log4j-changelog`].
29+
2730
== Distribution
2831
2932
In accordance with the Apache Software Foundation's release https://infra.apache.org/release-distribution.html[distribution policy] and https://infra.apache.org/release-publishing.html[creation process], project artifacts are _officially_ accessible from the following locations:
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
////
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
////
17+
18+
This project ships a Maven plugin providing convenient access to the `ChangelogExporter` and `ChangelogReleaser` of xref:../log4j-changelog/README.adoc[log4j-changelog].
19+
20+
== Exporting changelogs to AsciiDoc files
21+
22+
You can use the `export` goal wrapping xref:../log4j-changelog/README.adoc#qa-generate[`ChangelogExporter` to generate AsciiDoc files from a changelog directory].
23+
An example usage is shared below.
24+
25+
.`pom.xml` snippet that goes into the `project > build > plugins` block
26+
[source,xml]
27+
----
28+
<!-- export AsciiDoc-formatted sources to `target/generated-sources/site/asciidoc/changelog` -->
29+
<plugin>
30+
<groupId>org.apache.logging.log4j</groupId>
31+
<artifactId>log4j-changelog-maven-plugin</artifactId>
32+
<inherited>false</inherited>
33+
<executions>
34+
<execution>
35+
<id>generate-changelog</id>
36+
<goals>
37+
<goal>export</goal>
38+
</goals>
39+
</execution>
40+
</executions>
41+
</plugin>
42+
----
43+
44+
`export` goal by defaults runs during the `pre-site` phase and accepts the following configuration parameters:
45+
46+
`changelogDirectory`::
47+
Directory containing release folders composed of changelog entry XML files.
48+
It defaults to `${project.basedir}/src/changelog` and can be set using the `log4j.changelog.directory` property.
49+
50+
`outputDirectory`::
51+
Directory to write generated changelog files.
52+
It defaults to `${project.build.directory}/generated-sources/site/asciidoc/changelog` and can be set using the `log4j.changelog.exporter.outputDirectory` property.
53+
54+
== Populating a release changelog directory
55+
56+
You can use the `release` goal wrapping xref:../log4j-changelog/README.adoc#qa-deploy-release[`ChangelogReleaser` to populate a release changelog directory].
57+
An example usage is shared below.
58+
59+
[source,bash]
60+
----
61+
# Populate `src/changelog/<releaseVersion>` from `src/changelog/.<releaseVersionMajor>.x.x`
62+
./mvnw -N log4j-changelog:releaser -Dlog4j.changelog.releaseVersion=2.19.0
63+
----
64+
65+
`release` goal by defaults runs during the `validate` phase and accepts the following configuration parameters:
66+
67+
`changelogDirectory`::
68+
Directory containing release folders composed of changelog entry XML files.
69+
It defaults to `${project.basedir}/src/changelog` and can be set using the `log4j.changelog.directory` property.
70+
71+
`releaseVersion`::
72+
The version to be released.
73+
It can be set using the `log4j.changelog.releaseVersion` property.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
https://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>org.apache.logging.log4j</groupId>
26+
<artifactId>log4j-tools-parent</artifactId>
27+
<version>${revision}</version>
28+
<relativePath>../log4j-tools-parent/pom.xml</relativePath>
29+
</parent>
30+
31+
<artifactId>log4j-changelog-maven-plugin</artifactId>
32+
<packaging>maven-plugin</packaging>
33+
34+
<dependencies>
35+
36+
<dependency>
37+
<groupId>org.apache.logging.log4j</groupId>
38+
<artifactId>log4j-changelog</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.apache.maven.plugin-tools</groupId>
43+
<artifactId>maven-plugin-annotations</artifactId>
44+
<scope>provided</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.apache.maven</groupId>
49+
<artifactId>maven-plugin-api</artifactId>
50+
</dependency>
51+
52+
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-plugin-plugin</artifactId>
59+
<configuration>
60+
<goalPrefix>log4j-changelog</goalPrefix>
61+
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
62+
</configuration>
63+
<executions>
64+
<execution>
65+
<id>mojo-descriptor</id>
66+
<goals>
67+
<goal>descriptor</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
75+
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache license, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the license for the specific language governing permissions and
15+
* limitations under the license.
16+
*/
17+
package org.apache.logging.log4j;
18+
19+
import java.io.File;
20+
21+
import org.apache.logging.log4j.changelog.exporter.ChangelogExporter;
22+
import org.apache.logging.log4j.changelog.exporter.ChangelogExporterArgs;
23+
24+
import org.apache.maven.plugin.AbstractMojo;
25+
import org.apache.maven.plugins.annotations.LifecyclePhase;
26+
import org.apache.maven.plugins.annotations.Mojo;
27+
import org.apache.maven.plugins.annotations.Parameter;
28+
29+
/**
30+
* Goal exporting the changelog directory.
31+
*
32+
* @see ChangelogExporter
33+
*/
34+
@Mojo(name = "export", defaultPhase = LifecyclePhase.PRE_SITE)
35+
public class ExportMojo extends AbstractMojo {
36+
37+
/**
38+
* Directory containing release folders composed of changelog entry XML files.
39+
*/
40+
@Parameter(
41+
defaultValue = "${project.basedir}/src/changelog",
42+
property = ChangelogExporterArgs.CHANGELOG_DIRECTORY_PROPERTY_NAME,
43+
required = true)
44+
private File changelogDirectory;
45+
46+
/**
47+
* Directory to write generated changelog files.
48+
*/
49+
@Parameter(
50+
defaultValue = "${project.build.directory}/generated-sources/site/asciidoc/changelog",
51+
property = ChangelogExporterArgs.OUTPUT_DIRECTORY_PROPERTY_NAME,
52+
required = true)
53+
private File outputDirectory;
54+
55+
public void execute() {
56+
ChangelogExporterArgs args = ChangelogExporterArgs.fromArgs(
57+
changelogDirectory.toPath(),
58+
outputDirectory.toPath());
59+
ChangelogExporter.performExport(args);
60+
}
61+
62+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache license, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the license for the specific language governing permissions and
15+
* limitations under the license.
16+
*/
17+
package org.apache.logging.log4j;
18+
19+
import java.io.File;
20+
21+
import org.apache.logging.log4j.changelog.releaser.ChangelogReleaser;
22+
import org.apache.logging.log4j.changelog.releaser.ChangelogReleaserArgs;
23+
24+
import org.apache.maven.plugin.AbstractMojo;
25+
import org.apache.maven.plugins.annotations.LifecyclePhase;
26+
import org.apache.maven.plugins.annotations.Mojo;
27+
import org.apache.maven.plugins.annotations.Parameter;
28+
29+
/**
30+
* Goal moving the contents of an unreleased changelog directory (e.g., {@code .2.x.x} to a released one (e.g., {@code 2.19.0}).
31+
*
32+
* @see ChangelogReleaser
33+
*/
34+
@Mojo(name = "release", defaultPhase = LifecyclePhase.VALIDATE)
35+
public class ReleaseMojo extends AbstractMojo {
36+
37+
/**
38+
* Directory containing release folders composed of changelog entry XML files.
39+
*/
40+
@Parameter(
41+
defaultValue = "${project.basedir}/src/changelog",
42+
property = ChangelogReleaserArgs.CHANGELOG_DIRECTORY_PROPERTY_NAME,
43+
required = true)
44+
private File changelogDirectory;
45+
46+
/**
47+
* The version to be released, e.g., {@code 2.19.0}.
48+
*/
49+
@Parameter(
50+
property = ChangelogReleaserArgs.RELEASE_VERSION_PROPERTY_NAME,
51+
required = true)
52+
private String releaseVersion;
53+
54+
public void execute() {
55+
ChangelogReleaserArgs args = ChangelogReleaserArgs.fromArgs(changelogDirectory.toPath(), releaseVersion);
56+
ChangelogReleaser.performRelease(args);
57+
}
58+
59+
}

log4j-changelog/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ You need to use `ChangelogExporter` as follows:
260260
java \
261261
-cp /path/to/log4j-changelog.jar \
262262
-Dlog4j.changelog.directory=/path/to/changelog/directory \
263-
-Dlog4j.changelog.exporter.outputDirectory=/path/to/asciiDocOutputDirectory \
263+
-Dlog4j.changelog.outputDirectory=/path/to/asciiDocOutputDirectory \
264264
org.apache.logging.log4j.changelog.exporter.ChangelogExporter
265265
----
266266

log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/ChangelogExporter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ public final class ChangelogExporter {
3434
private ChangelogExporter() {}
3535

3636
public static void main(final String[] mainArgs) {
37+
performExport(ChangelogExporterArgs.fromSystemProperties());
38+
}
3739

38-
// Read arguments
39-
final ChangelogExporterArgs args = ChangelogExporterArgs.fromSystemProperties();
40+
public static void performExport(final ChangelogExporterArgs args) {
4041

4142
// Find release directories
4243
final List<Path> releaseDirectories = findReleaseDirectories(args);

log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/exporter/ChangelogExporterArgs.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
import static org.apache.logging.log4j.changelog.util.PropertyUtils.requireNonBlankPathProperty;
2222

23-
final class ChangelogExporterArgs {
23+
public final class ChangelogExporterArgs {
24+
25+
public static final String CHANGELOG_DIRECTORY_PROPERTY_NAME = "log4j.changelog.directory";
26+
27+
public static final String OUTPUT_DIRECTORY_PROPERTY_NAME = "log4j.changelog.outputDirectory";
2428

2529
final Path changelogDirectory;
2630

@@ -32,8 +36,12 @@ private ChangelogExporterArgs(final Path changelogDirectory, final Path outputDi
3236
}
3337

3438
static ChangelogExporterArgs fromSystemProperties() {
35-
final Path changelogDirectory = requireNonBlankPathProperty("log4j.changelog.directory");
36-
final Path outputDirectory = requireNonBlankPathProperty("log4j.changelog.exporter.outputDirectory");
39+
final Path changelogDirectory = requireNonBlankPathProperty(CHANGELOG_DIRECTORY_PROPERTY_NAME);
40+
final Path outputDirectory = requireNonBlankPathProperty(OUTPUT_DIRECTORY_PROPERTY_NAME);
41+
return new ChangelogExporterArgs(changelogDirectory, outputDirectory);
42+
}
43+
44+
public static ChangelogExporterArgs fromArgs(final Path changelogDirectory, final Path outputDirectory) {
3745
return new ChangelogExporterArgs(changelogDirectory, outputDirectory);
3846
}
3947

log4j-changelog/src/main/java/org/apache/logging/log4j/changelog/importer/MavenChangesImporterArgs.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323

2424
final class MavenChangesImporterArgs {
2525

26+
public static final String CHANGELOG_DIRECTORY_PROPERTY_NAME = "log4j.changelog.directory";
27+
28+
public static final String CHANGES_XML_FILE_PROPERTY_NAME = "log4j.changelog.changesXmlFile";
29+
30+
public static final String RELEASE_VERSION_MAJOR_PROPERTY_NAME = "log4j.changelog.releaseVersionMajor";
31+
2632
final Path changelogDirectory;
2733

2834
final Path changesXmlFile;
@@ -36,10 +42,10 @@ private MavenChangesImporterArgs(final Path changelogDirectory, final Path chang
3642
}
3743

3844
static MavenChangesImporterArgs fromSystemProperties() {
39-
final Path changelogDirectory = requireNonBlankPathProperty("log4j.changelog.directory");
40-
final Path changesXmlFile = requireNonBlankPathProperty("log4j.changelog.changesXmlFile");
41-
final int releaseVersion = requireNonBlankIntProperty("log4j.changelog.releaseVersionMajor");
42-
return new MavenChangesImporterArgs(changelogDirectory, changesXmlFile, releaseVersion);
45+
final Path changelogDirectory = requireNonBlankPathProperty(CHANGELOG_DIRECTORY_PROPERTY_NAME);
46+
final Path changesXmlFile = requireNonBlankPathProperty(CHANGES_XML_FILE_PROPERTY_NAME);
47+
final int releaseVersionMajor = requireNonBlankIntProperty(RELEASE_VERSION_MAJOR_PROPERTY_NAME);
48+
return new MavenChangesImporterArgs(changelogDirectory, changesXmlFile, releaseVersionMajor);
4349
}
4450

4551
}

0 commit comments

Comments
 (0)